From 2bc41bebf8afec5e86a6d9c7ef6c773b9fadf58b Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 13 Mar 2025 09:39:21 +0800 Subject: [PATCH 1/2] Fix state persistence handling problem - Removed `getInitialState` helper function. - Set default theme to 'system'. - Changed default language to 'en'. --- lightrag_webui/src/stores/settings.ts | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/lightrag_webui/src/stores/settings.ts b/lightrag_webui/src/stores/settings.ts index ba1b34ac..100b665e 100644 --- a/lightrag_webui/src/stores/settings.ts +++ b/lightrag_webui/src/stores/settings.ts @@ -59,27 +59,11 @@ interface SettingsState { setCurrentTab: (tab: Tab) => void } -// Helper to get initial state from localStorage -const getInitialState = () => { - try { - const stored = localStorage.getItem('settings-storage') - if (stored) { - const { state } = JSON.parse(stored) - return { - theme: state?.theme || 'system', - language: state?.language || 'zh' - } - } - } catch (e) { - console.error('Failed to parse settings from localStorage:', e) - } - return { theme: 'system', language: 'zh' } -} - const useSettingsStoreBase = create()( persist( (set) => ({ - ...getInitialState(), + theme: 'system', + language: 'en', refreshLayout: () => { const graphState = useGraphStore.getState(); const currentGraph = graphState.sigmaGraph; @@ -211,10 +195,8 @@ const useSettingsStoreBase = create()( state.graphLayoutMaxIterations = 15 } if (version < 8) { - state.enableNodeDrag = true - state.enableHideUnselectedEdges = true - state.enableEdgeEvents = false state.graphMinDegree = 0 + state.language = 'en' } return state } From 642d17b7740c8ea270c126e4b5986ccde6ae4f40 Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 13 Mar 2025 09:44:51 +0800 Subject: [PATCH 2/2] Moved refreshLayout from settings to graph store. --- lightrag_webui/src/components/graph/Settings.tsx | 3 ++- lightrag_webui/src/stores/graph.ts | 14 +++++++++++++- lightrag_webui/src/stores/settings.ts | 12 ------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lightrag_webui/src/components/graph/Settings.tsx b/lightrag_webui/src/components/graph/Settings.tsx index 8d764a9c..a24c86e9 100644 --- a/lightrag_webui/src/components/graph/Settings.tsx +++ b/lightrag_webui/src/components/graph/Settings.tsx @@ -8,6 +8,7 @@ import Input from '@/components/ui/Input' import { controlButtonVariant } from '@/lib/constants' import { useSettingsStore } from '@/stores/settings' import { useBackendState } from '@/stores/state' +import { useGraphStore } from '@/stores/graph' import { SettingsIcon, RefreshCwIcon } from 'lucide-react' import { useTranslation } from 'react-i18next'; @@ -114,7 +115,7 @@ const LabeledNumberInput = ({ export default function Settings() { const [opened, setOpened] = useState(false) const [tempApiKey, setTempApiKey] = useState('') - const refreshLayout = useSettingsStore.use.refreshLayout() + const refreshLayout = useGraphStore.use.refreshLayout() const showPropertyPanel = useSettingsStore.use.showPropertyPanel() const showNodeSearchBar = useSettingsStore.use.showNodeSearchBar() diff --git a/lightrag_webui/src/stores/graph.ts b/lightrag_webui/src/stores/graph.ts index 3c4fe37e..b27a7f09 100644 --- a/lightrag_webui/src/stores/graph.ts +++ b/lightrag_webui/src/stores/graph.ts @@ -72,6 +72,7 @@ interface GraphState { moveToSelectedNode: boolean isFetching: boolean + refreshLayout: () => void setSelectedNode: (nodeId: string | null, moveToSelectedNode?: boolean) => void setFocusedNode: (nodeId: string | null) => void setSelectedEdge: (edgeId: string | null) => void @@ -89,7 +90,7 @@ interface GraphState { setIsFetching: (isFetching: boolean) => void } -const useGraphStoreBase = create()((set) => ({ +const useGraphStoreBase = create()((set, get) => ({ selectedNode: null, focusedNode: null, selectedEdge: null, @@ -103,6 +104,17 @@ const useGraphStoreBase = create()((set) => ({ graphLabels: ['*'], allDatabaseLabels: ['*'], + refreshLayout: () => { + const currentGraph = get().sigmaGraph; + if (currentGraph) { + get().clearSelection(); + get().setSigmaGraph(null); + setTimeout(() => { + get().setSigmaGraph(currentGraph); + }, 10); + } + }, + setIsFetching: (isFetching: boolean) => set({ isFetching }), setSelectedNode: (nodeId: string | null, moveToSelectedNode?: boolean) => set({ selectedNode: nodeId, moveToSelectedNode }), diff --git a/lightrag_webui/src/stores/settings.ts b/lightrag_webui/src/stores/settings.ts index 100b665e..72df7351 100644 --- a/lightrag_webui/src/stores/settings.ts +++ b/lightrag_webui/src/stores/settings.ts @@ -3,7 +3,6 @@ import { persist, createJSONStorage } from 'zustand/middleware' import { createSelectors } from '@/lib/utils' import { defaultQueryLabel } from '@/lib/constants' import { Message, QueryRequest } from '@/api/lightrag' -import { useGraphStore } from '@/stores/graph' type Theme = 'dark' | 'light' | 'system' type Language = 'en' | 'zh' @@ -11,7 +10,6 @@ type Tab = 'documents' | 'knowledge-graph' | 'retrieval' | 'api' interface SettingsState { // Graph viewer settings - refreshLayout: () => void showPropertyPanel: boolean showNodeSearchBar: boolean @@ -64,16 +62,6 @@ const useSettingsStoreBase = create()( (set) => ({ theme: 'system', language: 'en', - refreshLayout: () => { - const graphState = useGraphStore.getState(); - const currentGraph = graphState.sigmaGraph; - graphState.clearSelection(); - graphState.setSigmaGraph(null); - setTimeout(() => { - graphState.setSigmaGraph(currentGraph); - }, 10); - }, - showPropertyPanel: true, showNodeSearchBar: true,