| import { useEffect, useRef } from 'react'; |
| import { useAppStore } from '@/store/app-store'; |
| import { useProjectSettings } from '@/hooks/queries'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function useProjectSettingsLoader() { |
| const currentProject = useAppStore((state) => state.currentProject); |
| const setBoardBackground = useAppStore((state) => state.setBoardBackground); |
| const setCardOpacity = useAppStore((state) => state.setCardOpacity); |
| const setColumnOpacity = useAppStore((state) => state.setColumnOpacity); |
| const setColumnBorderEnabled = useAppStore((state) => state.setColumnBorderEnabled); |
| const setCardGlassmorphism = useAppStore((state) => state.setCardGlassmorphism); |
| const setCardBorderEnabled = useAppStore((state) => state.setCardBorderEnabled); |
| const setCardBorderOpacity = useAppStore((state) => state.setCardBorderOpacity); |
| const setHideScrollbar = useAppStore((state) => state.setHideScrollbar); |
| const setWorktreePanelVisible = useAppStore((state) => state.setWorktreePanelVisible); |
| const setShowInitScriptIndicator = useAppStore((state) => state.setShowInitScriptIndicator); |
| const setDefaultDeleteBranch = useAppStore((state) => state.setDefaultDeleteBranch); |
| const setAutoDismissInitScriptIndicator = useAppStore( |
| (state) => state.setAutoDismissInitScriptIndicator |
| ); |
| const setWorktreeCopyFiles = useAppStore((state) => state.setWorktreeCopyFiles); |
| const setProjectUseWorktrees = useAppStore((state) => state.setProjectUseWorktrees); |
| const setPinnedWorktreesCount = useAppStore((state) => state.setPinnedWorktreesCount); |
| const setWorktreeDropdownThreshold = useAppStore((state) => state.setWorktreeDropdownThreshold); |
| const setAlwaysUseWorktreeDropdown = useAppStore((state) => state.setAlwaysUseWorktreeDropdown); |
|
|
| const appliedProjectRef = useRef<{ path: string; dataUpdatedAt: number } | null>(null); |
|
|
| |
| const { data: settings, dataUpdatedAt } = useProjectSettings(currentProject?.path); |
|
|
| |
| useEffect(() => { |
| if (!currentProject?.path || !settings) { |
| return; |
| } |
|
|
| |
| if ( |
| appliedProjectRef.current?.path === currentProject.path && |
| appliedProjectRef.current?.dataUpdatedAt === dataUpdatedAt |
| ) { |
| return; |
| } |
|
|
| appliedProjectRef.current = { path: currentProject.path, dataUpdatedAt }; |
| const projectPath = currentProject.path; |
|
|
| const bg = settings.boardBackground; |
|
|
| |
| if (bg?.imagePath) { |
| setBoardBackground(projectPath, bg.imagePath); |
| } |
|
|
| |
| const settingsMap = { |
| cardOpacity: setCardOpacity, |
| columnOpacity: setColumnOpacity, |
| columnBorderEnabled: setColumnBorderEnabled, |
| cardGlassmorphism: setCardGlassmorphism, |
| cardBorderEnabled: setCardBorderEnabled, |
| cardBorderOpacity: setCardBorderOpacity, |
| hideScrollbar: setHideScrollbar, |
| } as const; |
|
|
| |
| for (const [key, setter] of Object.entries(settingsMap)) { |
| const value = bg?.[key as keyof typeof bg]; |
| if (value !== undefined) { |
| (setter as (path: string, val: typeof value) => void)(projectPath, value); |
| } |
| } |
|
|
| |
| if (settings.worktreePanelVisible !== undefined) { |
| setWorktreePanelVisible(projectPath, settings.worktreePanelVisible); |
| } |
|
|
| |
| if (settings.showInitScriptIndicator !== undefined) { |
| setShowInitScriptIndicator(projectPath, settings.showInitScriptIndicator); |
| } |
|
|
| |
| if (settings.defaultDeleteBranchWithWorktree !== undefined) { |
| setDefaultDeleteBranch(projectPath, settings.defaultDeleteBranchWithWorktree); |
| } |
|
|
| |
| if (settings.autoDismissInitScriptIndicator !== undefined) { |
| setAutoDismissInitScriptIndicator(projectPath, settings.autoDismissInitScriptIndicator); |
| } |
|
|
| |
| if (settings.worktreeCopyFiles !== undefined) { |
| setWorktreeCopyFiles(projectPath, settings.worktreeCopyFiles); |
| } |
|
|
| |
| if (settings.useWorktrees !== undefined) { |
| setProjectUseWorktrees(projectPath, settings.useWorktrees); |
| } |
|
|
| |
| if (settings.pinnedWorktreesCount !== undefined) { |
| setPinnedWorktreesCount(projectPath, settings.pinnedWorktreesCount); |
| } |
|
|
| if (settings.worktreeDropdownThreshold !== undefined) { |
| setWorktreeDropdownThreshold(projectPath, settings.worktreeDropdownThreshold); |
| } |
|
|
| if (settings.alwaysUseWorktreeDropdown !== undefined) { |
| setAlwaysUseWorktreeDropdown(projectPath, settings.alwaysUseWorktreeDropdown); |
| } |
|
|
| |
| |
| |
| |
| const settingsWithExtras = settings as unknown as Record<string, unknown>; |
| const activeClaudeApiProfileId = settingsWithExtras.activeClaudeApiProfileId as |
| | string |
| | null |
| | undefined; |
| const phaseModelOverrides = settingsWithExtras.phaseModelOverrides as |
| | import('@automaker/types').PhaseModelConfig |
| | undefined; |
|
|
| |
| const storeState = useAppStore.getState(); |
| |
| |
| const snapshotProject = storeState.currentProject; |
| if (snapshotProject && snapshotProject.path === projectPath) { |
| const needsUpdate = |
| (activeClaudeApiProfileId !== undefined && |
| snapshotProject.activeClaudeApiProfileId !== activeClaudeApiProfileId) || |
| (phaseModelOverrides !== undefined && |
| JSON.stringify(snapshotProject.phaseModelOverrides) !== |
| JSON.stringify(phaseModelOverrides)); |
|
|
| if (needsUpdate) { |
| const updatedProjectData = { |
| ...snapshotProject, |
| ...(activeClaudeApiProfileId !== undefined && { activeClaudeApiProfileId }), |
| ...(phaseModelOverrides !== undefined && { phaseModelOverrides }), |
| }; |
|
|
| |
| |
| |
| const updatedProjects = storeState.projects.map((p) => |
| p.id === snapshotProject.id ? updatedProjectData : p |
| ); |
| |
| |
| |
| |
| |
| useAppStore.setState({ |
| currentProject: updatedProjectData, |
| projects: updatedProjects, |
| }); |
| } |
| } |
| }, [ |
| currentProject?.path, |
| settings, |
| dataUpdatedAt, |
| setBoardBackground, |
| setCardOpacity, |
| setColumnOpacity, |
| setColumnBorderEnabled, |
| setCardGlassmorphism, |
| setCardBorderEnabled, |
| setCardBorderOpacity, |
| setHideScrollbar, |
| setWorktreePanelVisible, |
| setShowInitScriptIndicator, |
| setDefaultDeleteBranch, |
| setAutoDismissInitScriptIndicator, |
| setWorktreeCopyFiles, |
| setProjectUseWorktrees, |
| setPinnedWorktreesCount, |
| setWorktreeDropdownThreshold, |
| setAlwaysUseWorktreeDropdown, |
| ]); |
| } |
|
|