This commit is contained in:
@@ -3,6 +3,7 @@ import { usePageTitle } from "@/hooks/usePageTitle";
|
|||||||
import Konva from "konva";
|
import Konva from "konva";
|
||||||
import { type FC, useEffect, useRef, useState } from "react";
|
import { type FC, useEffect, useRef, useState } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
import { useSharedStore } from "@/shared/store/sharedStore";
|
||||||
import { useGetCatalogById, useUpdateCatalog } from "../home/hooks/useHomeData";
|
import { useGetCatalogById, useUpdateCatalog } from "../home/hooks/useHomeData";
|
||||||
import EditorCanvas from "./components/EditorCanvas";
|
import EditorCanvas from "./components/EditorCanvas";
|
||||||
import EditorSidebar from "./components/EditorSidebar";
|
import EditorSidebar from "./components/EditorSidebar";
|
||||||
@@ -34,8 +35,26 @@ const Editor: FC = () => {
|
|||||||
objects,
|
objects,
|
||||||
currentPageId,
|
currentPageId,
|
||||||
} = useEditorStore();
|
} = useEditorStore();
|
||||||
|
const { setEditorCatalogSlug } = useSharedStore();
|
||||||
const { data, isFetched } = useGetCatalogById(id!);
|
const { data, isFetched } = useGetCatalogById(id!);
|
||||||
const catalogName = data?.data?.name;
|
const catalogName = data?.data?.name;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setEditorCatalogSlug(null);
|
||||||
|
}, [id, setEditorCatalogSlug]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data?.data?.slug) {
|
||||||
|
setEditorCatalogSlug(data.data.slug);
|
||||||
|
}
|
||||||
|
}, [data?.data?.slug, setEditorCatalogSlug]);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
setEditorCatalogSlug(null);
|
||||||
|
},
|
||||||
|
[setEditorCatalogSlug],
|
||||||
|
);
|
||||||
usePageTitle(
|
usePageTitle(
|
||||||
catalogName ? `ویرایش کاتالوگ ${catalogName}` : "ویرایش کاتالوگ",
|
catalogName ? `ویرایش کاتالوگ ${catalogName}` : "ویرایش کاتالوگ",
|
||||||
);
|
);
|
||||||
|
|||||||
+9
-18
@@ -4,10 +4,6 @@ import { type FC, useEffect } from "react";
|
|||||||
// import AvatarImage from '../assets/images/avatar_image.png'
|
// import AvatarImage from '../assets/images/avatar_image.png'
|
||||||
import { Paths } from "@/config/Paths";
|
import { Paths } from "@/config/Paths";
|
||||||
import { clx } from "@/helpers/utils";
|
import { clx } from "@/helpers/utils";
|
||||||
import {
|
|
||||||
isCatalogMongoId,
|
|
||||||
useGetCatalogByIdOrSlug,
|
|
||||||
} from "@/pages/home/hooks/useHomeData";
|
|
||||||
import { useSharedStore } from "@/shared/store/sharedStore";
|
import { useSharedStore } from "@/shared/store/sharedStore";
|
||||||
import { Eye, HambergerMenu } from "iconsax-react";
|
import { Eye, HambergerMenu } from "iconsax-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -41,24 +37,19 @@ const Header: FC<HeaderProps> = ({
|
|||||||
// const location = useLocation();
|
// const location = useLocation();
|
||||||
// const [popoverKey, setPopoverKey] = useState(0);
|
// const [popoverKey, setPopoverKey] = useState(0);
|
||||||
const { t } = useTranslation("global");
|
const { t } = useTranslation("global");
|
||||||
const { setOpenSidebar, openSidebar, hasSubMenu, setSearch } =
|
const {
|
||||||
useSharedStore();
|
setOpenSidebar,
|
||||||
|
openSidebar,
|
||||||
|
hasSubMenu,
|
||||||
|
setSearch,
|
||||||
|
editorCatalogSlug,
|
||||||
|
} = useSharedStore();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const editorPathPrefix = `${Paths.editor}/`;
|
const editorPathPrefix = `${Paths.editor}/`;
|
||||||
const isEditorRoute =
|
const isEditorRoute =
|
||||||
location.pathname.startsWith(editorPathPrefix) &&
|
location.pathname.startsWith(editorPathPrefix) &&
|
||||||
location.pathname.length > editorPathPrefix.length;
|
location.pathname.length > editorPathPrefix.length;
|
||||||
const editorRouteParam = isEditorRoute
|
const viewerSlug = isEditorRoute ? (editorCatalogSlug ?? "") : "";
|
||||||
? (location.pathname.slice(editorPathPrefix.length).split("/")[0] ?? "")
|
|
||||||
: "";
|
|
||||||
const { data: catalogData } = useGetCatalogByIdOrSlug(
|
|
||||||
isEditorRoute && editorRouteParam ? editorRouteParam : "",
|
|
||||||
);
|
|
||||||
const viewerSlug =
|
|
||||||
catalogData?.data?.slug ??
|
|
||||||
(editorRouteParam && !isCatalogMongoId(editorRouteParam)
|
|
||||||
? editorRouteParam
|
|
||||||
: "");
|
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// setPopoverKey((prevKey) => prevKey + 1);
|
// setPopoverKey((prevKey) => prevKey + 1);
|
||||||
@@ -103,7 +94,7 @@ const Header: FC<HeaderProps> = ({
|
|||||||
{isEditorRoute && viewerSlug ? (
|
{isEditorRoute && viewerSlug ? (
|
||||||
<Link
|
<Link
|
||||||
target="_blank"
|
target="_blank"
|
||||||
to={`${Paths.viewer}/${viewerSlug}`}
|
to={`${Paths.viewerBySlug}/${viewerSlug}`}
|
||||||
className="flex items-center"
|
className="flex items-center"
|
||||||
aria-label={t("header.open_viewer")}
|
aria-label={t("header.open_viewer")}
|
||||||
title={t("header.open_viewer")}
|
title={t("header.open_viewer")}
|
||||||
|
|||||||
@@ -10,4 +10,6 @@ export const useSharedStore = create<SharedStoreType>((set) => ({
|
|||||||
setSubMenuName: (value: string) => set({ subMenuName: value }),
|
setSubMenuName: (value: string) => set({ subMenuName: value }),
|
||||||
search: "",
|
search: "",
|
||||||
setSearch: (value: string) => set({ search: value }),
|
setSearch: (value: string) => set({ search: value }),
|
||||||
|
editorCatalogSlug: null,
|
||||||
|
setEditorCatalogSlug: (slug) => set({ editorCatalogSlug: slug }),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export type SharedStoreType = {
|
|||||||
setSubMenuName: (value: string) => void;
|
setSubMenuName: (value: string) => void;
|
||||||
search: string;
|
search: string;
|
||||||
setSearch: (value: string) => void;
|
setSearch: (value: string) => void;
|
||||||
|
editorCatalogSlug: string | null;
|
||||||
|
setEditorCatalogSlug: (slug: string | null) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PagerType = {
|
export type PagerType = {
|
||||||
|
|||||||
Reference in New Issue
Block a user