Skip to content

Commit

Permalink
Feat: Reset tutorials (#37)
Browse files Browse the repository at this point in the history
* feat: reset tutorials ,refresh battletv

* Fix: Reset tutorials

* fix: small fixes

* fix : stats

* fix: minor changes

---------

Co-authored-by: shubham-1806 <[email protected]>
Co-authored-by: Ram-20062003 <[email protected]>
Co-authored-by: Ram Ganesh K. R <[email protected]>
  • Loading branch information
4 people authored Mar 12, 2023
1 parent 76ae353 commit 8c44824
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/map-designer/src/Parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Parameters {

static mapTileOffsetY = 256;

static totalCoins = 10000;
static totalCoins = 6000;

static mapLocalStorageKey = 'cc-map-designer-map';
}
6 changes: 3 additions & 3 deletions packages/renderer/src/config/TowerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class TowerConfig {
'tower1_thumbnail.png',
400,
4,
100,
25,
),
new TowerType(
1,
Expand All @@ -19,7 +19,7 @@ export default class TowerConfig {
'tower2_thumbnail.png',
600,
6,
200,
50,
),
new TowerType(
2,
Expand All @@ -28,7 +28,7 @@ export default class TowerConfig {
'tower3_thumbnail.png',
400,
6,
200,
100,
),
];
}
18 changes: 18 additions & 0 deletions src/components/BattleTV/BattleTV.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,21 @@
height: 0;
width: 0;
}
.button {
background-color: transparent;
color: #eaeaea;
margin: 0px 8px;
border: 1px solid #eaeaea;
padding: 8px;
text-transform: uppercase;
border-radius: 8px;
font-family: monospace, sans-serif;
display: inline-block;
white-space: nowrap;
transition: 0.3s;
}

.button:hover {
color: #0a1c2a;
background-color: #aaaaaa;
}
12 changes: 11 additions & 1 deletion src/components/BattleTV/BattleTV.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function PaginatedItems() {
></img>
</div>
<span className={[styles.name].join(' ')}>
{match.user1.username}
{match.user1.username.substring(0, 10)}
</span>
</span>
<span className={styles.coinsusedleft}>
Expand Down Expand Up @@ -206,6 +206,16 @@ function PaginatedItems() {
containerClassName={styles.pagination}
activeClassName="active"
/>
<button
type="button"
className={styles.button}
onClick={() => {
dispatch(fetchBattleTv());
}}
id="refresh"
>
Refresh
</button>
</nav>
</>
);
Expand Down
32 changes: 31 additions & 1 deletion src/components/DashboardOptions/DashboardOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
import Dropdown from 'react-bootstrap/Dropdown';
import { Link } from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';
import styles from './DashboardOptions.module.css';
import DropdownToggle from 'react-bootstrap/esm/DropdownToggle';
import { ButtonGroup } from 'react-bootstrap';
import { apiConfig, ApiError } from '../../api/ApiConfig';
import { CurrentUserApi } from '@codecharacter-2023/client';
import Toast from 'react-hot-toast';
import { useAppDispatch } from '../../store/hooks';
import {
isTourOverChanged,
isTourResetChanged,
} from '../../store/DailyChallenge/dailyChallenge';

interface dashboardoptions {
image?: JSX.Element;
onLogout?: React.MouseEventHandler<HTMLElement>;
}

const DashboardOptions = (props: dashboardoptions): JSX.Element => {
const currentUserApi = new CurrentUserApi(apiConfig);
const navigate = useNavigate();
const dispatch = useAppDispatch();

const resetTutorials = () => {
currentUserApi
.updateCurrentUser({
updateTutorialLevel: 'RESET',
})
.then(() => {
navigate('/dashboard', { replace: true });
dispatch(isTourResetChanged(true));
dispatch(isTourOverChanged(false));
})
.catch(err => {
if (err instanceof ApiError) Toast.error(err.message);
});
};

return (
<div className={styles.dropdown}>
<Dropdown as={ButtonGroup}>
Expand All @@ -20,6 +47,9 @@ const DashboardOptions = (props: dashboardoptions): JSX.Element => {
<Dropdown.Item as={Link} to="/profile" className={styles.menuText}>
View Profile
</Dropdown.Item>
<Dropdown.Item onClick={resetTutorials} className={styles.menuText}>
Revisit Tutorial
</Dropdown.Item>
<Dropdown.Item onClick={props.onLogout} className={styles.menuText}>
Logout
</Dropdown.Item>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Leaderboard/DailyLeaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function PaginatedItems() {
className={styles.pic}
src={getAvatarByID(row.avatarId).url}
></img>
{' ' + row.userName}
{' ' + row.userName.substring(0, 10)}
</div>
</td>
<td className={styles.score}>{row.score}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Leaderboard/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function PaginatedItems() {
className={styles.pic}
src={getAvatarByID(row.user.avatarId).url}
></img>
{' ' + row.user.username}
{' ' + row.user.username.substring(0, 10)}
</div>
</td>
<td className={styles.score}>
Expand Down
13 changes: 10 additions & 3 deletions src/components/TourIntroModal/TourIntroModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ import { apiConfig, ApiError } from '../../api/ApiConfig';
import { CurrentUserApi } from '@codecharacter-2023/client';
import Toast from 'react-hot-toast';
import styles from './TourIntroModal.module.css';
import { useAppSelector } from '../../store/hooks';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import { user } from '../../store/User/UserSlice';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useTour } from '@reactour/tour';
import { IsTourOver } from '../../store/DailyChallenge/dailyChallenge';
import {
IsTourOver,
IsTourReset,
isTourResetChanged,
} from '../../store/DailyChallenge/dailyChallenge';

const TourIntroModal = (): JSX.Element => {
const [isTourOpen, setIsTourOpen] = useState(false);
const currentUserApi = new CurrentUserApi(apiConfig);

const User = useAppSelector(user);
const navigate = useNavigate();
const dispatch = useAppDispatch();
const { setIsOpen } = useTour();

const isTourOver = useAppSelector(IsTourOver);
const isTourReset = useAppSelector(IsTourReset);

const handleShowClick = () => {
setIsTourOpen(false);
Expand Down Expand Up @@ -70,10 +76,11 @@ const TourIntroModal = (): JSX.Element => {
currentUserApi.getCurrentUser().then(res => {
if (res.isTutorialComplete === false && res.tutorialLevel < 6) {
setIsTourOpen(true);
dispatch(isTourResetChanged(false));
}
});
}
}, [isTourOver]);
}, [isTourOver, isTourReset]);

return (
<Modal show={isTourOpen} centered onHide={onHide}>
Expand Down
8 changes: 8 additions & 0 deletions src/store/DailyChallenge/dailyChallenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface DailyChallengeStateType {
dcMap: Array<Array<number>>;
isSimulating: boolean;
isTourOver: boolean;
isTourReset: boolean;
}

const initialState: DailyChallengeStateType = {
Expand All @@ -40,6 +41,7 @@ const initialState: DailyChallengeStateType = {
dcMap: [],
isSimulating: false,
isTourOver: false,
isTourReset: false,
};

export const dailyChallengeSlice = createSlice({
Expand Down Expand Up @@ -87,6 +89,9 @@ export const dailyChallengeSlice = createSlice({
isTourOverChanged: (state, action: PayloadAction<boolean>) => {
state.isTourOver = action.payload;
},
isTourResetChanged: (state, action: PayloadAction<boolean>) => {
state.isTourReset = action.payload;
},
},
});

Expand All @@ -98,6 +103,7 @@ export const {
changeDcMap,
changeSimulationState,
isTourOverChanged,
isTourResetChanged,
} = dailyChallengeSlice.actions;
export const dailyChallengeState = (
state: RootState,
Expand All @@ -119,4 +125,6 @@ export const dcSimulation = (state: RootState): boolean =>
state.dailyChallenge.isSimulating;
export const IsTourOver = (state: RootState): boolean =>
state.dailyChallenge.isTourOver;
export const IsTourReset = (state: RootState): boolean =>
state.dailyChallenge.isTourReset;
export default dailyChallengeSlice.reducer;

0 comments on commit 8c44824

Please sign in to comment.