Skip to content

Commit 6ac6ab8

Browse files
committed
rendering optimization around useTabs
1 parent 045722d commit 6ac6ab8

File tree

16 files changed

+235
-156
lines changed

16 files changed

+235
-156
lines changed

apps/desktop/src/components/chat/message/tool/search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function RenderContent({ part }: { part: Part }) {
9292

9393
function RenderSession({ sessionId }: { sessionId: string }) {
9494
const session = main.UI.useRow("sessions", sessionId, main.STORE_ID);
95-
const { openNew } = useTabs();
95+
const openNew = useTabs((state) => state.openNew);
9696

9797
const handleClick = useCallback(() => {
9898
openNew({ type: "sessions", id: sessionId });

apps/desktop/src/components/main/body/calendars/day-events.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useTabs } from "../../../../store/zustand/tabs";
1111
export function TabContentCalendarDayEvents({ eventId }: { eventId: string }) {
1212
const event = main.UI.useRow("events", eventId, main.STORE_ID);
1313
const [open, setOpen] = useState(false);
14-
const { openNew } = useTabs();
14+
const openNew = useTabs((state) => state.openNew);
1515

1616
const title = event?.title || "Untitled Event";
1717

apps/desktop/src/components/main/body/calendars/day-sessions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTabs } from "../../../../store/zustand/tabs";
77

88
export function TabContentCalendarDaySessions({ sessionId }: { sessionId: string }) {
99
const session = main.UI.useRow("sessions", sessionId, main.STORE_ID);
10-
const { openNew } = useTabs();
10+
const openNew = useTabs((state) => state.openNew);
1111

1212
const eventId = session?.event_id ?? "";
1313
const event = main.UI.useRow("events", eventId, main.STORE_ID);

apps/desktop/src/components/main/body/calendars/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function TabContentCalendar({ tab }: { tab: Tab }) {
5656
function TabContentCalendarInner({ tab }: { tab: Extract<Tab, { type: "calendars" }> }) {
5757
const [sidebarOpen, setSidebarOpen] = useState(false);
5858

59-
const { openCurrent } = useTabs();
59+
const openCurrent = useTabs((state) => state.openCurrent);
6060

6161
const calendarIds = main.UI.useRowIds("calendars", main.STORE_ID);
6262

apps/desktop/src/components/main/body/contacts/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@hypr/ui/c
22

33
import { Contact2Icon } from "lucide-react";
44
import { useCallback, useEffect } from "react";
5+
import { useShallow } from "zustand/shallow";
56

67
import * as main from "../../../../store/tinybase/main";
78
import { type Tab, useTabs } from "../../../../store/zustand/tabs";
@@ -46,7 +47,12 @@ export function TabContentContact({ tab }: { tab: Extract<Tab, { type: "contacts
4647

4748
function ContactView({ tab }: { tab: Extract<Tab, { type: "contacts" }> }) {
4849
const updateContactsTabState = useTabs((state) => state.updateContactsTabState);
49-
const { openCurrent, invalidateResource } = useTabs();
50+
const { openCurrent, invalidateResource } = useTabs(
51+
useShallow((state) => ({
52+
openCurrent: state.openCurrent,
53+
invalidateResource: state.invalidateResource,
54+
})),
55+
);
5056

5157
const { selectedOrganization, selectedPerson } = tab.state;
5258

apps/desktop/src/components/main/body/empty/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function TabContentEmpty({ tab: _tab }: { tab: Extract<Tab, { type: "empt
4040

4141
function EmptyView() {
4242
const newNote = useNewNote({ behavior: "current" });
43-
const { openCurrent } = useTabs();
43+
const openCurrent = useTabs((state) => state.openCurrent);
4444
const openCalendar = useCallback(() => openCurrent({ type: "calendars", month: new Date() }), [openCurrent]);
4545
const openContacts = useCallback(() => openCurrent({ type: "contacts" }), [openCurrent]);
4646

apps/desktop/src/components/main/body/folders/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function TabContentFolderTopLevel() {
112112

113113
function FolderCard({ folderId }: { folderId: string }) {
114114
const folder = main.UI.useRow("folders", folderId, main.STORE_ID);
115-
const { openCurrent } = useTabs();
115+
const openCurrent = useTabs((state) => state.openCurrent);
116116

117117
const childFolderIds = main.UI.useSliceRowIds(
118118
main.INDEXES.foldersByParent,
@@ -200,7 +200,7 @@ function TabContentFolderSpecific({ folderId }: { folderId: string }) {
200200
}
201201

202202
function TabContentFolderBreadcrumb({ folderId }: { folderId: string }) {
203-
const { openCurrent } = useTabs();
203+
const openCurrent = useTabs((state) => state.openCurrent);
204204

205205
return (
206206
<FolderBreadcrumb
@@ -227,7 +227,7 @@ function TabContentFolderBreadcrumb({ folderId }: { folderId: string }) {
227227

228228
function FolderSessionItem({ sessionId }: { sessionId: string }) {
229229
const session = main.UI.useRow("sessions", sessionId, main.STORE_ID);
230-
const { openCurrent } = useTabs();
230+
const openCurrent = useTabs((state) => state.openCurrent);
231231

232232
return (
233233
<div

apps/desktop/src/components/main/body/index.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ArrowLeftIcon, ArrowRightIcon, PanelLeftOpenIcon, PlusIcon } from "luci
33
import { Reorder } from "motion/react";
44
import { useCallback, useEffect, useRef } from "react";
55
import { useHotkeys } from "react-hotkeys-hook";
6+
import { useShallow } from "zustand/shallow";
67

78
import { Button } from "@hypr/ui/components/ui/button";
89
import { cn } from "@hypr/utils";
@@ -20,7 +21,12 @@ import { Search } from "./search";
2021
import { TabContentNote, TabItemNote } from "./sessions";
2122

2223
export function Body() {
23-
const { tabs, currentTab } = useTabs();
24+
const { tabs, currentTab } = useTabs(
25+
useShallow((state) => ({
26+
tabs: state.tabs,
27+
currentTab: state.currentTab,
28+
})),
29+
);
2430

2531
if (!currentTab) {
2632
return null;
@@ -41,7 +47,19 @@ export function Body() {
4147

4248
function Header({ tabs }: { tabs: Tab[] }) {
4349
const { leftsidebar } = useShell();
44-
const { select, close, reorder, goBack, goNext, canGoBack, canGoNext, closeOthers, closeAll } = useTabs();
50+
const { select, close, reorder, goBack, goNext, canGoBack, canGoNext, closeOthers, closeAll } = useTabs(
51+
useShallow((state) => ({
52+
select: state.select,
53+
close: state.close,
54+
reorder: state.reorder,
55+
goBack: state.goBack,
56+
goNext: state.goNext,
57+
canGoBack: state.canGoBack,
58+
canGoNext: state.canGoNext,
59+
closeOthers: state.closeOthers,
60+
closeAll: state.closeAll,
61+
})),
62+
);
4563
const tabsScrollContainerRef = useRef<HTMLDivElement>(null);
4664
const handleNewEmptyTab = useNewEmptyTab();
4765

@@ -341,7 +359,14 @@ function useScrollActiveTabIntoView(tabs: Tab[]) {
341359
}
342360

343361
function useTabsShortcuts() {
344-
const { tabs, currentTab, close, select } = useTabs();
362+
const { tabs, currentTab, close, select } = useTabs(
363+
useShallow((state) => ({
364+
tabs: state.tabs,
365+
currentTab: state.currentTab,
366+
close: state.close,
367+
select: state.select,
368+
})),
369+
);
345370
const newNote = useNewNote({ behavior: "new" });
346371
const newEmptyTab = useNewEmptyTab();
347372

@@ -396,7 +421,7 @@ function useTabsShortcuts() {
396421
}
397422

398423
function useNewEmptyTab() {
399-
const { openNew } = useTabs();
424+
const openNew = useTabs((state) => state.openNew);
400425

401426
const handler = useCallback(() => {
402427
openNew({ type: "empty" });

apps/desktop/src/components/main/body/sessions/note-input/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Transcript } from "./transcript";
1515

1616
export function NoteInput({ tab }: { tab: Extract<Tab, { type: "sessions" }> }) {
1717
const editorTabs = useEditorTabs({ sessionId: tab.id });
18-
const { updateSessionTabState } = useTabs();
18+
const updateSessionTabState = useTabs((state) => state.updateSessionTabState);
1919
const editorRef = useRef<{ editor: TiptapEditor | null }>(null);
2020
const inactive = useListener((state) => state.live.status === "inactive");
2121
const [isEditing, setIsEditing] = useState(false);

apps/desktop/src/components/main/body/sessions/outer-header/folder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function RenderIfRootExist(
5050
handleChangeTitle: (title: string) => void;
5151
},
5252
) {
53-
const { openNew } = useTabs();
53+
const openNew = useTabs((state) => state.openNew);
5454

5555
return (
5656
<>

0 commit comments

Comments
 (0)