From 8717afbced59f75ab2f180306a8aa67ff45636d4 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 6 May 2026 14:53:55 +0330 Subject: [PATCH] fix ccolor one page --- src/pages/editor/components/EditorCanvas.tsx | 14 +++++---- src/pages/editor/components/SettingsPanel.tsx | 30 ++++++++++++------- .../components/canvas/useDrawingHandlers.ts | 1 - .../editor/components/tools/TextShape.tsx | 28 +++++++++-------- src/pages/editor/store/editorStore.helpers.ts | 3 ++ src/pages/editor/store/editorStore.ts | 28 +++++++++++++++++ src/pages/editor/store/editorStore.types.ts | 3 ++ 7 files changed, 77 insertions(+), 30 deletions(-) diff --git a/src/pages/editor/components/EditorCanvas.tsx b/src/pages/editor/components/EditorCanvas.tsx index 9765f51..5428b9d 100644 --- a/src/pages/editor/components/EditorCanvas.tsx +++ b/src/pages/editor/components/EditorCanvas.tsx @@ -32,6 +32,8 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => { tool, objects, guides, + pages, + currentPageId, selectedObjectId, selectedObjectIds, selectedCellId, @@ -40,17 +42,17 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => { setLayerRef, setGuides, zoom, - documentSettings, } = useEditorStore(); + const currentPage = pages.find((page) => page.id === currentPageId); const bgColor = - documentSettings.backgroundType === 'color' - ? documentSettings.backgroundColor + currentPage?.backgroundType === 'color' + ? currentPage.backgroundColor : '#ffffff'; const [bgImage] = useImage( - documentSettings.backgroundType === 'image' - ? documentSettings.backgroundImageUrl + currentPage?.backgroundType === 'image' + ? (currentPage.backgroundImageUrl || '') : '', ); const stageSize = useStageSize(catalogSize); @@ -394,7 +396,7 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => { fill={bgColor} listening={false} /> - {documentSettings.backgroundType === 'image' && bgImage && ( + {currentPage?.backgroundType === 'image' && bgImage && ( { - const { documentSettings, updateDocumentSettings } = useEditorStore() + const { + documentSettings, + pages, + currentPageId, + updateDocumentSettings, + updateCurrentPageBackground, + } = useEditorStore() const colorInputRef = useRef(null) const { mutateAsync: uploadFile, isPending: imageLoading } = useSingleUpload() + const currentPage = pages.find((page) => page.id === currentPageId) + const backgroundType = currentPage?.backgroundType ?? 'color' + const backgroundColor = currentPage?.backgroundColor ?? '#ffffff' + const backgroundImageUrl = currentPage?.backgroundImageUrl ?? '' const [uploadedPreviews, setUploadedPreviews] = useState( - documentSettings.backgroundImageUrl ? [documentSettings.backgroundImageUrl] : [] + backgroundImageUrl ? [backgroundImageUrl] : [] ) const { @@ -39,15 +49,13 @@ const SettingsPanel = () => { autoPlay, pageFlipSound, leftToRightFlip, - backgroundType, - backgroundColor, } = documentSettings useEffect(() => { setUploadedPreviews( - documentSettings.backgroundImageUrl ? [documentSettings.backgroundImageUrl] : [] + backgroundImageUrl ? [backgroundImageUrl] : [] ) - }, [documentSettings.backgroundImageUrl]) + }, [backgroundImageUrl]) const handleImageFiles = async (files: File[]) => { if (files.length === 0) return @@ -59,7 +67,7 @@ const SettingsPanel = () => { const imageUrl = result?.data?.url if (!imageUrl) return - updateDocumentSettings({ backgroundImageUrl: imageUrl }) + updateCurrentPageBackground({ backgroundImageUrl: imageUrl }) setUploadedPreviews([imageUrl]) } catch { // TODO: show error toast @@ -69,7 +77,7 @@ const SettingsPanel = () => { const handlePreviewChange = (previews: string[]) => { setUploadedPreviews(previews) if (previews.length === 0) { - updateDocumentSettings({ backgroundImageUrl: '' }) + updateCurrentPageBackground({ backgroundImageUrl: '' }) } } @@ -137,7 +145,7 @@ const SettingsPanel = () => {