Skip to content

Commit 7227de3

Browse files
authored
Merge pull request #560 from Yavuzlar/559-bug-fix-on-frontend
Bugs fixed on Frontend.
2 parents 3b38770 + cc374c6 commit 7227de3

File tree

18 files changed

+139
-100
lines changed

18 files changed

+139
-100
lines changed

frontend/src/components/cards/Activity.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const CustomSelect = styled(Select)({
2727

2828
const Activity = () => {
2929
const dispatch = useDispatch();
30-
const { activity: activityData } = useSelector((state) => state);
30+
// const { activity: activityData } = useSelector((state) => state);
31+
const activityData = useSelector((state) => state.activity);
3132

3233
const data = activityData.data.data;
3334

frontend/src/components/cards/LabInfo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { theme } from "src/configs/theme";
1313

1414
const LabInfo = ({ programingId, filter, setIconPath, containerLoading }) => {
1515
const dispatch = useDispatch();
16-
const { lab: stateLabs } = useSelector((state) => state);
16+
// const { lab: stateLabs } = useSelector((state) => state);
17+
const stateLabs = useSelector((state) => state.lab);
1718

1819
const router = useRouter();
1920

@@ -158,8 +159,7 @@ const LabInfo = ({ programingId, filter, setIconPath, containerLoading }) => {
158159
>
159160
{containerLoading ? (
160161
<CircularProgress size={24} sx={{ position: "absolute" }} />
161-
) :
162-
lab.isFinished ? (
162+
) : lab.isFinished ? (
163163
<Translations text={"lab.button.review"} />
164164
) : (
165165
<Translations text={"lab.button.solve"} />

frontend/src/components/cards/Timestatistic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const Timestatistic = () => {
3434

3535
const dispatch = useDispatch();
3636

37-
const { log: logStatistics } = useSelector((state) => state);
37+
// const { log: logStatistics } = useSelector((state) => state);
38+
const logStatistics = useSelector((state) => state.log);
3839

3940
useEffect(() => {
4041
dispatch(getSolitionWeek());

frontend/src/components/filter/FilterUser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const FilterUser = ({
4444
onChange={(e) => setFilters({ ...filters, search: e.target.value })}
4545
InputProps={{
4646
startAdornment: (
47-
<InputAdornment sx={{ zIndex: 10, mr: 1 }}>
47+
<InputAdornment position="start" sx={{ zIndex: 10, mr: 1 }}>
4848
<Search />
4949
</InputAdornment>
5050
),

frontend/src/configs/i18n.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,65 @@
1+
// import i18n from "i18next";
2+
// import { initReactI18next } from "react-i18next";
3+
// import Backend from "i18next-http-backend";
4+
// import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
5+
// import themeConfig from "./themeConfig";
6+
7+
// i18n
8+
9+
// // Enables the i18next backend
10+
// .use(Backend)
11+
12+
// // Enable automatic language detection
13+
// .use(I18nextBrowserLanguageDetector)
14+
15+
// // Enables the hook initialization module
16+
// .use(initReactI18next)
17+
// .init({
18+
// lng: "en",
19+
// defaultLng: themeConfig.defaultLng,
20+
// backend: {
21+
// /* translation file path */
22+
// loadPath: "/locales/{{lng}}/common.json",
23+
// },
24+
// fallbackLng: themeConfig.defaultLng,
25+
// debug: false,
26+
// keySeparator: false,
27+
// react: {
28+
// useSuspense: false,
29+
// },
30+
// interpolation: {
31+
// escapeValue: false,
32+
// formatSeparator: ",",
33+
// },
34+
// });
35+
36+
// export default i18n;
37+
38+
// i18n.js
39+
140
import i18n from "i18next";
241
import { initReactI18next } from "react-i18next";
342
import Backend from "i18next-http-backend";
443
import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
544
import themeConfig from "./themeConfig";
645

746
i18n
8-
9-
// Enables the i18next backend
1047
.use(Backend)
11-
12-
// Enable automatic language detection
1348
.use(I18nextBrowserLanguageDetector)
14-
15-
// Enables the hook initialization module
1649
.use(initReactI18next)
1750
.init({
18-
lng: "en",
51+
fallbackLng: themeConfig.defaultLng,
52+
1953
backend: {
20-
/* translation file path */
2154
loadPath: "/locales/{{lng}}/common.json",
2255
},
23-
fallbackLng: themeConfig.defaultLng,
56+
57+
detection: {
58+
order: ["localStorage", "navigator", "cookie", "htmlTag"],
59+
60+
caches: ["localStorage"],
61+
},
62+
2463
debug: false,
2564
keySeparator: false,
2665
react: {

frontend/src/context/AuthContext.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const AuthProvider = ({ children }) => {
4343
}
4444
ws.current = new WebSocket("ws://localhost/api/v1/private/socket/ws");
4545

46-
ws.current.onopen = () => { };
46+
ws.current.onopen = () => {};
4747

4848
ws.current.onmessage = (e) => {
4949
const data = JSON.parse(e.data);
@@ -145,8 +145,8 @@ const AuthProvider = ({ children }) => {
145145

146146
const initAuth = () => {
147147
const storedUserData = localStorage.getItem(authConfig.userDataName);
148-
149-
if (["/login", "/register"].includes(router.pathname)) {
148+
149+
if (["/login", "/register"]?.includes(router.pathname)) {
150150
if (storedUserData) {
151151
try {
152152
const userData = JSON.parse(storedUserData);
@@ -256,9 +256,34 @@ const AuthProvider = ({ children }) => {
256256
}
257257
};
258258

259+
// useEffect(() => {
260+
// initAuth();
261+
// }, [router.pathname]);
262+
263+
// useEffect(() => {
264+
// initAuth();
265+
// }, []);
266+
259267
useEffect(() => {
260268
initAuth();
261-
}, [router.pathname]);
269+
270+
const responseInterceptor = axios.interceptors.response.use(
271+
(response) => {
272+
return response;
273+
},
274+
(error) => {
275+
if (error.response && error.response.status === 401) {
276+
handleLogout();
277+
}
278+
279+
return Promise.reject(error);
280+
}
281+
);
282+
283+
return () => {
284+
axios.interceptors.response.eject(responseInterceptor);
285+
};
286+
}, []);
262287

263288
const values = {
264289
user,

frontend/src/layout/components/navigation/item/LanguageSelector.js

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,42 @@
11
import { Button, Menu, MenuItem, Typography } from "@mui/material";
2-
import { useEffect, useState } from "react";
2+
import { useState, useEffect } from "react";
33
import Image from "next/image";
44
import Turkish from "src/assets/flags/turkish.png";
55
import English from "src/assets/flags/english.png";
66
import { useTranslation } from "react-i18next";
77

88
const LanguageSelector = () => {
99
const [anchorEl, setAnchorEl] = useState(null);
10+
const { i18n, t } = useTranslation();
11+
1012
const open = Boolean(anchorEl);
13+
14+
const currentLanguageCode = i18n.language;
15+
1116
const handleClick = (event) => {
1217
setAnchorEl(event.currentTarget);
1318
};
19+
1420
const handleClose = () => {
1521
setAnchorEl(null);
1622
};
17-
const [language, setLanguage] = useState("turkish");
18-
19-
const { i18n } = useTranslation();
20-
21-
useEffect(() => {
22-
switch (language) {
23-
case "turkish":
24-
i18n.changeLanguage("tr");
25-
break;
26-
27-
case "english":
28-
i18n.changeLanguage("en");
2923

30-
default:
31-
i18n.changeLanguage("en");
32-
break;
33-
}
34-
}, [language]);
24+
const handleLanguageChange = (langCode) => {
25+
i18n.changeLanguage(langCode);
26+
handleClose();
27+
};
3528

3629
useEffect(() => {
3730
const handleResize = () => {
3831
setAnchorEl(null);
3932
};
4033
window.addEventListener("resize", handleResize);
4134
return () => window.removeEventListener("resize", handleResize);
42-
}, [setAnchorEl]);
35+
}, []);
4336

44-
const { t } = useTranslation();
4537
const tr = t("languages.tr");
4638
const en = t("languages.en");
4739

48-
useEffect(() => {
49-
const handleResize = () => {
50-
setAnchorEl(null);
51-
};
52-
window.addEventListener("resize", handleResize);
53-
return () => window.removeEventListener("resize", handleResize);
54-
}, [setAnchorEl]);
55-
5640
return (
5741
<>
5842
<Button
@@ -63,14 +47,12 @@ const LanguageSelector = () => {
6347
sx={{ backgroundColor: "transparent" }}
6448
onClick={handleClick}
6549
>
66-
{language === "turkish" && (
67-
<Image src={Turkish} alt="Turkish" width={24} height={24} />
68-
)}
69-
70-
{language === "english" && (
71-
<Image src={English} alt="English" width={24} height={24} />
72-
)}
73-
50+
<Image
51+
src={currentLanguageCode === "tr" ? Turkish : English}
52+
alt={currentLanguageCode === "tr" ? "Turkish Flag" : "English Flag"}
53+
width={24}
54+
height={24}
55+
/>
7456
<Typography
7557
sx={{
7658
fontWeight: 300,
@@ -80,9 +62,7 @@ const LanguageSelector = () => {
8062
ml: 0.5,
8163
}}
8264
>
83-
{language === "turkish" && tr}
84-
85-
{language === "english" && en}
65+
{currentLanguageCode === "tr" ? tr : en}
8666
</Typography>
8767
</Button>
8868
<Menu
@@ -95,22 +75,8 @@ const LanguageSelector = () => {
9575
}}
9676
sx={{ mt: 1, "& .MuiMenu-paper": { backgroundColor: "#0A3B7A" } }}
9777
>
98-
<MenuItem
99-
onClick={(e) => {
100-
setLanguage("turkish");
101-
setAnchorEl(false);
102-
}}
103-
>
104-
{tr}
105-
</MenuItem>
106-
<MenuItem
107-
onClick={(e) => {
108-
setLanguage("english");
109-
setAnchorEl(false);
110-
}}
111-
>
112-
{en}
113-
</MenuItem>
78+
<MenuItem onClick={() => handleLanguageChange("tr")}>{tr}</MenuItem>
79+
<MenuItem onClick={() => handleLanguageChange("en")}>{en}</MenuItem>
11480
</Menu>
11581
</>
11682
);

frontend/src/layout/components/navigation/item/SingleItem.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const SingleItem = (props) => {
1515

1616
const router = useRouter();
1717

18-
// Sayfaya gitmek için kullanılacak fonksiyon
1918
const handleLocate = (p) => {
2019
if (p) {
21-
router.replace(p);
20+
// router.replace(p);
21+
router.push(p);
2222
}
2323
ChangePage();
2424
};
@@ -41,7 +41,6 @@ const SingleItem = (props) => {
4141
sx={style}
4242
onKeyDown={handleKeyPress}
4343
variant="text"
44-
active={router.pathname == path}
4544
onClick={() => handleLocate(path)}
4645
>
4746
<Typography

frontend/src/pages/404.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Error404 = () => {
5959
if (window.history.length > 2) {
6060
router.back();
6161
setTimeout(() => {
62-
if (window.location.pathname.includes("404")) {
62+
if (router.push?.pathname?.includes("404")) {
6363
window.history.go(-2);
6464
}
6565
}, 100);

frontend/src/pages/_app.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,6 @@ const App = (props) => {
6969
<title>{`${themeConfig.projectName}`}</title>
7070
<meta name="description" content={`${themeConfig.projectName}`} />
7171
<meta name="viewport" content="initial-scale=1, width=device-width" />
72-
<link
73-
href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;700&display=swap&subset=latin-ext"
74-
rel="stylesheet"
75-
></link>
76-
77-
<link
78-
href="https://fonts.cdnfonts.com/css/cascadia-code"
79-
rel="stylesheet"
80-
></link>
81-
<link
82-
href="https://fonts.cdnfonts.com/css/nunito"
83-
rel="stylesheet"
84-
></link>
8572
</Head>
8673

8774
<AuthProvider>

0 commit comments

Comments
 (0)