From 4d67e366ad23e1d3b23b6bc33d4b4a4eefa6e7c5 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Fri, 11 Jul 2025 03:52:39 +0200 Subject: feat: background settings (color, blur) --- apps/web/src/stores/project-store.ts | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'apps/web/src/stores') diff --git a/apps/web/src/stores/project-store.ts b/apps/web/src/stores/project-store.ts index 9570f4a0..913c6810 100644 --- a/apps/web/src/stores/project-store.ts +++ b/apps/web/src/stores/project-store.ts @@ -20,6 +20,11 @@ interface ProjectStore { closeProject: () => void; renameProject: (projectId: string, name: string) => Promise; duplicateProject: (projectId: string) => Promise; + updateProjectBackground: (backgroundColor: string) => Promise; + updateBackgroundType: ( + type: "color" | "blur", + options?: { backgroundColor?: string; blurIntensity?: number } + ) => Promise; } export const useProjectStore = create((set, get) => ({ @@ -35,6 +40,9 @@ export const useProjectStore = create((set, get) => ({ thumbnail: "", createdAt: new Date(), updatedAt: new Date(), + backgroundColor: "#000000", + backgroundType: "color", + blurIntensity: 8, }; set({ activeProject: newProject }); @@ -234,4 +242,55 @@ export const useProjectStore = create((set, get) => ({ throw error; } }, + + updateProjectBackground: async (backgroundColor: string) => { + const { activeProject } = get(); + if (!activeProject) return; + + const updatedProject = { + ...activeProject, + backgroundColor, + updatedAt: new Date(), + }; + + try { + await storageService.saveProject(updatedProject); + set({ activeProject: updatedProject }); + await get().loadAllProjects(); // Refresh the list + } catch (error) { + console.error("Failed to update project background:", error); + toast.error("Failed to update background", { + description: "Please try again", + }); + } + }, + + updateBackgroundType: async ( + type: "color" | "blur", + options?: { backgroundColor?: string; blurIntensity?: number } + ) => { + const { activeProject } = get(); + if (!activeProject) return; + + const updatedProject = { + ...activeProject, + backgroundType: type, + ...(options?.backgroundColor && { + backgroundColor: options.backgroundColor, + }), + ...(options?.blurIntensity && { blurIntensity: options.blurIntensity }), + updatedAt: new Date(), + }; + + try { + await storageService.saveProject(updatedProject); + set({ activeProject: updatedProject }); + await get().loadAllProjects(); // Refresh the list + } catch (error) { + console.error("Failed to update background type:", error); + toast.error("Failed to update background", { + description: "Please try again", + }); + } + }, })); -- cgit v1.3.1