mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-05 09:33:07 +00:00
fix background image part 2
This commit is contained in:
@@ -19,8 +19,11 @@ export function useProjectSettingsLoader() {
|
|||||||
const setHideScrollbar = useAppStore((state) => state.setHideScrollbar);
|
const setHideScrollbar = useAppStore((state) => state.setHideScrollbar);
|
||||||
|
|
||||||
const loadingRef = useRef<string | null>(null);
|
const loadingRef = useRef<string | null>(null);
|
||||||
|
const currentProjectRef = useRef<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
currentProjectRef.current = currentProject?.path ?? null;
|
||||||
|
|
||||||
if (!currentProject?.path) {
|
if (!currentProject?.path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -31,44 +34,43 @@ export function useProjectSettingsLoader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadingRef.current = currentProject.path;
|
loadingRef.current = currentProject.path;
|
||||||
|
const requestedProjectPath = currentProject.path;
|
||||||
|
|
||||||
const loadProjectSettings = async () => {
|
const loadProjectSettings = async () => {
|
||||||
try {
|
try {
|
||||||
const httpClient = getHttpApiClient();
|
const httpClient = getHttpApiClient();
|
||||||
const result = await httpClient.settings.getProject(currentProject.path);
|
const result = await httpClient.settings.getProject(requestedProjectPath);
|
||||||
|
|
||||||
if (result.success && result.settings?.boardBackground) {
|
// Race condition protection: ignore stale results if project changed
|
||||||
|
if (currentProjectRef.current !== requestedProjectPath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.success && result.settings) {
|
||||||
const bg = result.settings.boardBackground;
|
const bg = result.settings.boardBackground;
|
||||||
|
|
||||||
// Update store with loaded settings (without triggering server save)
|
// Apply boardBackground if present
|
||||||
setBoardBackground(currentProject.path, bg.imagePath);
|
if (bg?.imagePath) {
|
||||||
|
setBoardBackground(requestedProjectPath, bg.imagePath);
|
||||||
if (bg.cardOpacity !== undefined) {
|
|
||||||
setCardOpacity(currentProject.path, bg.cardOpacity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bg.columnOpacity !== undefined) {
|
// Settings map for cleaner iteration
|
||||||
setColumnOpacity(currentProject.path, bg.columnOpacity);
|
const settingsMap = {
|
||||||
}
|
cardOpacity: setCardOpacity,
|
||||||
|
columnOpacity: setColumnOpacity,
|
||||||
|
columnBorderEnabled: setColumnBorderEnabled,
|
||||||
|
cardGlassmorphism: setCardGlassmorphism,
|
||||||
|
cardBorderEnabled: setCardBorderEnabled,
|
||||||
|
cardBorderOpacity: setCardBorderOpacity,
|
||||||
|
hideScrollbar: setHideScrollbar,
|
||||||
|
} as const;
|
||||||
|
|
||||||
if (bg.columnBorderEnabled !== undefined) {
|
// Apply all settings that are defined
|
||||||
setColumnBorderEnabled(currentProject.path, bg.columnBorderEnabled);
|
for (const [key, setter] of Object.entries(settingsMap)) {
|
||||||
}
|
const value = bg?.[key as keyof typeof bg];
|
||||||
|
if (value !== undefined) {
|
||||||
if (bg.cardGlassmorphism !== undefined) {
|
(setter as (path: string, val: typeof value) => void)(requestedProjectPath, value);
|
||||||
setCardGlassmorphism(currentProject.path, bg.cardGlassmorphism);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (bg.cardBorderEnabled !== undefined) {
|
|
||||||
setCardBorderEnabled(currentProject.path, bg.cardBorderEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bg.cardBorderOpacity !== undefined) {
|
|
||||||
setCardBorderOpacity(currentProject.path, bg.cardBorderOpacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bg.hideScrollbar !== undefined) {
|
|
||||||
setHideScrollbar(currentProject.path, bg.hideScrollbar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -78,15 +80,5 @@ export function useProjectSettingsLoader() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
loadProjectSettings();
|
loadProjectSettings();
|
||||||
}, [
|
}, [currentProject?.path]);
|
||||||
currentProject?.path,
|
|
||||||
setBoardBackground,
|
|
||||||
setCardOpacity,
|
|
||||||
setColumnOpacity,
|
|
||||||
setColumnBorderEnabled,
|
|
||||||
setCardGlassmorphism,
|
|
||||||
setCardBorderEnabled,
|
|
||||||
setCardBorderOpacity,
|
|
||||||
setHideScrollbar,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user