This commit is contained in:
karimalden 2024-07-03 21:36:56 +03:00
parent b34ba269c1
commit fad0d81565
5 changed files with 57 additions and 29 deletions

View 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;

View File

@ -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<ParamsEnum>();
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();

View File

@ -102,27 +102,7 @@ export const CrudRoute: TCrudRoute[] = [
abilities: ABILITIES_ENUM?.QUESTION,
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,
// },
];

View File

@ -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/";

12
src/zustand/Location.ts Normal file
View 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 })),
}));