From a082c7d33aed3fcc81fcacb6652b5fd7ddfe8ed7 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 18 Feb 2025 15:42:52 +0500 Subject: [PATCH] mobile: small ui improvements and perf fixes --- .../app/components/list-items/note/index.tsx | 2 +- apps/mobile/app/components/list/card.tsx | 7 +- apps/mobile/app/components/list/empty.tsx | 16 +-- apps/mobile/app/components/list/index.tsx | 109 ++++++++++-------- .../app/components/side-menu/menu-item.tsx | 29 ++--- .../side-menu/side-menu-notebooks.tsx | 61 ++++++---- .../components/side-menu/side-menu-tags.tsx | 2 +- apps/mobile/app/components/tip/index.tsx | 12 +- .../app/screens/settings/section-item.tsx | 13 ++- .../app/stores/create-notebook-tree-stores.ts | 83 ++++++++----- apps/mobile/app/stores/index.ts | 3 + apps/mobile/app/stores/use-monograph-store.ts | 30 +++++ apps/mobile/app/utils/size/index.js | 6 +- apps/mobile/native/globals.js | 2 +- 14 files changed, 224 insertions(+), 151 deletions(-) create mode 100644 apps/mobile/app/stores/use-monograph-store.ts diff --git a/apps/mobile/app/components/list-items/note/index.tsx b/apps/mobile/app/components/list-items/note/index.tsx index 9aeec050a..c85c8b1fe 100644 --- a/apps/mobile/app/components/list-items/note/index.tsx +++ b/apps/mobile/app/components/list-items/note/index.tsx @@ -105,7 +105,7 @@ const NoteItem = ({ {compactMode ? null : ( diff --git a/apps/mobile/app/components/list/card.tsx b/apps/mobile/app/components/list/card.tsx index c47422e0c..97f8015d6 100644 --- a/apps/mobile/app/components/list/card.tsx +++ b/apps/mobile/app/components/list/card.tsx @@ -99,15 +99,12 @@ export const Card = ({ flexWrap: "nowrap", flexShrink: 1 }} - size={AppFontSize.xs} + size={AppFontSize.sm} color={colors.primary.heading} > {messageBoardState.actionText} - + {messageBoardState.message} diff --git a/apps/mobile/app/components/list/empty.tsx b/apps/mobile/app/components/list/empty.tsx index 490f17112..62304c2cf 100644 --- a/apps/mobile/app/components/list/empty.tsx +++ b/apps/mobile/app/components/list/empty.tsx @@ -19,18 +19,17 @@ along with this program. If not, see . import { useThemeColors } from "@notesnook/theme"; import React from "react"; -import { ActivityIndicator, useWindowDimensions, View } from "react-native"; +import { ActivityIndicator, View } from "react-native"; import { notesnook } from "../../../e2e/test.ids"; -import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets"; import { TTip, useTip } from "../../services/tip-manager"; +import { RouteParams } from "../../stores/use-navigation-store"; import { useSettingStore } from "../../stores/use-setting-store"; -import { defaultBorderRadius, AppFontSize } from "../../utils/size"; +import { AppFontSize, defaultBorderRadius } from "../../utils/size"; import { Tip } from "../tip"; import { Button } from "../ui/button"; import Seperator from "../ui/seperator"; import Heading from "../ui/typography/heading"; import Paragraph from "../ui/typography/paragraph"; -import { RouteParams } from "../../stores/use-navigation-store"; export type PlaceholderData = { title: string; @@ -59,8 +58,6 @@ export const Empty = React.memo(function Empty({ screen }: EmptyListProps) { const { colors } = useThemeColors(); - const insets = useGlobalSafeAreaInsets(); - const { height } = useWindowDimensions(); const introCompleted = useSettingStore( (state) => state.settings.introCompleted ); @@ -75,7 +72,7 @@ export const Empty = React.memo(function Empty({ - { - fluidTabsRef.current?.unlock(); - }} - getItemType={(item: number, index: number) => { - return props.data?.type(index); - }} - estimatedItemSize={isCompactModeEnabled ? 60 : 120} - directionalLockEnabled={true} - keyboardShouldPersistTaps="always" - keyboardDismissMode="interactive" - refreshControl={ - props.isRenderedInActionSheet ? null : ( - - ) - } - ListEmptyComponent={ - props.placeholder ? ( - + {props.CustomLisHeader ? ( + props.CustomLisHeader + ) : !props.headerTitle ? null : ( +
- ) : null - } - ListHeaderComponent={ - <> - {props.CustomLisHeader ? ( - props.CustomLisHeader - ) : !props.headerTitle ? null : ( -
+ + ) : ( + { + fluidTabsRef.current?.unlock(); + }} + getItemType={(item: number, index: number) => { + return props.data?.type(index); + }} + estimatedItemSize={isCompactModeEnabled ? 60 : 120} + directionalLockEnabled={true} + keyboardShouldPersistTaps="always" + keyboardDismissMode="interactive" + refreshControl={ + props.isRenderedInActionSheet ? null : ( + - )} - - } - /> + ) + } + ListHeaderComponent={ + <> + {props.CustomLisHeader ? ( + props.CustomLisHeader + ) : !props.headerTitle ? null : ( +
+ )} + + } + /> + )} ); diff --git a/apps/mobile/app/components/side-menu/menu-item.tsx b/apps/mobile/app/components/side-menu/menu-item.tsx index edaee742d..2c379e81c 100644 --- a/apps/mobile/app/components/side-menu/menu-item.tsx +++ b/apps/mobile/app/components/side-menu/menu-item.tsx @@ -21,8 +21,8 @@ import { useThemeColors } from "@notesnook/theme"; import React, { useEffect, useRef, useState } from "react"; import { View } from "react-native"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; -import { db } from "../../common/database"; import { useTotalNotes } from "../../hooks/use-db-item"; + import Navigation from "../../services/navigation"; import { useFavoriteStore } from "../../stores/use-favorite-store"; import useNavigationStore, { @@ -35,6 +35,7 @@ import { defaultBorderRadius, AppFontSize } from "../../utils/size"; import { DefaultAppStyles } from "../../utils/styles"; import { Pressable } from "../ui/pressable"; import Paragraph from "../ui/typography/paragraph"; +import { useMonographStore } from "../../stores/use-monograph-store"; function _MenuItem({ item, @@ -93,10 +94,12 @@ function _MenuItem({ ); break; case "Monographs": - db.monographs.all.count().then((count) => { - setItemCount(count); + unsub = useMonographStore.subscribe((state) => { + setItemCount(state.items?.placeholders.length || 0); }); - // TODO make it reactive? + setItemCount( + useMonographStore.getState().items?.placeholders?.length || 0 + ); break; case "Trash": unsub = useTrashStore.subscribe((state) => { @@ -184,16 +187,14 @@ function _MenuItem({ - {menuItemCount > 0 ? ( - - {menuItemCount} - - ) : null} + + {menuItemCount} + ); } diff --git a/apps/mobile/app/components/side-menu/side-menu-notebooks.tsx b/apps/mobile/app/components/side-menu/side-menu-notebooks.tsx index 58e8639af..7d35cfe5f 100644 --- a/apps/mobile/app/components/side-menu/side-menu-notebooks.tsx +++ b/apps/mobile/app/components/side-menu/side-menu-notebooks.tsx @@ -202,7 +202,7 @@ const NotebookItem = ({ }} > { @@ -246,12 +246,14 @@ const NotebookItem = ({ onPress={() => { if (item.hasChildren) { onToggleExpanded?.(); + } else { + onPress?.(); } }} top={0} - left={20} + left={50} bottom={0} - right={20} + right={40} style={{ width: 32, height: 32, @@ -299,14 +301,12 @@ const NotebookItem = ({ ) : ( <> - {totalNotes(notebook?.id) ? ( - - {totalNotes?.(notebook?.id)} - - ) : null} + + {totalNotes?.(notebook?.id) || 0} + )} @@ -327,7 +327,10 @@ export const SideMenuNotebooks = () => { for (let i = 0; i < filteredNotebooks.placeholders.length; i++) { _notebooks[i] = (await filteredNotebooks?.item(i))?.item as Notebook; } - useSideMenuNotebookTreeStore.getState().addNotebooks("root", _notebooks, 0); + const items = await useSideMenuNotebookTreeStore + .getState() + .addNotebooks("root", _notebooks, 0); + useSideMenuNotebookTreeStore.getState().setTree(items); }, [filteredNotebooks]); const updateNotebooks = React.useCallback(() => { @@ -391,6 +394,8 @@ export const SideMenuNotebooks = () => { [] ); + console.log("RENDERING ROOT"); + return ( { bounces={false} bouncesZoom={false} overScrollMode="never" + keyExtractor={(item) => item.notebook.id} + windowSize={3} ListHeaderComponent={ state.expanded[item.notebook.id] ); + const selectionEnabled = useSideMenuNotebookSelectionStore( (state) => state.enabled ); @@ -467,18 +475,6 @@ const NotebookItemWrapper = React.memo( (state) => state.focusedRouteId === item.notebook.id ); - useEffect(() => { - if (expanded) { - useSideMenuNotebookTreeStore - .getState() - .fetchAndAdd(item.notebook.id, item.depth + 1); - } else { - useSideMenuNotebookTreeStore - .getState() - .removeChildren(item.notebook.id); - } - }, [expanded, item.depth, item.notebook]); - const onItemUpdate = React.useCallback(async () => { const notebook = await db.notebooks.notebook(item.notebook.id); if (notebook) { @@ -490,6 +486,8 @@ const NotebookItemWrapper = React.memo( } }, [item.notebook.id]); + console.log("RENDERING", item?.notebook?.title, item.parentId); + return ( { + onToggleExpanded={async () => { useSideMenuNotebookExpandedStore .getState() .setExpanded(item.notebook.id); + if (!expanded) { + useSideMenuNotebookTreeStore + .getState() + .setTree( + await useSideMenuNotebookTreeStore + .getState() + .fetchAndAdd(item.notebook.id, item.depth + 1) + ); + } else { + useSideMenuNotebookTreeStore + .getState() + .removeChildren(item.notebook.id); + } }} selected={selected} selectionEnabled={selectionEnabled} diff --git a/apps/mobile/app/components/side-menu/side-menu-tags.tsx b/apps/mobile/app/components/side-menu/side-menu-tags.tsx index 8160c0a08..14e840bf6 100644 --- a/apps/mobile/app/components/side-menu/side-menu-tags.tsx +++ b/apps/mobile/app/components/side-menu/side-menu-tags.tsx @@ -66,7 +66,7 @@ const TagItem = (props: { {item ? ( diff --git a/apps/mobile/app/components/tip/index.tsx b/apps/mobile/app/components/tip/index.tsx index 2a6d77861..523ac4c12 100644 --- a/apps/mobile/app/components/tip/index.tsx +++ b/apps/mobile/app/components/tip/index.tsx @@ -70,7 +70,7 @@ export const Tip = ({