From face0a30d9008b8f0db5475d77d4ac5863d138ed Mon Sep 17 00:00:00 2001 From: alij Date: Wed, 3 Jul 2024 14:51:40 +0330 Subject: [PATCH] feat : optimaze code by eslint --- src/App.tsx | 5 ++- src/common/modal/index.tsx | 13 +++--- .../header/components/navbar/Navbar.tsx | 6 +-- src/components/loaderSpin/index.tsx | 2 - src/hooks/useAxios.ts | 2 +- src/http.ts | 41 ------------------- src/index.css | 9 ++++ 7 files changed, 24 insertions(+), 54 deletions(-) delete mode 100644 src/http.ts diff --git a/src/App.tsx b/src/App.tsx index e842733..889a3fd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,7 +15,7 @@ import AuthLayout from "./layout/AuthLayout"; import Login from "./pages/login"; import Profile from "./pages/profile"; import { Toaster } from "react-hot-toast"; -import { isAuthenticated } from "./utils/auth"; +import { IsAuthenticated } from "./utils/auth"; import { HelmetProvider } from "react-helmet-async"; const App = () => { @@ -31,6 +31,7 @@ const App = () => { }> } /> + } /> } /> } /> } /> @@ -41,7 +42,7 @@ const App = () => { ) : ( diff --git a/src/common/modal/index.tsx b/src/common/modal/index.tsx index eae49f7..1f1b44f 100644 --- a/src/common/modal/index.tsx +++ b/src/common/modal/index.tsx @@ -1,5 +1,5 @@ import Modal from "@mui/material/Modal"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { motion } from "framer-motion"; import { IoClose } from "react-icons/io5"; import Button from "../../components/button"; @@ -17,15 +17,15 @@ export default function MuiModal({ }: MuiModalProps) { const [open, setOpen] = useState(false); const handleOpen = () => setOpen(true); - const handleClose = () => { + const handleClose = useCallback(() => { setOpen(false); setIsOpenModal(false); - }; + }, [setIsOpenModal]); useEffect(() => { if (isOpenModal) handleOpen(); else handleClose(); - }, [isOpenModal]); + }, [isOpenModal, handleClose]); return (
@@ -63,7 +63,10 @@ export default function MuiModal({ > {submitText && ( - + )} diff --git a/src/components/header/components/navbar/Navbar.tsx b/src/components/header/components/navbar/Navbar.tsx index 84f1788..571dbdc 100644 --- a/src/components/header/components/navbar/Navbar.tsx +++ b/src/components/header/components/navbar/Navbar.tsx @@ -7,11 +7,11 @@ import router from "../../../../routes/routes"; import Button from "../../../button"; import { useNavigate } from "react-router-dom"; import { Route } from "../../../../types/props"; -import { isAuthenticated } from "../../../../utils/auth"; +import { IsAuthenticated } from "../../../../utils/auth"; const Navbar = ({extra}:{extra?:string}) => { const [isOpen, setIsOpen] = useState(false); - const auth = isAuthenticated(); + const auth = IsAuthenticated(); const [routes] = useState(router); const navigate = useNavigate(); @@ -46,7 +46,7 @@ const Navbar = ({extra}:{extra?:string}) => { {auth ? ( ) : ( - + )}
diff --git a/src/components/loaderSpin/index.tsx b/src/components/loaderSpin/index.tsx index 32dd1f5..67a43a7 100644 --- a/src/components/loaderSpin/index.tsx +++ b/src/components/loaderSpin/index.tsx @@ -1,5 +1,3 @@ -import React from "react"; - const LoaderSpin = ({ children }: { children: React.ReactNode }) => { return (
diff --git a/src/hooks/useAxios.ts b/src/hooks/useAxios.ts index 28aa650..c7bb626 100644 --- a/src/hooks/useAxios.ts +++ b/src/hooks/useAxios.ts @@ -8,7 +8,7 @@ const useAxios = () => { const navigate = useNavigate(); const instance = axios.create({ - baseURL: "https://api.soheilkhaledabadi.ir/api/v1", + baseURL: "https://api.persain-game.com/api/v1", maxBodyLength: Infinity, }); diff --git a/src/http.ts b/src/http.ts deleted file mode 100644 index 842c92c..0000000 --- a/src/http.ts +++ /dev/null @@ -1,41 +0,0 @@ -import axios from "axios"; -import store from "./redux/store"; -import { setToken } from "./redux/slices/token"; -import { useNavigate } from "react-router-dom"; - - -const navigate = useNavigate() - -const instance = axios.create({ - baseURL: "https://api.soheilkhaledabadi.ir/api/v1", - maxBodyLength: Infinity, -}); - -axios.interceptors.request.use( - (config) => { - const state = store.getState(); - const token = state.token.token; - if (token) { - config.headers.Authorization = `Bearer ${token}`; - } - return config; - }, - (error) => { - return Promise.reject(error); - } -); - -axios.interceptors.response.use( - (response) => { - return response; - }, - (error) => { - if (error.response && error.response.status === 401) { - navigate('/login') - store.dispatch(setToken('')); - } - return Promise.reject(error); - } -); - -export default instance; diff --git a/src/index.css b/src/index.css index 05b6748..dd35e51 100644 --- a/src/index.css +++ b/src/index.css @@ -99,4 +99,13 @@ input[type="number"] { -moz-appearance: textfield; } + button { + -webkit-appearance: none; /* غیرفعال کردن سبک پیش‌فرض Safari */ + appearance: none; /* غیرفعال کردن سبک پیش‌فرض */ + } + *, + *::before, + *::after { + box-sizing: border-box; + } }