diff --git a/src/Home.tsx b/src/Home.tsx index ab5e73f3..e45cb18f 100644 --- a/src/Home.tsx +++ b/src/Home.tsx @@ -8,8 +8,7 @@ import DBTree from '@/pages/sidebar'; import { activeSideAtom, ASide } from '@/pages/sidebar/aside'; import { Favorite, History, SqlCode } from '@/pages/sidebar/Favorite'; import { sizeAtom } from '@/stores/app'; -import { useAtomValue } from 'jotai'; -import { useAtom } from 'jotai/react'; +import { useAtom, useAtomValue } from 'jotai'; import { BellIcon } from 'lucide-react'; import { RefObject } from 'react'; diff --git a/src/components/custom/TreeView3.tsx b/src/components/custom/TreeView3.tsx index 9154ee18..1801bac3 100644 --- a/src/components/custom/TreeView3.tsx +++ b/src/components/custom/TreeView3.tsx @@ -272,14 +272,13 @@ export const TreeView3 = forwardRef( return; } - const dbId = data.dbId; + const { dbId, path } = data; - const nodes = tableMap.get(data.dbId)!; - const node = nodes.get(data.path as string); + const node = tableMap?.get(dbId)?.get(path as string); const nodeContext = { dbId, - tableId: data.path as string, + tableId: path as string, }; const noDataTypes = ['path', 'database', 'root']; diff --git a/src/pages/sidebar/SideToolbar.tsx b/src/pages/sidebar/SideToolbar.tsx index 544a57e0..b7cadbaa 100644 --- a/src/pages/sidebar/SideToolbar.tsx +++ b/src/pages/sidebar/SideToolbar.tsx @@ -14,9 +14,8 @@ import { ConfigDialog } from '@/pages/sidebar/dialog/ConfigDialog'; import { DatabaseDialog } from '@/pages/sidebar/dialog/DatabaseDialog'; import { DialectType, - dbMapAtom, selectedNodeAtom, - useDBListStore, + useDBListStore } from '@/stores/dbList'; import { ChevronsDownUpIcon, ChevronsUpDownIcon } from 'lucide-react'; @@ -27,8 +26,9 @@ export function SideToolbar({ onExpandAll: () => void; onCollapseAll: () => void; }) { - const [dbList, appendDB, updateDB, removeDB] = useDBListStore((s) => [ + const [dbList, dbMap, appendDB, updateDB, _removeDB] = useDBListStore((s) => [ s.dbList, + s.dbMap, s.append, s.update, s.remove, @@ -40,8 +40,7 @@ export function SideToolbar({ } const selectedNode = useAtomValue(selectedNodeAtom); - const dbMap = useAtomValue(dbMapAtom); - const db = selectedNode ? dbMap.get(selectedNode?.dbId) : undefined; + const db = selectedNode ? dbMap?.get(selectedNode?.dbId) : undefined; async function handleAppendFolder() { const res = await dialog.open({ diff --git a/src/pages/sidebar/index.tsx b/src/pages/sidebar/index.tsx index 07aa84b9..b4aa0caa 100644 --- a/src/pages/sidebar/index.tsx +++ b/src/pages/sidebar/index.tsx @@ -1,11 +1,10 @@ import { invoke } from '@tauri-apps/api/core'; -import { useAtomValue } from 'jotai'; import { nanoid } from 'nanoid'; import { useEffect, useRef, useState } from 'react'; import { getDB } from '@/api'; import { SideToolbar } from '@/pages/sidebar/SideToolbar'; -import { dbListAtom, useDBListStore } from '@/stores/dbList'; +import { useDBListStore } from '@/stores/dbList'; import { TableContextType, useTabsStore } from '@/stores/tabs'; import { SearchInput } from '@/components/custom/search'; @@ -42,7 +41,7 @@ function useInitOpenUrl() { } function DBTree() { - const dbList = useAtomValue(dbListAtom); + const dbList = useDBListStore((s) => s.dbList); useInitOpenUrl();