From 7873251d0530d55230da4ecdc518ceb987ed2a6c Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Wed, 14 Feb 2024 17:54:45 +0500 Subject: [PATCH] mobile: fix sidemenu shortcuts --- .../components/dialogs/color-picker/index.tsx | 1 + .../components/side-menu/pinned-section.tsx | 3 +- apps/mobile/app/stores/use-menu-store.ts | 15 ++++++---- packages/core/src/collections/shortcuts.ts | 28 +++++++++++++++---- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/apps/mobile/app/components/dialogs/color-picker/index.tsx b/apps/mobile/app/components/dialogs/color-picker/index.tsx index 14e1c8af7..ef63cb1e2 100644 --- a/apps/mobile/app/components/dialogs/color-picker/index.tsx +++ b/apps/mobile/app/components/dialogs/color-picker/index.tsx @@ -56,6 +56,7 @@ const ColorPicker = ({ { + title.current = undefined; setVisible(false); useSettingStore.getState().setSheetKeyboardHandler(true); }} diff --git a/apps/mobile/app/components/side-menu/pinned-section.tsx b/apps/mobile/app/components/side-menu/pinned-section.tsx index 9132f6d22..a839357c1 100644 --- a/apps/mobile/app/components/side-menu/pinned-section.tsx +++ b/apps/mobile/app/components/side-menu/pinned-section.tsx @@ -84,8 +84,7 @@ export const PinnedSection = React.memo( data={menuPins} style={{ flexGrow: 1, - width: "100%", - paddingHorizontal: 12 + width: "100%" }} contentContainerStyle={{ flexGrow: 1 diff --git a/apps/mobile/app/stores/use-menu-store.ts b/apps/mobile/app/stores/use-menu-store.ts index b2b108a3f..865bb031f 100644 --- a/apps/mobile/app/stores/use-menu-store.ts +++ b/apps/mobile/app/stores/use-menu-store.ts @@ -42,12 +42,17 @@ export const useMenuStore = create((set) => ({ }); }, setColorNotes: () => { - db.colors?.all.items().then((colors) => { - set({ - colorNotes: colors, - loadingColors: false + db.colors?.all + .items(undefined, { + sortBy: "dateCreated", + sortDirection: "asc" + }) + .then((colors) => { + set({ + colorNotes: colors, + loadingColors: false + }); }); - }); }, clearAll: () => set({ menuPins: [], colorNotes: [] }) })); diff --git a/packages/core/src/collections/shortcuts.ts b/packages/core/src/collections/shortcuts.ts index 750b14d62..84bdef8a2 100644 --- a/packages/core/src/collections/shortcuts.ts +++ b/packages/core/src/collections/shortcuts.ts @@ -101,6 +101,7 @@ export class Shortcuts implements ICollection { ): Promise> { const tagIds: string[] = []; const notebookIds: string[] = []; + for (const shortcut of this.all) { if ( (type === "all" || type === "notebooks") && @@ -113,12 +114,29 @@ export class Shortcuts implements ICollection { ) tagIds.push(shortcut.itemId); } - return [ - ...(notebookIds.length > 0 + + const notebooks = + notebookIds.length > 0 ? await this.db.notebooks.all.items(notebookIds) - : []), - ...(tagIds.length > 0 ? await this.db.tags.all.items(tagIds) : []) - ] as ResolveTypeToItem; + : []; + const tags = tagIds.length > 0 ? await this.db.tags.all.items(tagIds) : []; + + const sortedItems: (Notebook | Tag)[] = []; + + this.all + .sort((a, b) => a.dateCreated - b.dateCreated) + .forEach((shortcut) => { + if (type === "all" || type === "notebooks") { + const notebook = notebooks.find((n) => n.id === shortcut.itemId); + if (notebook) sortedItems.push(notebook); + } + if (type === "all" || type === "tags") { + const tag = tags.find((t) => t.id === shortcut.itemId); + if (tag) sortedItems.push(tag); + } + }); + + return sortedItems as ResolveTypeToItem; } exists(id: string) {