From 7ffbee18b578cc7f6d5eff6b7b4740eeb278d387 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 6 Nov 2023 20:51:46 -0600 Subject: [PATCH] Fix removal of old lists from saved feeds (#1823) * Fix removal of old lists from saved feeds * Fix saved feed removal race condition --- src/state/models/content/feed-source.ts | 11 +++++++++-- src/state/models/content/list.ts | 2 +- src/state/models/ui/saved-feeds.ts | 14 ++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/state/models/content/feed-source.ts b/src/state/models/content/feed-source.ts index 79747d6f..156e3be3 100644 --- a/src/state/models/content/feed-source.ts +++ b/src/state/models/content/feed-source.ts @@ -142,7 +142,8 @@ export class FeedSourceModel { } async unsave() { - if (this.type !== 'feed-generator') { + // TODO TEMPORARY — see PRF's comment in content/list.ts togglePin + if (this.type !== 'feed-generator' && this.type !== 'list') { return } try { @@ -179,7 +180,13 @@ export class FeedSourceModel { name: this.displayName, uri: this.uri, }) - return this.rootStore.preferences.removePinnedFeed(this.uri) + + if (this.type === 'list') { + // TODO TEMPORARY — see PRF's comment in content/list.ts togglePin + return this.unsave() + } else { + return this.rootStore.preferences.removePinnedFeed(this.uri) + } } } diff --git a/src/state/models/content/list.ts b/src/state/models/content/list.ts index 115426e5..fc09eeb9 100644 --- a/src/state/models/content/list.ts +++ b/src/state/models/content/list.ts @@ -361,7 +361,7 @@ export class ListModel { name: this.data?.name || '', uri: this.uri, }) - // TEMPORARY + // TODO TEMPORARY // lists are temporarily piggybacking on the saved/pinned feeds preferences // we'll eventually replace saved feeds with the bookmarks API // until then, we need to unsave lists instead of just unpin them diff --git a/src/state/models/ui/saved-feeds.ts b/src/state/models/ui/saved-feeds.ts index fd84edc0..624da4f5 100644 --- a/src/state/models/ui/saved-feeds.ts +++ b/src/state/models/ui/saved-feeds.ts @@ -38,12 +38,18 @@ export class SavedFeedsModel { return this.hasLoaded && !this.hasContent } - get pinned() { - return this.all.filter(feed => feed.isPinned) + get pinned(): FeedSourceModel[] { + return this.rootStore.preferences.savedFeeds + .filter(feed => this.rootStore.preferences.isPinnedFeed(feed)) + .map(uri => this.all.find(f => f.uri === uri)) + .filter(Boolean) as FeedSourceModel[] } - get unpinned() { - return this.all.filter(feed => !feed.isPinned) + get unpinned(): FeedSourceModel[] { + return this.rootStore.preferences.savedFeeds + .filter(feed => !this.rootStore.preferences.isPinnedFeed(feed)) + .map(uri => this.all.find(f => f.uri === uri)) + .filter(Boolean) as FeedSourceModel[] } get pinnedFeedNames() {