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