From c644f606f3a2d0bbde001a017a7bcdfcce375ec9 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 24 Jul 2023 10:12:17 +0500 Subject: [PATCH] web: add support for endless scrolling in themes --- .../settings/components/themes-selector.tsx | 115 ++++++++++-------- 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/apps/web/src/dialogs/settings/components/themes-selector.tsx b/apps/web/src/dialogs/settings/components/themes-selector.tsx index dfc82f379..8a9a2c5fd 100644 --- a/apps/web/src/dialogs/settings/components/themes-selector.tsx +++ b/apps/web/src/dialogs/settings/components/themes-selector.tsx @@ -33,6 +33,7 @@ import { import { ThemeMetadata } from "@notesnook/themes-server"; import { showThemeDetails } from "../../../common/dialog-controller"; import { ThemePreview } from "../../../components/theme-preview"; +import { VirtuosoGrid } from "react-virtuoso"; const ThemesClient = ThemesTRPC.createClient({ links: [ @@ -131,61 +132,73 @@ function ThemesList() { ))} - - {themes.data?.pages - .flatMap((a) => a.themes) - .map((theme) => ( - a.themes) || []} + endReached={() => (themes.hasNextPage ? themes.fetchNextPage() : null)} + components={{ + List: (props) => ( + { - if (await showThemeDetails(theme)) { - await setTheme(theme); - } + display: "grid", + gridTemplateColumns: "1fr 1fr", + gap: 4, + mt: 2 }} + {...props} + /> + ) + }} + itemContent={(_index, theme) => ( + { + if (await showThemeDetails(theme)) { + await setTheme(theme); + } + }} + > + + + {theme.name} + + {theme.authors[0].name} + - - - {theme.name} - - {theme.authors[0].name} - - {theme.totalInstalls} installs - {isThemeCurrentlyApplied(theme.id) ? ( - - ) : ( - - )} - + {theme.totalInstalls} installs + {isThemeCurrentlyApplied(theme.id) ? ( + + ) : ( + + )} - ))} - + + )} + > ); }