fix(webui): keep preference sync quiet
Keep routine layout, page, and appearance changes free of success notices. Surface persistence failures without interrupting normal adjustments.
This commit is contained in:
2 files changed
+19
-37
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||
import { actionErrorMessage, useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { defaultOverviewGrid, defaultOverviewMobile, migrateOverviewBlocks } from '@/lib/dashboard-layout';
|
||||
import type { UiLayout, UiLayoutItem, UiPages } from '@/types';
|
||||
@@ -105,7 +105,7 @@ const LayoutContext = createContext<LayoutContextValue | null>(null);
|
||||
|
||||
export function LayoutProvider({ children }: { children: ReactNode }) {
|
||||
const api = useApi();
|
||||
const { runAction } = useActionFeedback();
|
||||
const { startAction } = useActionFeedback();
|
||||
const [layout, setLayout] = useState<UiLayout>(DEFAULT_LAYOUT);
|
||||
const [pages, setPagesState] = useState<UiPages>(DEFAULT_PAGES);
|
||||
const [ready, setReady] = useState(false);
|
||||
@@ -143,8 +143,8 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
if (config.pages) setPagesState(config.pages);
|
||||
}
|
||||
} catch {
|
||||
/* keep defaults — layout/pages are non-critical */
|
||||
} catch (error) {
|
||||
console.error('initial UI preferences load failed', error);
|
||||
} finally {
|
||||
if (!cancelled) setReady(true);
|
||||
}
|
||||
@@ -176,19 +176,13 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
|
||||
if (saveTimer.current) clearTimeout(saveTimer.current);
|
||||
saveTimer.current = setTimeout(() => {
|
||||
saveTimer.current = null; // mark not-pending so the unmount flush can't double-fire
|
||||
void runAction(
|
||||
{
|
||||
title: '正在更新界面布局',
|
||||
detail: '正在同步仪表盘与导航布局',
|
||||
successTitle: '界面布局已更新',
|
||||
errorTitle: '界面布局更新失败',
|
||||
},
|
||||
() => api.ui.save({ layout: next }),
|
||||
).catch((error) => {
|
||||
void api.ui.save({ layout: next }).catch((error) => {
|
||||
console.error('persist layout failed', error);
|
||||
startAction({ title: '界面布局同步失败' })
|
||||
.fail(`当前修改未保存:${actionErrorMessage(error)}`);
|
||||
});
|
||||
}, 300);
|
||||
}, [api, runAction]);
|
||||
}, [api, startAction]);
|
||||
|
||||
const setOverviewBlocks = useCallback((items: UiLayoutItem[]) => {
|
||||
persist({ ...layoutRef.current, overviewBlocks: items });
|
||||
@@ -223,19 +217,13 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
|
||||
if (pagesTimer.current) clearTimeout(pagesTimer.current);
|
||||
pagesTimer.current = setTimeout(() => {
|
||||
pagesTimer.current = null;
|
||||
void runAction(
|
||||
{
|
||||
title: '正在更新页面设置',
|
||||
detail: '正在同步当前页面偏好',
|
||||
successTitle: '页面设置已更新',
|
||||
errorTitle: '页面设置更新失败',
|
||||
},
|
||||
() => api.ui.save({ pages: next }),
|
||||
).catch((error) => {
|
||||
void api.ui.save({ pages: next }).catch((error) => {
|
||||
console.error('persist page preferences failed', error);
|
||||
startAction({ title: '页面偏好同步失败' })
|
||||
.fail(`当前修改未保存:${actionErrorMessage(error)}`);
|
||||
});
|
||||
}, 300);
|
||||
}, [api, runAction]);
|
||||
}, [api, startAction]);
|
||||
|
||||
const value = useMemo<LayoutContextValue>(() => ({
|
||||
overviewBlocks: layout.overviewBlocks,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import { flushSync } from 'react-dom';
|
||||
import { MotionConfig } from 'motion/react';
|
||||
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||
import { actionErrorMessage, useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||
import type { Palette, ThemeMode, UiAppearance, UiBackground } from '@/types';
|
||||
|
||||
// Re-export the appearance value types so consumers (settings page etc.) can
|
||||
@@ -635,7 +635,7 @@ function getSystemTheme(): 'light' | 'dark' {
|
||||
}
|
||||
|
||||
export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||
const { runAction } = useActionFeedback();
|
||||
const { runAction, startAction } = useActionFeedback();
|
||||
const [appearance, setAppearanceState] = useState<UiAppearance>(readCache);
|
||||
const [systemTheme, setSystemTheme] = useState<'light' | 'dark'>(getSystemTheme);
|
||||
const [ready, setReady] = useState(false);
|
||||
@@ -719,20 +719,14 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||
writeCache(next);
|
||||
if (saveTimer.current) clearTimeout(saveTimer.current);
|
||||
saveTimer.current = setTimeout(() => {
|
||||
void runAction(
|
||||
{
|
||||
title: '正在更新外观',
|
||||
detail: '正在同步界面设置',
|
||||
successTitle: '外观已更新',
|
||||
successDetail: '界面设置已同步',
|
||||
errorTitle: '外观更新失败',
|
||||
},
|
||||
() => persistAppearance(next),
|
||||
).catch((error) => {
|
||||
saveTimer.current = null;
|
||||
void persistAppearance(next).catch((error) => {
|
||||
console.error('persist appearance failed', error);
|
||||
startAction({ title: '外观同步失败' })
|
||||
.fail(`当前修改未保存:${actionErrorMessage(error)}`);
|
||||
});
|
||||
}, 400);
|
||||
}, [runAction]);
|
||||
}, [startAction]);
|
||||
|
||||
const setAppearance = useCallback((patch: AppearancePatch) => {
|
||||
const prev = appearanceRef.current;
|
||||
|
||||
Reference in new issue
Block a user