Skip to content

Commit

Permalink
Store saved feeds on the root store so we can load on init (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee authored Nov 2, 2023
1 parent f57a8cf commit 5927166
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/state/models/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import {RootStoreModel} from './root-store'
import {PostsFeedModel} from './feeds/posts'
import {NotificationsFeedModel} from './feeds/notifications'
import {MyFeedsUIModel} from './ui/my-feeds'
import {MyFollowsCache} from './cache/my-follows'
import {isObj, hasProp} from 'lib/type-guards'

Expand All @@ -22,6 +23,7 @@ export class MeModel {
followersCount: number | undefined
mainFeed: PostsFeedModel
notifications: NotificationsFeedModel
myFeeds: MyFeedsUIModel
follows: MyFollowsCache
invites: ComAtprotoServerDefs.InviteCode[] = []
appPasswords: ComAtprotoServerListAppPasswords.AppPassword[] = []
Expand All @@ -42,12 +44,14 @@ export class MeModel {
algorithm: 'reverse-chronological',
})
this.notifications = new NotificationsFeedModel(this.rootStore)
this.myFeeds = new MyFeedsUIModel(this.rootStore)
this.follows = new MyFollowsCache(this.rootStore)
}

clear() {
this.mainFeed.clear()
this.notifications.clear()
this.myFeeds.clear()
this.follows.clear()
this.rootStore.profiles.cache.clear()
this.rootStore.posts.cache.clear()
Expand Down Expand Up @@ -111,6 +115,11 @@ export class MeModel {
/* dont await */ this.notifications.setup().catch(e => {
this.rootStore.log.error('Failed to setup notifications model', e)
})
/* dont await */ this.notifications.setup().catch(e => {
this.rootStore.log.error('Failed to setup notifications model', e)
})
this.myFeeds.clear()
/* dont await */ this.myFeeds.saved.refresh()
this.rootStore.emitSessionLoaded()
await this.fetchInviteCodes()
await this.fetchAppPasswords()
Expand Down
7 changes: 6 additions & 1 deletion src/state/models/ui/my-feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export class MyFeedsUIModel {
}
}

clear() {
this.saved.clear()
this.discovery.clear()
}

registerListeners() {
const dispose1 = reaction(
() => this.rootStore.preferences.savedFeeds,
Expand Down Expand Up @@ -107,7 +112,7 @@ export class MyFeedsUIModel {
_reactKey: '__saved_feeds_header__',
type: 'saved-feeds-header',
})
if (this.saved.isLoading) {
if (this.saved.isLoading && !this.saved.hasContent) {
items.push({
_reactKey: '__saved_feeds_loading__',
type: 'saved-feeds-loading',
Expand Down
4 changes: 4 additions & 0 deletions src/state/models/ui/saved-feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export class SavedFeedsModel {
// public api
// =

clear() {
this.all = []
}

/**
* Refresh the preferences then reload all feed infos
*/
Expand Down
4 changes: 2 additions & 2 deletions src/view/screens/Feeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import {ErrorMessage} from 'view/com/util/error/ErrorMessage'
import debounce from 'lodash.debounce'
import {Text} from 'view/com/util/text/Text'
import {MyFeedsUIModel, MyFeedsItem} from 'state/models/ui/my-feeds'
import {MyFeedsItem} from 'state/models/ui/my-feeds'
import {FeedSourceModel} from 'state/models/content/feed-source'
import {FlatList} from 'view/com/util/Views'
import {useFocusEffect} from '@react-navigation/native'
Expand All @@ -34,7 +34,7 @@ export const FeedsScreen = withAuthRequired(
const pal = usePalette('default')
const store = useStores()
const {isMobile, isTabletOrDesktop} = useWebMediaQueries()
const myFeeds = React.useMemo(() => new MyFeedsUIModel(store), [store])
const myFeeds = store.me.myFeeds
const [query, setQuery] = React.useState<string>('')
const debouncedSearchFeeds = React.useMemo(
() => debounce(q => myFeeds.discovery.search(q), 500), // debounce for 500ms
Expand Down

0 comments on commit 5927166

Please sign in to comment.