From ca79b0c4d802562580eef9c7c85c4974ec4c2252 Mon Sep 17 00:00:00 2001 From: chfhtw Date: Mon, 27 Apr 2026 10:15:44 +0200 Subject: [PATCH] make sharedFiltered a computed and rename it to filteredBookmarks & get rid of unnecessary functions --- public/js/components/DashboardWidget/Url.js | 201 +++++++++----------- 1 file changed, 90 insertions(+), 111 deletions(-) diff --git a/public/js/components/DashboardWidget/Url.js b/public/js/components/DashboardWidget/Url.js index 38dad5ce7..b6a780dc1 100644 --- a/public/js/components/DashboardWidget/Url.js +++ b/public/js/components/DashboardWidget/Url.js @@ -35,8 +35,7 @@ export default { newTag: null, selectedFilters: [], filter: [], - filteredArray: [], - sharedFiltered: {}, + filteredArray: [] }), computed: { availableTags() { @@ -45,17 +44,17 @@ export default { .flat() .filter((v, i, a) => v && a.indexOf(v) === i); }, - tagName() { - return this.config.tag !== undefined && this.config.tag.length > 0 - ? this.config.tag - : this.$p.t("bookmark", "myBookmarks"); - }, - emptyBookmarks() { - if (this.shared instanceof Array && this.shared.length == 0) return true; + filteredBookmarks() { + if (!this.shared) + return []; - if (!this.shared) return true; + if (!this.config.tags || !this.config.tags.length) + return this.shared; - return false; + return this.shared.filter(bookmark => { + const tags = JSON.parse(bookmark.tag || "[]"); + return tags.some(tag => this.config.tags.includes(tag)); + }); }, newSort(){ if(this.shared.length == 0) @@ -67,19 +66,16 @@ export default { if(this.shared.length == 0) return 0; else - return Math.max(...this.sharedFiltered.map(b => b.sort)); + return Math.max(...this.filteredBookmarks.map(b => b.sort)); }, minSort(){ if(this.shared.length == 0) return 0; else - return Math.min(...this.sharedFiltered.map(b => b.sort)); + return Math.min(...this.filteredBookmarks.map(b => b.sort)); } }, methods: { - stopDrag(event){ - event.preventDefault(); - }, clearInputs(){ this.title_input = ""; this.url_input = ""; @@ -171,10 +167,6 @@ export default { .then((res) => res.data) .then((result) => { this.shared = result; - - this.$nextTick(() => { - this.sharedFiltered = this.filterBookmarksByTags(this.shared); - }); }) .catch(this.$fhcAlert.handleSystemError); }, @@ -194,18 +186,10 @@ export default { }) .catch(this.$fhcAlert.handleSystemError); }, - filterBookmarksByTags(bookmarks) { - if (!this.config.tags || !this.config.tags.length) - return bookmarks; - return bookmarks.filter(bookmark => { - const tags = JSON.parse(bookmark.tag || "[]"); - return tags.some(tag => this.config.tags.includes(tag)); - }); - }, sortDown(bookmark_id){ - const current = this.sharedFiltered.find(b => b.bookmark_id === bookmark_id); + const current = this.filteredBookmarks.find(b => b.bookmark_id === bookmark_id); - const next = this.sharedFiltered + const next = this.filteredBookmarks .filter(b => b.sort > current.sort) .sort((a, b) => a.sort - b.sort)[0]; @@ -216,9 +200,9 @@ export default { this.changeOrder(current.bookmark_id, next.bookmark_id); }, sortUp(bookmark_id){ - const current = this.sharedFiltered.find(b => b.bookmark_id === bookmark_id); + const current = this.filteredBookmarks.find(b => b.bookmark_id === bookmark_id); - const next = this.sharedFiltered + const next = this.filteredBookmarks .filter(b => b.sort < current.sort) .sort((a, b) => a.sort + b.sort)[0]; @@ -275,7 +259,6 @@ export default { async handleAddingTagFilter(widgetId) { this.config.tags = this.selectedFilters; this.$emit('change'); - this.sharedFiltered = this.filterBookmarksByTags(this.shared); this.$fhcAlert.alertInfo(this.$p.t("bookmark", "filterUpdated")); this.$refs.filterModal.hide(); }, @@ -329,93 +312,89 @@ export default { - +
+ {{ $p.t('bookmark', 'emptyBookmarks') }} +
+