diff --git a/src/Hooks/usePreviousRoute.tsx b/src/Hooks/usePreviousRoute.tsx new file mode 100644 index 0000000..7b5f806 --- /dev/null +++ b/src/Hooks/usePreviousRoute.tsx @@ -0,0 +1,32 @@ +import { useEffect, useState } from 'react'; +import { useLocation, useNavigate } from 'react-router-dom'; + +const usePreviousPath = () => { + const location = useLocation(); + const navigate = useNavigate(); + const [previousPath, setPreviousPath] = useState(null); + console.log(previousPath); + + useEffect(() => { + // Update the previous path whenever the location changes + const currentPath = location.pathname as any; + setPreviousPath(currentPath); + + // Clean up + return () => { + setPreviousPath(null); + }; + }, [location]); + + const navigateToPreviousPath = () => { + if (previousPath) { + navigate(previousPath); + } else { + navigate(-1); // Fallback to default behavior + } + }; + + return { navigateToPreviousPath }; +}; + +export default usePreviousPath; diff --git a/src/Layout/Ui/NavBar.tsx b/src/Layout/Ui/NavBar.tsx index e4d7474..86a4764 100644 --- a/src/Layout/Ui/NavBar.tsx +++ b/src/Layout/Ui/NavBar.tsx @@ -15,6 +15,9 @@ import { ModalEnum } from "../../enums/Model"; import ChangePasswordModel from "./model/AddModel"; import { getLocalStorage } from "../../utils/LocalStorage"; import NavBarSelect from "../../Components/Layout/NavBarSelect"; +import usePreviousRoute from "../../Hooks/usePreviousRoute"; +import usePreviousPath from "../../Hooks/usePreviousRoute"; +import { useLocationsState } from "../../zustand/Location"; const NavBar = () => { const { Page_title } = usePage_titleState((state) => state); const userData = getLocalStorage(USER_KEY); @@ -25,19 +28,20 @@ const NavBar = () => { const translateArray = translateOptions(search_array, t); const { course_id } = useParams(); console.log(location); - + const {PreLocation} = useLocationsState() const navigate = useNavigate(); + const handelNavigate = () => { const pattern = /^\/course\/\d+\/eduClass\/\d+$/; if (pattern.test(location.pathname)) { navigate(`/course/${course_id}/eduClass`); return; + }else if (PreLocation) { + navigate(PreLocation) + }else{ + navigate(-1) } - if (location.pathname === "/") { - return; - } - navigate(-1); }; const { handel_open_model } = useModalHandler(); diff --git a/src/Routes.tsx b/src/Routes.tsx index 9b244c3..c287513 100644 --- a/src/Routes.tsx +++ b/src/Routes.tsx @@ -102,27 +102,7 @@ export const CrudRoute: TCrudRoute[] = [ abilities: ABILITIES_ENUM?.QUESTION, abilities_value: ABILITIES_VALUES_ENUM.INDEX, }, - // { - // header: "page_header.Question_child", - // element: , - // path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.CHILDREN_QUESTION_ID}/children`, - // abilities: ABILITIES_ENUM?.QUESTION, - // abilities_value: ABILITIES_VALUES_ENUM.INDEX, - // }, - // { - // header: "page_header.add_Question_child", - // element: , - // path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.CHILDREN_QUESTION_ID}/children/add`, - // abilities: ABILITIES_ENUM?.QUESTION, - // abilities_value: ABILITIES_VALUES_ENUM.INDEX, - // }, - // { - // header: "page_header.edit_Question_child", - // element: , - // path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.CHILDREN_QUESTION_ID}/children/:${ParamsEnum?.CHILDREN_QUESTION_ID}`, - // abilities: ABILITIES_ENUM?.QUESTION, - // abilities_value: ABILITIES_VALUES_ENUM.INDEX, - // }, + ]; diff --git a/src/api/config.ts b/src/api/config.ts index 5d922ad..1f68632 100644 --- a/src/api/config.ts +++ b/src/api/config.ts @@ -1,7 +1,7 @@ -// export const BaseURL = "http://192.168.1.108:8000/api/"; -export const BaseURL = "http://127.0.0.1:8000/api/"; +// export const BaseURL = "http://192.168.1.109:8000/api/"; +// export const BaseURL = "http://127.0.0.1:8000/api/"; -// export const BaseURL = "https://exercise-automation.point-dev.net/api/"; +export const BaseURL = "https://exercise-automation.point-dev.net/api/"; export const ImageBaseURL = "http://192.168.1.9:8000/"; diff --git a/src/zustand/Location.ts b/src/zustand/Location.ts new file mode 100644 index 0000000..8e084d6 --- /dev/null +++ b/src/zustand/Location.ts @@ -0,0 +1,12 @@ +import { create } from "zustand"; +import { ModalEnum } from "../enums/Model"; + +interface LocationsState{ + PreLocation: string; + setPreLocation: (value: string) => void; +} + +export const useLocationsState= create((set) => ({ + PreLocation: "", + setPreLocation: (value: string) => set((state) => ({ PreLocation: value })), +}));