diff --git a/src/state/models/feeds/algo/algo-item.ts b/src/state/models/feeds/algo/algo-item.ts index 39bc760a..8291b6d8 100644 --- a/src/state/models/feeds/algo/algo-item.ts +++ b/src/state/models/feeds/algo/algo-item.ts @@ -67,30 +67,12 @@ export class AlgoItemModel { } } + private rewriteData(data: AppBskyFeedDefs.GeneratorView) { + this.data = data + } + // public apis // = - async save() { - try { - this.toggleSaved = true - await this.rootStore.agent.app.bsky.feed.saveFeed({ - feed: this.data.uri, - }) - } catch (e: any) { - this.rootStore.log.error('Failed to save feed', e) - } - } - - async unsave() { - try { - this.toggleSaved = false - await this.rootStore.agent.app.bsky.feed.unsaveFeed({ - feed: this.data.uri, - }) - } catch (e: any) { - this.rootStore.log.error('Failed to unsanve feed', e) - } - } - async like() { try { const res = await this.rootStore.agent.app.bsky.feed.like.create( @@ -151,7 +133,7 @@ export class AlgoItemModel { const res = await this.rootStore.agent.app.bsky.feed.getFeedGenerator({ feed: this.data.uri, }) - this.data = res.data.view + this.rewriteData(res.data.view) } serialize() { diff --git a/src/state/models/feeds/algo/saved.ts b/src/state/models/feeds/algo/saved.ts index 15859fe0..97d75820 100644 --- a/src/state/models/feeds/algo/saved.ts +++ b/src/state/models/feeds/algo/saved.ts @@ -71,6 +71,12 @@ export class SavedFeedsModel { ) } + get listOfPinnedFeedNames() { + return this.pinned.map( + f => f.data.displayName ?? f.data.creator.displayName + "'s feed", + ) + } + get savedFeedsWithoutPinned() { return this.feeds.filter( f => !this.pinned.find(p => p.data.uri === f.data.uri), @@ -81,10 +87,14 @@ export class SavedFeedsModel { if (!this.isPinned(feed)) { this.pinned.push(feed) } else { - this.pinned = this.pinned.filter(f => f.data.uri !== feed.data.uri) + this.removePinnedFeed(feed.data.uri) } } + removePinnedFeed(uri: string) { + this.pinned = this.pinned.filter(f => f.data.uri !== uri) + } + reorderPinnedFeeds(temp: AlgoItemModel[]) { this.pinned = temp } @@ -144,18 +154,22 @@ export class SavedFeedsModel { await this.rootStore.agent.app.bsky.feed.saveFeed({ feed: algoItem.getUri, }) + algoItem.toggleSaved = true this.addFeed(algoItem) } catch (e: any) { this.rootStore.log.error('Failed to save feed', e) } } - async unsave(uri: string) { + async unsave(algoItem: AlgoItemModel) { + const uri = algoItem.getUri try { await this.rootStore.agent.app.bsky.feed.unsaveFeed({ feed: uri, }) + algoItem.toggleSaved = false this.removeFeed(uri) + this.removePinnedFeed(uri) } catch (e: any) { this.rootStore.log.error('Failed to unsanve feed', e) } diff --git a/src/view/com/algos/AlgoItem.tsx b/src/view/com/algos/AlgoItem.tsx index f7d32053..b52a7e00 100644 --- a/src/view/com/algos/AlgoItem.tsx +++ b/src/view/com/algos/AlgoItem.tsx @@ -13,7 +13,7 @@ import {UserAvatar} from '../util/UserAvatar' import {Button} from '../util/forms/Button' import {observer} from 'mobx-react-lite' import {AlgoItemModel} from 'state/models/feeds/algo/algo-item' -import {useNavigation} from '@react-navigation/native' +import {useFocusEffect, useNavigation} from '@react-navigation/native' import {NavigationProp} from 'lib/routes/types' import {useStores} from 'state/index' import {HeartIconSolid} from 'lib/icons' @@ -34,6 +34,11 @@ const AlgoItem = observer( const pal = usePalette('default') const navigation = useNavigation() + // TODO: this is pretty hacky, but it works for now + useFocusEffect(() => { + item.reload() + }) + return (