Rework Linkding integration based on feedback on the PR

pull/895/head
Cees Bos 2025-04-01 20:24:54 +02:00
parent e1fdb0069b
commit a63f9e2c7c
1 changed files with 21 additions and 26 deletions

View File

@ -1,8 +1,6 @@
<template> <template>
<template v-for="bookmark in bookmarks" :key="bookmark.name"> <Generic v-for="bookmark in bookmarks" :key="bookmark.name" :item="bookmark">
<Generic :item="bookmark"> </Generic>
</Generic>
</template>
</template> </template>
<script> <script>
@ -16,16 +14,16 @@ export default {
}, },
mixins: [service], mixins: [service],
props: { props: {
item: Object item: Object,
}, },
data: () => ({ data: () => ({
bookmarks: [], bookmarks: [],
}), }),
computed: { computed: {
calculatedLimit: function () { calculatedLimit: function () {
let limit = this.item.limit ? this.item.limit : 5; const limit = parseInt(this.item.limit) || 5;
return Math.min(Math.max(limit,1),15); return Math.min(Math.max(limit, 1), 15);
} },
}, },
created() { created() {
this.fetchBookmarks(); this.fetchBookmarks();
@ -37,32 +35,29 @@ export default {
Accept: "application/json", Accept: "application/json",
}; };
let limit = this.calculatedLimit; let query = "";
let query = ''
if (this.item.query) { if (this.item.query) {
query = `&q=${encodeURIComponent(this.item.query)}`; query = `&q=${encodeURIComponent(this.item.query)}`;
} }
let url = `/api/bookmarks/?limit=${limit}${query}`; let url = `/api/bookmarks/?limit=${this.calculatedLimit}${query}`;
this.fetch(url, { this.fetch(url, {
headers, headers,
}) })
.then((ld_response) => { .then((ld_response) => {
this.bookmarks = ld_response.results.map(bookmark => ({ this.bookmarks = ld_response.results.map((bookmark) => ({
name: `${bookmark.title}`, name: `${bookmark.title}`,
subtitle: `${bookmark.description}`, subtitle: `${bookmark.description}`,
url: bookmark.url, url: bookmark.url,
logo: `${bookmark.favicon_url}`, logo: `${bookmark.favicon_url}`,
tag: `${bookmark.tag_names.join(" #")}` tag: `${bookmark.tag_names.join(" #")}`,
})); }));
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
this.error = true; });
});
}, },
}, },
}; };
</script> </script>