From 8bce18d32ad4e60e2463385ed969648108008723 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Wed, 22 Jan 2025 05:30:03 -0500 Subject: [PATCH 1/3] bug fix --- src/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manifest.json b/src/manifest.json index 5d06398..4b03ace 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -45,7 +45,7 @@ "_execute_action": { "suggested_key": { "default": "Ctrl+Shift+F", - "mac": "Command+Shift+K" + "mac": "Command+Shift+Y" } } } From ef119b40850b27302003237c228a70ff9fd848ee Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Sun, 26 Jan 2025 21:51:32 +0200 Subject: [PATCH 2/3] Commit --- src/@/lib/actions/collections.ts | 43 +++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/@/lib/actions/collections.ts b/src/@/lib/actions/collections.ts index e89fad0..7ce2ea7 100644 --- a/src/@/lib/actions/collections.ts +++ b/src/@/lib/actions/collections.ts @@ -9,17 +9,54 @@ interface ResponseCollections { members: never[]; // Assuming members can be of any type, adjust as necessary name: string; ownerId: number; - parent: null | never; // Assuming parent can be of any type or null, adjust as necessary + parent: null | { + id: number; + name: string; + }; parentId: null | number; // Assuming parentId can be null or a number updatedAt: string; } +function buildFullPath( + collection: ResponseCollections, + collectionsMap: Map +): string { + const paths: string[] = [collection.name]; + let currentParent = collection.parent; + + while (currentParent) { + paths.unshift(currentParent.name); + const parentCollection = collectionsMap.get(currentParent.id); + currentParent = parentCollection?.parent || null; + } + + return paths.join(' > '); +} + export async function getCollections(baseUrl: string, apiKey: string) { const url = `${baseUrl}/api/v1/collections`; - return await axios.get<{ response: ResponseCollections[] }>(url, { + const response = await axios.get<{ response: ResponseCollections[] }>(url, { headers: { Authorization: `Bearer ${apiKey}`, }, }); -} + + // Create a map for quick lookups + const collectionsMap = new Map( + response.data.response.map(collection => [collection.id, collection]) + ); + + // Format the collection names with full parent structure + const formattedCollections = response.data.response.map(collection => ({ + ...collection, + name: buildFullPath(collection, collectionsMap) + })); + + return { + ...response, + data: { + response: formattedCollections + } + }; +} \ No newline at end of file From de33d7d7e0ede4ee73aaf7767b580ce2d9324c59 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Thu, 6 Feb 2025 22:27:08 -0500 Subject: [PATCH 3/3] improvement --- src/@/components/BookmarkForm.tsx | 10 +++++++--- src/@/lib/actions/collections.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/@/components/BookmarkForm.tsx b/src/@/components/BookmarkForm.tsx index 836a87b..52057e0 100644 --- a/src/@/components/BookmarkForm.tsx +++ b/src/@/components/BookmarkForm.tsx @@ -166,7 +166,7 @@ const BookmarkForm = () => { const response = await getCollections(config.baseUrl, config.apiKey); return response.data.response.sort((a, b) => { - return a.name.localeCompare(b.name); + return a.pathname.localeCompare(b.pathname); }); }, enabled: configured, @@ -274,11 +274,12 @@ const BookmarkForm = () => { name: string; id: number; ownerId: number; + pathname: string; }) => ( { form.setValue('collection', { ownerId: collection.ownerId, @@ -288,7 +289,10 @@ const BookmarkForm = () => { setOpenCollections(false); }} > - {collection.name} +

{collection.name}

+

+ {collection.pathname} +

) ) diff --git a/src/@/lib/actions/collections.ts b/src/@/lib/actions/collections.ts index 7ce2ea7..27754a5 100644 --- a/src/@/lib/actions/collections.ts +++ b/src/@/lib/actions/collections.ts @@ -44,19 +44,19 @@ export async function getCollections(baseUrl: string, apiKey: string) { // Create a map for quick lookups const collectionsMap = new Map( - response.data.response.map(collection => [collection.id, collection]) + response.data.response.map((collection) => [collection.id, collection]) ); // Format the collection names with full parent structure - const formattedCollections = response.data.response.map(collection => ({ + const formattedCollections = response.data.response.map((collection) => ({ ...collection, - name: buildFullPath(collection, collectionsMap) + pathname: buildFullPath(collection, collectionsMap), })); return { ...response, data: { - response: formattedCollections - } + response: formattedCollections, + }, }; -} \ No newline at end of file +}