From 330f608fa986e3a8aa2d5e1667dd1201e4d26022 Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 12 Mar 2025 18:55:15 +0800 Subject: [PATCH] Fix linting --- lightrag/api/lightrag_server.py | 10 ++++++---- lightrag_webui/src/components/AppSettings.tsx | 4 ++-- lightrag_webui/src/components/ThemeProvider.tsx | 4 ++-- lightrag_webui/src/components/graph/GraphLabels.tsx | 4 ++-- lightrag_webui/src/components/ui/Tooltip.tsx | 2 +- lightrag_webui/src/hooks/useLightragGraph.tsx | 10 +++++----- lightrag_webui/src/stores/graph.ts | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index 9b43d98f..4c75430f 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -427,10 +427,12 @@ def create_app(args): class NoCacheStaticFiles(StaticFiles): async def get_response(self, path: str, scope): response = await super().get_response(path, scope) - if path.endswith('.html'): - response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate' - response.headers['Pragma'] = 'no-cache' - response.headers['Expires'] = '0' + if path.endswith(".html"): + response.headers["Cache-Control"] = ( + "no-cache, no-store, must-revalidate" + ) + response.headers["Pragma"] = "no-cache" + response.headers["Expires"] = "0" return response # Webui mount webui/index.html diff --git a/lightrag_webui/src/components/AppSettings.tsx b/lightrag_webui/src/components/AppSettings.tsx index bc2161d6..284ad67f 100644 --- a/lightrag_webui/src/components/AppSettings.tsx +++ b/lightrag_webui/src/components/AppSettings.tsx @@ -9,10 +9,10 @@ import { useTranslation } from 'react-i18next' export default function AppSettings() { const [opened, setOpened] = useState(false) const { t } = useTranslation() - + const language = useSettingsStore.use.language() const setLanguage = useSettingsStore.use.setLanguage() - + const theme = useSettingsStore.use.theme() const setTheme = useSettingsStore.use.setTheme() diff --git a/lightrag_webui/src/components/ThemeProvider.tsx b/lightrag_webui/src/components/ThemeProvider.tsx index dfccb795..df5816c6 100644 --- a/lightrag_webui/src/components/ThemeProvider.tsx +++ b/lightrag_webui/src/components/ThemeProvider.tsx @@ -34,10 +34,10 @@ export default function ThemeProvider({ children, ...props }: ThemeProviderProps root.classList.remove('light', 'dark') root.classList.add(e.matches ? 'dark' : 'light') } - + root.classList.add(mediaQuery.matches ? 'dark' : 'light') mediaQuery.addEventListener('change', handleChange) - + return () => mediaQuery.removeEventListener('change', handleChange) } else { root.classList.add(theme) diff --git a/lightrag_webui/src/components/graph/GraphLabels.tsx b/lightrag_webui/src/components/graph/GraphLabels.tsx index 58d470b6..74749a06 100644 --- a/lightrag_webui/src/components/graph/GraphLabels.tsx +++ b/lightrag_webui/src/components/graph/GraphLabels.tsx @@ -54,9 +54,9 @@ const GraphLabels = () => { const setQueryLabel = useCallback((newLabel: string) => { if (newLabel.startsWith('And ') && newLabel.endsWith(' others')) return - + const currentLabel = useSettingsStore.getState().queryLabel - + if (newLabel === '*' && currentLabel === '*') { // When reselecting '*', just set it again to trigger a new fetch useSettingsStore.getState().setQueryLabel('*') diff --git a/lightrag_webui/src/components/ui/Tooltip.tsx b/lightrag_webui/src/components/ui/Tooltip.tsx index cdec63a9..e52a82aa 100644 --- a/lightrag_webui/src/components/ui/Tooltip.tsx +++ b/lightrag_webui/src/components/ui/Tooltip.tsx @@ -25,7 +25,7 @@ const TooltipContent = React.forwardRef< } >(({ className, side = 'left', align = 'start', children, ...props }, ref) => { const contentRef = React.useRef(null); - + React.useEffect(() => { if (contentRef.current) { contentRef.current.scrollTop = 0; diff --git a/lightrag_webui/src/hooks/useLightragGraph.tsx b/lightrag_webui/src/hooks/useLightragGraph.tsx index b6230a50..c85d5cfc 100644 --- a/lightrag_webui/src/hooks/useLightragGraph.tsx +++ b/lightrag_webui/src/hooks/useLightragGraph.tsx @@ -178,8 +178,8 @@ const useLightrangeGraph = () => { // Reset fetch status only when parameters actually change useEffect(() => { const prevParams = prevParamsRef.current; - if (prevParams.queryLabel !== queryLabel || - prevParams.maxQueryDepth !== maxQueryDepth || + if (prevParams.queryLabel !== queryLabel || + prevParams.maxQueryDepth !== maxQueryDepth || prevParams.minDegree !== minDegree) { useGraphStore.getState().setIsFetching(false); // Reset fetch status for new parameters @@ -206,7 +206,7 @@ const useLightrangeGraph = () => { useEffect(() => { if (queryLabel) { const fetchKey = `${queryLabel}-${maxQueryDepth}-${minDegree}`; - + // Only fetch if we haven't fetched this combination in the current component lifecycle if (!isFetching && !fetchStatusRef.current[fetchKey]) { useGraphStore.getState().setIsFetching(true); @@ -215,13 +215,13 @@ const useLightrangeGraph = () => { const state = useGraphStore.getState() const newSigmaGraph = createSigmaGraph(data) data?.buildDynamicMap() - + // Update all graph data at once to minimize UI flicker state.clearSelection() state.setMoveToSelectedNode(false) state.setSigmaGraph(newSigmaGraph) state.setRawGraph(data) - + // Extract labels from graph data if (data) { const labelSet = new Set(); diff --git a/lightrag_webui/src/stores/graph.ts b/lightrag_webui/src/stores/graph.ts index 5e7c6ccd..b47d6445 100644 --- a/lightrag_webui/src/stores/graph.ts +++ b/lightrag_webui/src/stores/graph.ts @@ -129,7 +129,7 @@ const useGraphStoreBase = create()((set) => ({ }), setSigmaGraph: (sigmaGraph: DirectedGraph | null) => set({ sigmaGraph }), - + setGraphLabels: (labels: string[]) => set({ graphLabels: labels }), setMoveToSelectedNode: (moveToSelectedNode?: boolean) => set({ moveToSelectedNode })