Skip to content

Commit

Permalink
fix: initial null exception
Browse files Browse the repository at this point in the history
  • Loading branch information
l1xnan committed Jun 14, 2024
1 parent 226dcc7 commit cd1325c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 3 additions & 4 deletions src/components/custom/TreeView3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
9 changes: 4 additions & 5 deletions src/pages/sidebar/SideToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand All @@ -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({
Expand Down
5 changes: 2 additions & 3 deletions src/pages/sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,7 +41,7 @@ function useInitOpenUrl() {
}

function DBTree() {
const dbList = useAtomValue(dbListAtom);
const dbList = useDBListStore((s) => s.dbList);

useInitOpenUrl();

Expand Down

0 comments on commit cd1325c

Please # to comment.