Merge pull request #119 from linkwarden/dev

bug fix
This commit is contained in:
Daniel
2025-02-07 06:59:32 +03:30
committed by GitHub
3 changed files with 47 additions and 6 deletions
+7 -3
View File
@@ -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;
}) => (
<CommandItem
value={collection.name}
key={collection.id}
className="cursor-pointer"
className="cursor-pointer flex flex-col items-start justify-start"
onSelect={() => {
form.setValue('collection', {
ownerId: collection.ownerId,
@@ -288,7 +289,10 @@ const BookmarkForm = () => {
setOpenCollections(false);
}}
>
{collection.name}
<p>{collection.name}</p>
<p className="text-xs text-neutral-500">
{collection.pathname}
</p>
</CommandItem>
)
)
+39 -2
View File
@@ -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<number, ResponseCollections>
): 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,
pathname: buildFullPath(collection, collectionsMap),
}));
return {
...response,
data: {
response: formattedCollections,
},
};
}
+1 -1
View File
@@ -45,7 +45,7 @@
"_execute_action": {
"suggested_key": {
"default": "Ctrl+Shift+F",
"mac": "Command+Shift+K"
"mac": "Command+Shift+Y"
}
}
}