Skip to content

Commit 41e272a

Browse files
fix: unknown error in Rating History,self-match-modal, reset-password redirect,skip tutorial,add intellisense option button (#31)
* fix: unknown error in RatingHistory * fix: self match-make modal and reset-password redirect * fix: skip tutorial * fix: avatarId for user2 and DC icon * Feat : Autocomplete toggle * Fix : Intellisense btn --------- Co-authored-by: shubham-1806 <shub.agarwal2003@gmail.com>
1 parent a8b0a9c commit 41e272a

File tree

11 files changed

+114
-31
lines changed

11 files changed

+114
-31
lines changed

src/components/BattleTV/BattleTV.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import watchIcon from '../../assets/watch.png';
2424
import { useTour } from '@reactour/tour';
2525
import { apiConfig } from '../../api/ApiConfig';
26+
import codecharacterIcon from '../../../public/assets/codechar_favicon.png';
2627

2728
function getIcon(loggedInUser: User, match: Match) {
2829
if (loggedInUser.username === match.user1.username) {
@@ -172,7 +173,12 @@ function PaginatedItems() {
172173
</span>
173174
<div className={styles.picholder}>
174175
<img
175-
src={getAvatarByID(match.user1.avatarId).url}
176+
src={
177+
match.user2 == null
178+
? codecharacterIcon
179+
: getAvatarByID(match.user2?.avatarId as number)
180+
.url
181+
}
176182
className={styles.pic}
177183
></img>
178184
</div>

src/components/Editor/Editor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
isCommitModalOpened,
2424
KeyboardHandler,
2525
Theme,
26+
Autocomplete,
2627
} from '../../store/EditorSettings/settings';
2728

2829
import {
@@ -63,6 +64,7 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
6364
: useAppSelector(dcCode);
6465
const fontSize: number = useAppSelector(FontSize);
6566
const theme: string = useAppSelector(Theme);
67+
const autocomplete: boolean = useAppSelector(Autocomplete);
6668
const dispatch: React.Dispatch<unknown> = useAppDispatch();
6769
const [workspace, setWorkspace] = useState<Editor.Workspace>({
6870
filepath: '',
@@ -113,6 +115,7 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
113115
}
114116

115117
useEffect(() => {
118+
if (!autocomplete) return;
116119
const url = `${lspUrl}/${
117120
props.language == 'c_cpp' ? 'cpp' : props.language
118121
}`;
@@ -143,7 +146,7 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
143146
return () => {
144147
wsClient?.close(1000);
145148
};
146-
}, [props.language]);
149+
}, [props.language, autocomplete]);
147150

148151
useEffect(() => {
149152
if (!divCodeEditor.current) return;

src/components/EditorSettings/EditorSettings.module.css

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,62 @@
1919
font-weight: bold;
2020
}
2121

22+
.autocompletediv{
23+
display: flex;
24+
flex-direction: row;
25+
margin-bottom: 5px;
26+
padding-top: 5px;
27+
padding-left: 10px;
28+
padding-right: 20px;
29+
}
30+
31+
.autocompletebtn{
32+
padding-top: 2px;
33+
padding-left: 15px;
34+
}
35+
36+
.autocompleteLabel{
37+
color:#aaaaaa;
38+
font-family: 'Poppins';
39+
font-weight: 400;
40+
font-size: 18px;
41+
height: 3vh;
42+
margin-bottom: 1.5vh;
43+
padding-top: 0.2rem;
44+
}
45+
46+
.toggle {
47+
width: 55px;
48+
height: 28px;
49+
border-radius: 25px;
50+
background-color: gray;
51+
position: relative;
52+
cursor: pointer;
53+
}
54+
55+
.toggleHandle {
56+
width: 22px;
57+
height: 22px;
58+
border-radius: 50%;
59+
background-color: #fff;
60+
position: absolute;
61+
top: 3.5px;
62+
left: 2.5px;
63+
transition: all 0.3s ease-in-out;
64+
}
65+
66+
.on {
67+
background-color: #232627;
68+
69+
}
70+
71+
.on .toggleHandle {
72+
transform: translateX(25px);
73+
}
74+
75+
.off .toggleHandle {
76+
transform: translateX(0);
77+
}
2278

2379
.editorSettingsBody {
2480
background-color: #1e1e1e;

src/components/EditorSettings/EditorSettings.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
IsSettingsOpen,
99
FontSize,
1010
Theme,
11+
Autocomplete,
12+
autoCompleteChanged,
1113
} from '../../store/EditorSettings/settings';
1214

1315
const EditorSettings = (): JSX.Element => {
@@ -16,6 +18,7 @@ const EditorSettings = (): JSX.Element => {
1618
const theme = useAppSelector(Theme);
1719

1820
const dispatch = useAppDispatch();
21+
const autocomplete = useAppSelector(Autocomplete);
1922

2023
const fontSizeOptions = [];
2124
for (let i = 8; i <= 40; i += 2) {
@@ -32,6 +35,10 @@ const EditorSettings = (): JSX.Element => {
3235
dispatch(themeChanged(newTheme));
3336
}
3437

38+
const handleAutocompleteChange = () => {
39+
dispatch(autoCompleteChanged(!autocomplete));
40+
};
41+
3542
return (
3643
<Modal
3744
show={isSettingsOpen}
@@ -94,6 +101,22 @@ const EditorSettings = (): JSX.Element => {
94101
</select>
95102
</FormGroup>
96103
</Col>
104+
105+
<Col xs={12}>
106+
<div className={styles.autocompletediv}>
107+
<div className={styles.autocompleteLabel}>Intellisense</div>
108+
<div className={styles.autocompletebtn}>
109+
<div
110+
className={`${styles.toggle} ${
111+
autocomplete ? styles.on : styles.off
112+
}`}
113+
onClick={handleAutocompleteChange}
114+
>
115+
<div className={styles.toggleHandle}></div>
116+
</div>
117+
</div>
118+
</div>
119+
</Col>
97120
</Row>
98121
</Container>
99122
</Modal.Body>

src/components/RatingChart/RatingChart.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ function RatingHistoryChart() {
2424
const [items, setItems] = useState<RatingHistory[]>([]);
2525
const [labelItems, setLabelItems] = useState<string[]>([]);
2626
const [dataItems, setDataItems] = useState<number[]>([]);
27-
const [currentUser, setCurrentUser] = useState<string>('');
2827
const userApi = new UserApi(apiConfig);
2928

3029
const labels: string[] = [];
@@ -79,14 +78,10 @@ function RatingHistoryChart() {
7978
useEffect(() => {
8079
const currentUserApi = new CurrentUserApi(apiConfig);
8180
currentUserApi.getCurrentUser().then(response => {
82-
setCurrentUser(response.id);
81+
fetchRatingHistory(response.id);
8382
});
8483
}, []);
8584

86-
useEffect(() => {
87-
fetchRatingHistory();
88-
}, [currentUser]);
89-
9085
useEffect(() => {
9186
items &&
9287
items.map((entry: RatingHistory) => {
@@ -100,9 +95,9 @@ function RatingHistoryChart() {
10095
});
10196
}, [isLoaded]);
10297

103-
function fetchRatingHistory() {
98+
function fetchRatingHistory(id: string) {
10499
setIsLoaded(false);
105-
const ratingHistory = userApi.getRatingHistory(currentUser);
100+
const ratingHistory = userApi.getRatingHistory(id);
106101
ratingHistory
107102
.then(response => {
108103
setItems(response);

src/components/SelfMatchMakingModal/SelfMatchMakeModal.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
MatchMode,
2727
} from '@codecharacter-2023/client';
2828
import Toast from 'react-hot-toast';
29-
import { isloggedIn } from '../../store/User/UserSlice';
3029

3130
const selfMatchModal = (): JSX.Element => {
3231
const IsSelfMatchModalOpen = useAppSelector(isSelfMatchModalOpen);
@@ -37,7 +36,6 @@ const selfMatchModal = (): JSX.Element => {
3736
const dispatch = useAppDispatch();
3837
const [completeCodeHistory, setCodeHistory] = useState<CodeRevision[]>([]);
3938
const [completeMapHistory, setMapHistory] = useState<GameMapRevision[]>([]);
40-
const isLogged = useAppSelector(isloggedIn);
4139

4240
useEffect(() => {
4341
if (localStorage.getItem('token') !== null) {
@@ -72,7 +70,7 @@ const selfMatchModal = (): JSX.Element => {
7270
}
7371
});
7472
}
75-
}, [isLogged]);
73+
}, [IsSelfMatchModalOpen]);
7674

7775
function handleCodeCommitChange(selectedValue: string) {
7876
if (selectedValue === 'Current Code') {

src/components/SideBar/SideBar.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ const SideBar: React.FunctionComponent = () => {
5454

5555
useEffect(() => {
5656
setTimeout(() => {
57-
currentUserApi.getCurrentUser().then(res => {
58-
if (res.isTutorialComplete === false && res.tutorialLevel === 6) {
59-
setIsOpen(true);
60-
}
61-
});
57+
if (localStorage.getItem('token') != null) {
58+
currentUserApi.getCurrentUser().then(res => {
59+
if (res.isTutorialComplete === false && res.tutorialLevel === 6) {
60+
setIsOpen(true);
61+
}
62+
});
63+
}
6264
}, 1000);
6365
}, [isTourOver]);
6466

src/components/TourIntroModal/TourIntroModal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ const TourIntroModal = (): JSX.Element => {
5151
setIsTourOpen(false);
5252
currentUserApi
5353
.updateCurrentUser({
54-
name: User.name,
55-
country: User.country,
56-
college: User.college,
57-
updateTutorialLevel: 'NEXT',
54+
updateTutorialLevel: 'SKIP',
5855
})
5956
.then(() => {
60-
Toast.success('Tutorial skipped successfully');
57+
Toast.success('Tutorial skipped');
6158
})
6259
.catch(err => {
6360
if (err instanceof ApiError) Toast.error(err.message);

src/pages/SideBarWrap/SideBarWrap.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,16 @@ import Tour from '../../components/TourProvider/TourProvider';
33
import { SideBarSteps } from '../../components/TourProvider/SideBarSteps';
44
import { CurrentUserApi } from '@codecharacter-2023/client';
55
import { apiConfig, ApiError } from '../../api/ApiConfig';
6-
import { useAppSelector } from '../../store/hooks';
7-
import { user } from '../../store/User/UserSlice';
86
import Toast from 'react-hot-toast';
97

108
const SideBarWrap = () => {
119
const currentUserApi = new CurrentUserApi(apiConfig);
1210

13-
const User = useAppSelector(user);
14-
1511
const setOpened = (opened: boolean) => {
1612
if (opened === false) {
1713
currentUserApi
1814
.updateCurrentUser({
19-
name: User.name,
20-
country: User.country,
21-
college: User.college,
22-
updateTutorialLevel: 'SKIP',
15+
updateTutorialLevel: 'NEXT',
2316
})
2417
.then(() => {
2518
Toast.success('Tutorial Completed');

src/store/EditorSettings/settings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface settingsStateType {
1010
enableSnippets: boolean;
1111
isInfoOpen: boolean;
1212
isCommitModalOpen: boolean;
13+
autocomplete: boolean;
1314
}
1415

1516
const initialState: settingsStateType = {
@@ -21,6 +22,7 @@ const initialState: settingsStateType = {
2122
enableSnippets: true,
2223
isInfoOpen: false,
2324
isCommitModalOpen: false,
25+
autocomplete: true,
2426
};
2527

2628
export interface CodeAndLanguage {
@@ -56,6 +58,9 @@ export const settingsSlice = createSlice({
5658
isCommitModalOpened: (state, action: PayloadAction<boolean>) => {
5759
state.isCommitModalOpen = action.payload;
5860
},
61+
autoCompleteChanged: (state, action: PayloadAction<boolean>) => {
62+
state.autocomplete = action.payload;
63+
},
5964
},
6065
});
6166

@@ -68,6 +73,7 @@ export const {
6873
enableSnippetsChanged,
6974
isInfoOpened,
7075
isCommitModalOpened,
76+
autoCompleteChanged,
7177
} = settingsSlice.actions;
7278

7379
export const IsSettingsOpen = (state: RootState): boolean =>
@@ -86,5 +92,7 @@ export const IsInfoOpen = (state: RootState): boolean =>
8692
state.codeEditorReducer.settingsState.isInfoOpen;
8793
export const IsCommitModalOpen = (state: RootState): boolean =>
8894
state.codeEditorReducer.settingsState.isCommitModalOpen;
95+
export const Autocomplete = (state: RootState): boolean =>
96+
state.codeEditorReducer.settingsState.autocomplete;
8997

9098
export default settingsSlice.reducer;

0 commit comments

Comments
 (0)