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