end
This commit is contained in:
parent
b34ba269c1
commit
fad0d81565
32
src/Hooks/usePreviousRoute.tsx
Normal file
32
src/Hooks/usePreviousRoute.tsx
Normal file
|
|
@ -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;
|
||||||
|
|
@ -15,6 +15,9 @@ import { ModalEnum } from "../../enums/Model";
|
||||||
import ChangePasswordModel from "./model/AddModel";
|
import ChangePasswordModel from "./model/AddModel";
|
||||||
import { getLocalStorage } from "../../utils/LocalStorage";
|
import { getLocalStorage } from "../../utils/LocalStorage";
|
||||||
import NavBarSelect from "../../Components/Layout/NavBarSelect";
|
import NavBarSelect from "../../Components/Layout/NavBarSelect";
|
||||||
|
import usePreviousRoute from "../../Hooks/usePreviousRoute";
|
||||||
|
import usePreviousPath from "../../Hooks/usePreviousRoute";
|
||||||
|
import { useLocationsState } from "../../zustand/Location";
|
||||||
const NavBar = () => {
|
const NavBar = () => {
|
||||||
const { Page_title } = usePage_titleState((state) => state);
|
const { Page_title } = usePage_titleState((state) => state);
|
||||||
const userData = getLocalStorage(USER_KEY);
|
const userData = getLocalStorage(USER_KEY);
|
||||||
|
|
@ -25,19 +28,20 @@ const NavBar = () => {
|
||||||
const translateArray = translateOptions(search_array, t);
|
const translateArray = translateOptions(search_array, t);
|
||||||
const { course_id } = useParams<ParamsEnum>();
|
const { course_id } = useParams<ParamsEnum>();
|
||||||
console.log(location);
|
console.log(location);
|
||||||
|
const {PreLocation} = useLocationsState()
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
|
||||||
const handelNavigate = () => {
|
const handelNavigate = () => {
|
||||||
const pattern = /^\/course\/\d+\/eduClass\/\d+$/;
|
const pattern = /^\/course\/\d+\/eduClass\/\d+$/;
|
||||||
if (pattern.test(location.pathname)) {
|
if (pattern.test(location.pathname)) {
|
||||||
navigate(`/course/${course_id}/eduClass`);
|
navigate(`/course/${course_id}/eduClass`);
|
||||||
return;
|
return;
|
||||||
|
}else if (PreLocation) {
|
||||||
|
navigate(PreLocation)
|
||||||
|
}else{
|
||||||
|
navigate(-1)
|
||||||
}
|
}
|
||||||
if (location.pathname === "/") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
navigate(-1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
|
|
|
||||||
|
|
@ -102,27 +102,7 @@ export const CrudRoute: TCrudRoute[] = [
|
||||||
abilities: ABILITIES_ENUM?.QUESTION,
|
abilities: ABILITIES_ENUM?.QUESTION,
|
||||||
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// header: "page_header.Question_child",
|
|
||||||
// element: <QuestionChildren />,
|
|
||||||
// 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: <AddQuestionChildren />,
|
|
||||||
// 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: <EditQuestionChildren />,
|
|
||||||
// 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,
|
|
||||||
// },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// export const BaseURL = "http://192.168.1.108: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 = "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/";
|
export const ImageBaseURL = "http://192.168.1.9:8000/";
|
||||||
|
|
||||||
|
|
|
||||||
12
src/zustand/Location.ts
Normal file
12
src/zustand/Location.ts
Normal file
|
|
@ -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<LocationsState>((set) => ({
|
||||||
|
PreLocation: "",
|
||||||
|
setPreLocation: (value: string) => set((state) => ({ PreLocation: value })),
|
||||||
|
}));
|
||||||
Loading…
Reference in New Issue
Block a user