From 36150fb55b103b83c41d0ea4fbc558ce2c498af6 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 22 Dec 2023 08:21:46 +0500 Subject: [PATCH] web: more fixes --- apps/web/src/common/multi-select.ts | 2 +- .../src/components/cached-router/index.tsx | 6 ++- apps/web/src/components/properties/index.tsx | 8 ++-- .../web/src/components/session-item/index.tsx | 6 ++- apps/web/src/dialogs/add-tags-dialog.tsx | 2 +- apps/web/src/dialogs/attachments-dialog.tsx | 47 ++++++++++++------- .../settings/backup-export-settings.ts | 2 +- apps/web/src/hooks/use-hash-routes.tsx | 4 +- apps/web/src/hooks/use-routes.ts | 4 +- apps/web/src/navigation/routes.tsx | 13 +---- apps/web/src/navigation/types.ts | 34 ++++++++++++-- apps/web/src/stores/attachment-store.ts | 4 +- apps/web/src/utils/importer.ts | 28 +++++------ packages/core/src/collections/notebooks.ts | 4 ++ .../core/src/utils/virtualized-grouping.ts | 13 +---- 15 files changed, 96 insertions(+), 81 deletions(-) diff --git a/apps/web/src/common/multi-select.ts b/apps/web/src/common/multi-select.ts index d2538f98e..f853c0409 100644 --- a/apps/web/src/common/multi-select.ts +++ b/apps/web/src/common/multi-select.ts @@ -87,7 +87,7 @@ async function deleteAttachments(ids: string[]) { action: async (report) => { for (let i = 0; i < ids.length; ++i) { const id = ids[i]; - const attachment = await attachmentStore.get().attachments?.item(id); + const attachment = await db.attachments.attachment(id); if (!attachment) continue; report({ diff --git a/apps/web/src/components/cached-router/index.tsx b/apps/web/src/components/cached-router/index.tsx index 542eb5f11..7bb769a77 100644 --- a/apps/web/src/components/cached-router/index.tsx +++ b/apps/web/src/components/cached-router/index.tsx @@ -24,6 +24,7 @@ import useRoutes from "../../hooks/use-routes"; import RouteContainer from "../route-container"; import routes from "../../navigation/routes"; import { Flex } from "@theme-ui/components"; +import { isRouteResult } from "../../navigation/types"; function CachedRouter() { const [RouteResult, location] = useRoutes(routes, { @@ -39,9 +40,10 @@ function CachedRouter() { NavigationEvents.publish("onNavigate", RouteResult, location); }, [RouteResult, location]); - if (!RouteResult) return null; + if (!RouteResult || !isRouteResult(RouteResult)) return null; if (RouteResult.key === "general" || !cachedRoutes.current[RouteResult.key]) - cachedRoutes.current[RouteResult.key] = RouteResult.component; + cachedRoutes.current[RouteResult.key] = + RouteResult.component as React.FunctionComponent; return ( result.value.key(index)} items={result.value.ids} - renderItem={({ item: index }) => ( + renderItem={({ index }) => ( {({ item, data }) => ( @@ -302,7 +302,7 @@ function Reminders({ noteId }: { noteId: string }) { estimatedSize={54} getItemKey={(index) => result.value.key(index)} items={result.value.ids} - renderItem={({ item: index }) => ( + renderItem={({ index }) => ( {({ item, data }) => ( @@ -329,7 +329,7 @@ function Attachments({ noteId }: { noteId: string }) { getItemKey={(index) => result.value.key(index)} items={result.value.ids} header={<>} - renderRow={({ item: index }) => ( + renderRow={({ index }) => ( {({ item }) => } @@ -367,7 +367,7 @@ function SessionHistory({ estimatedSize={28} getItemKey={(index) => result.value.key(index)} items={result.value.ids} - renderItem={({ item: index }) => ( + renderItem={({ index }) => ( {({ item }) => ( { const content = await db.noteHistory.content(session.id); if (!content) return; - // toggleProperties(false); if (session.locked) { await Vault.askPassword(async (password) => { try { @@ -85,7 +84,10 @@ export function SessionItem(props: SessionItemProps) { }); } else { onOpenPreviewSession({ - content, + content: { + data: content.data as string, + type: content.type + }, dateCreated: session.dateCreated, dateEdited: session.dateModified }); diff --git a/apps/web/src/dialogs/add-tags-dialog.tsx b/apps/web/src/dialogs/add-tags-dialog.tsx index e49eb3bf1..f708bcfe8 100644 --- a/apps/web/src/dialogs/add-tags-dialog.tsx +++ b/apps/web/src/dialogs/add-tags-dialog.tsx @@ -126,7 +126,7 @@ function AddTagsDialog(props: AddTagsDialogProps) { const { selected, setSelected } = useSelectionStore.getState(); setSelected([...selected, { id: tagId, new: true, op: "add" }]); }} - renderItem={({ item: index }) => { + renderItem={({ index }) => { return ( {({ item }) => } diff --git a/apps/web/src/dialogs/attachments-dialog.tsx b/apps/web/src/dialogs/attachments-dialog.tsx index ec9374b35..b2ec74eaa 100644 --- a/apps/web/src/dialogs/attachments-dialog.tsx +++ b/apps/web/src/dialogs/attachments-dialog.tsx @@ -160,7 +160,14 @@ function AttachmentsDialog({ onClose }: AttachmentsDialogProps) { }} > download(allAttachments?.ungrouped || [])} + onDownloadAll={async () => + download( + await db.attachments.all.ids({ + sortBy: "dateCreated", + sortDirection: "desc" + }) + ) + } filter={async (query) => { setAttachments(await db.lookup.attachments(query).sorted()); }} @@ -248,10 +255,12 @@ function AttachmentsDialog({ onClose }: AttachmentsDialogProps) {