diff --git a/src/globals.d.ts b/src/globals.d.ts index 2a4190f9..c7b5d43b 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -104,6 +104,7 @@ type Item = { text?: string isFavorite?: boolean // injected in UI array isRunning?: boolean // only apps have this + bookmarkFolder? : null | string // only bookmarks have this } type OnboardingStep = diff --git a/src/stores/ui.store.tsx b/src/stores/ui.store.tsx index 7790043b..16b7a1e8 100644 --- a/src/stores/ui.store.tsx +++ b/src/stores/ui.store.tsx @@ -109,6 +109,7 @@ let minisearch = new MiniSearch({ 'shortcut', 'isFavorite', 'isRunning', + 'bookmarkFolder', ], searchOptions: { prefix: true, @@ -261,9 +262,17 @@ export const createUIStore = (root: IRootStore) => { launchAtLogin: true, useBackgroundOverlay: true, hasFullDiskAccess: false, - safariBookmarks: [] as {title: string; url: string}[], - braveBookmarks: [] as {title: string; url: string}[], - chromeBookmarks: [] as {title: string; url: string}[], + safariBookmarks: [] as { + title: string + url: string + bookmarkFolder: string | null + }[], + braveBookmarks: [] as {title: string; url: string; bookmarkFolder: string | null}[], + chromeBookmarks: [] as { + title: string + url: string + bookmarkFolder: string | null + }[], mediaKeyForwardingEnabled: true, targetHeight: 64, isDarkMode: Appearance.getColorScheme() === 'dark', @@ -328,6 +337,7 @@ export const createUIStore = (root: IRootStore) => { id: `${bookmark.title}_safari_${idx}`, name: bookmark.title, type: ItemType.BOOKMARK, + bookmarkFolder: null, iconImage: Assets.Safari, callback: () => { Linking.openURL(bookmark.url) @@ -338,6 +348,7 @@ export const createUIStore = (root: IRootStore) => { return { id: `${bookmark.title}_brave_${idx}`, name: bookmark.title, + bookmarkFolder: bookmark.bookmarkFolder, type: ItemType.BOOKMARK, iconImage: Assets.Brave, callback: () => { @@ -350,6 +361,7 @@ export const createUIStore = (root: IRootStore) => { id: `${bookmark.title}_chrome_${idx}`, name: bookmark.title, type: ItemType.BOOKMARK, + bookmarkFolder: bookmark.bookmarkFolder, iconImage: Assets.Chrome, callback: async () => { if (!bookmark.url) { @@ -741,13 +753,21 @@ export const createUIStore = (root: IRootStore) => { return } const OGbookmarks = JSON.parse(bookmarksString) - let bookmarks = OGbookmarks.roots.bookmark_bar.children.map( - (v: any) => ({ - title: v.name, - url: v.url, - }), - ) - + let bookmarks: { + title: string + url: string + bookmarkFolder: null | string + }[] = [] + const traverse = (nodes: any[], bookmarkFolder: null | string) => { + nodes.forEach(node => { + if (node.type === 'folder') { + traverse(node.children, node.name) + } else if (node.type === 'url') { + bookmarks.push({title: node.name, url: node.url, bookmarkFolder}) + } + }) + } + traverse(OGbookmarks.roots.bookmark_bar.children, null) store.braveBookmarks = bookmarks } }, @@ -761,13 +781,18 @@ export const createUIStore = (root: IRootStore) => { return } const OGbookmarks = JSON.parse(bookmarksString) - let bookmarks = OGbookmarks.roots.bookmark_bar.children.map( - (v: any) => ({ - title: v.name, - url: v.url, - }), - ) - + let bookmarks: {title: string; url: string; bookmarkFolder: null | string}[] = + [] + const traverse = (nodes: any[], bookmarkFolder: null | string) => { + nodes.forEach(node => { + if (node.type === 'folder') { + traverse(node.children, node.name) + } else if (node.type === 'url') { + bookmarks.push({title: node.name, url: node.url, bookmarkFolder}) + } + }) + } + traverse(OGbookmarks.roots.bookmark_bar.children, null) store.chromeBookmarks = bookmarks } }, @@ -825,7 +850,7 @@ export const createUIStore = (root: IRootStore) => { setCustomSearchUrl: (url: string) => { store.customSearchUrl = url }, - + onHotkey({id}: {id: string}) { let item = store.items.find(i => i.id === id) if (item == null) { diff --git a/src/widgets/search.widget.tsx b/src/widgets/search.widget.tsx index 20a0fee9..c5353792 100644 --- a/src/widgets/search.widget.tsx +++ b/src/widgets/search.widget.tsx @@ -130,6 +130,12 @@ export const SearchWidget: FC = observer(() => { {renderToKeys(store.ui.shortcuts[item.id])} )} + {item.type === ItemType.BOOKMARK && !!item.bookmarkFolder && ( + {`${item.bookmarkFolder.substring( + 0, + 16, + )}${item.bookmarkFolder.length > 16 ? '...' : ''}`} + )} )