diff options
author | Patrizio Bekerle <patrizio@bekerle.com> | 2024-06-20 21:32:25 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2024-06-27 21:28:44 +0200 |
commit | 3aae9e379d81551e33c0c263883eea46ac95bcc6 (patch) | |
tree | b2780c47d735b32e54cc7b7bf68cf702c2784b80 | |
parent | 2603fee0e85788fa45a6b34fb3a56ab64a9d5445 (diff) |
add: filter persistence
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/components/feed-display/FeedItemDisplayList.vue | 44 |
2 files changed, 43 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dfb87649..2e3ff1db9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the # Unreleased ## [25.x.x] ### Changed +- Persist the filter state and show unread items by default (#2704) ### Fixed - Fix undefined item when using `j` and `k` keyboards shortcuts in an empty feed (#2689) diff --git a/src/components/feed-display/FeedItemDisplayList.vue b/src/components/feed-display/FeedItemDisplayList.vue index c9291f6fd..4bfd31177 100644 --- a/src/components/feed-display/FeedItemDisplayList.vue +++ b/src/components/feed-display/FeedItemDisplayList.vue @@ -113,8 +113,8 @@ export default Vue.extend({ return { mounted: false, - // no filter to start - filter: () => { return true as boolean }, + // Show unread items at start + filter: () => { return this.unreadFilter }, // Always want to sort by date (most recent first) sort: (a: FeedItem, b: FeedItem) => { @@ -144,10 +144,48 @@ export default Vue.extend({ this.selectedItem = newVal }, }, + created() { + this.loadFilter() + }, mounted() { this.mounted = true }, methods: { + storeFilter() { + try { + let filterString = 'noFilter' + + if (this.filter === this.starFilter) { + filterString = 'starFilter' + } else if (this.filter === this.unreadFilter) { + filterString = 'unreadFilter' + } + + localStorage.setItem('news-filter', filterString) + } catch (error) { + console.error('Error saving filter to local storage:', error) + } + }, + loadFilter() { + try { + const filterString = localStorage.getItem('news-filter') + + if (filterString) { + switch (filterString) { + case 'starFilter': + this.filter = this.starFilter + break + case 'unreadFilter': + this.filter = this.unreadFilter + break + default: + this.filter = this.noFilter + } + } + } catch (error) { + console.error('Error loading filter from local storage:', error) + } + }, fetchMore() { this.$emit('load-more') }, @@ -169,6 +207,8 @@ export default Vue.extend({ } else { this.filter = filter as () => boolean } + + this.storeFilter() }, filterSortedItems(): FeedItem[] { let response = [...this.items] as FeedItem[] |