Move posts feed to root store (me) and ensure new posts always update the feed
parent
ebfa6e5581
commit
345ec83f26
|
@ -1,5 +1,6 @@
|
||||||
import {makeAutoObservable, runInAction} from 'mobx'
|
import {makeAutoObservable, runInAction} from 'mobx'
|
||||||
import {RootStoreModel} from './root-store'
|
import {RootStoreModel} from './root-store'
|
||||||
|
import {FeedModel} from './feed-view'
|
||||||
import {MembershipsViewModel} from './memberships-view'
|
import {MembershipsViewModel} from './memberships-view'
|
||||||
import {NotificationsViewModel} from './notifications-view'
|
import {NotificationsViewModel} from './notifications-view'
|
||||||
import {isObj, hasProp} from '../lib/type-guards'
|
import {isObj, hasProp} from '../lib/type-guards'
|
||||||
|
@ -12,6 +13,7 @@ export class MeModel {
|
||||||
avatar: string = ''
|
avatar: string = ''
|
||||||
notificationCount: number = 0
|
notificationCount: number = 0
|
||||||
memberships?: MembershipsViewModel
|
memberships?: MembershipsViewModel
|
||||||
|
mainFeed: FeedModel
|
||||||
notifications: NotificationsViewModel
|
notifications: NotificationsViewModel
|
||||||
|
|
||||||
constructor(public rootStore: RootStoreModel) {
|
constructor(public rootStore: RootStoreModel) {
|
||||||
|
@ -20,6 +22,9 @@ export class MeModel {
|
||||||
{rootStore: false, serialize: false, hydrate: false},
|
{rootStore: false, serialize: false, hydrate: false},
|
||||||
{autoBind: true},
|
{autoBind: true},
|
||||||
)
|
)
|
||||||
|
this.mainFeed = new FeedModel(this.rootStore, 'home', {
|
||||||
|
algorithm: 'reverse-chronological',
|
||||||
|
})
|
||||||
this.notifications = new NotificationsViewModel(this.rootStore, {})
|
this.notifications = new NotificationsViewModel(this.rootStore, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,12 +98,17 @@ export class MeModel {
|
||||||
this.memberships = new MembershipsViewModel(this.rootStore, {
|
this.memberships = new MembershipsViewModel(this.rootStore, {
|
||||||
actor: this.did,
|
actor: this.did,
|
||||||
})
|
})
|
||||||
await this.memberships?.setup().catch(e => {
|
await Promise.all([
|
||||||
console.error('Failed to setup memberships model', e)
|
this.memberships?.setup().catch(e => {
|
||||||
})
|
console.error('Failed to setup memberships model', e)
|
||||||
await this.notifications.setup().catch(e => {
|
}),
|
||||||
console.error('Failed to setup notifications model', e)
|
this.mainFeed.setup().catch(e => {
|
||||||
})
|
console.error('Failed to setup main feed model', e)
|
||||||
|
}),
|
||||||
|
this.notifications.setup().catch(e => {
|
||||||
|
console.error('Failed to setup notifications model', e)
|
||||||
|
}),
|
||||||
|
])
|
||||||
} else {
|
} else {
|
||||||
this.clear()
|
this.clear()
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
setIsProcessing(false)
|
setIsProcessing(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
store.me.mainFeed.loadLatest()
|
||||||
onPost?.()
|
onPost?.()
|
||||||
onClose()
|
onClose()
|
||||||
Toast.show(`Your ${replyTo ? 'reply' : 'post'} has been published`)
|
Toast.show(`Your ${replyTo ? 'reply' : 'post'} has been published`)
|
||||||
|
|
|
@ -27,23 +27,16 @@ export const Home = observer(function Home({
|
||||||
const {appState} = useAppState({
|
const {appState} = useAppState({
|
||||||
onForeground: () => doPoll(true),
|
onForeground: () => doPoll(true),
|
||||||
})
|
})
|
||||||
const defaultFeedView = useMemo<FeedModel>(
|
|
||||||
() =>
|
|
||||||
new FeedModel(store, 'home', {
|
|
||||||
algorithm: 'reverse-chronological',
|
|
||||||
}),
|
|
||||||
[store],
|
|
||||||
)
|
|
||||||
|
|
||||||
const doPoll = (knownActive = false) => {
|
const doPoll = (knownActive = false) => {
|
||||||
if ((!knownActive && appState !== 'active') || !visible) {
|
if ((!knownActive && appState !== 'active') || !visible) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (defaultFeedView.isLoading) {
|
if (store.me.mainFeed.isLoading) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('Polling home feed')
|
console.log('Polling home feed')
|
||||||
defaultFeedView.checkForLatest().catch(e => {
|
store.me.mainFeed.checkForLatest().catch(e => {
|
||||||
console.error('Failed to poll feed', e)
|
console.error('Failed to poll feed', e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -57,11 +50,11 @@ export const Home = observer(function Home({
|
||||||
|
|
||||||
if (hasSetup) {
|
if (hasSetup) {
|
||||||
console.log('Updating home feed')
|
console.log('Updating home feed')
|
||||||
defaultFeedView.update()
|
store.me.mainFeed.update()
|
||||||
} else {
|
} else {
|
||||||
store.nav.setTitle(navIdx, 'Home')
|
store.nav.setTitle(navIdx, 'Home')
|
||||||
console.log('Fetching home feed')
|
console.log('Fetching home feed')
|
||||||
defaultFeedView.setup().then(() => {
|
store.me.mainFeed.setup().then(() => {
|
||||||
if (aborted) return
|
if (aborted) return
|
||||||
setHasSetup(true)
|
setHasSetup(true)
|
||||||
})
|
})
|
||||||
|
@ -73,37 +66,29 @@ export const Home = observer(function Home({
|
||||||
}, [visible, store])
|
}, [visible, store])
|
||||||
|
|
||||||
const onPressCompose = () => {
|
const onPressCompose = () => {
|
||||||
store.shell.openComposer({onPost: onCreatePost})
|
store.shell.openComposer({})
|
||||||
}
|
|
||||||
const onCreatePost = () => {
|
|
||||||
defaultFeedView.loadLatest()
|
|
||||||
}
|
}
|
||||||
const onPressTryAgain = () => {
|
const onPressTryAgain = () => {
|
||||||
defaultFeedView.refresh()
|
store.me.mainFeed.refresh()
|
||||||
}
|
}
|
||||||
const onPressLoadLatest = () => {
|
const onPressLoadLatest = () => {
|
||||||
defaultFeedView.refresh()
|
store.me.mainFeed.refresh()
|
||||||
scrollElRef?.current?.scrollToOffset({offset: 0})
|
scrollElRef?.current?.scrollToOffset({offset: 0})
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={s.flex1}>
|
<View style={s.flex1}>
|
||||||
<ViewHeader
|
<ViewHeader title="Bluesky" subtitle="Private Beta" canGoBack={false} />
|
||||||
title="Bluesky"
|
|
||||||
subtitle="Private Beta"
|
|
||||||
canGoBack={false}
|
|
||||||
onPost={onCreatePost}
|
|
||||||
/>
|
|
||||||
<Feed
|
<Feed
|
||||||
key="default"
|
key="default"
|
||||||
feed={defaultFeedView}
|
feed={store.me.mainFeed}
|
||||||
scrollElRef={scrollElRef}
|
scrollElRef={scrollElRef}
|
||||||
style={{flex: 1}}
|
style={{flex: 1}}
|
||||||
onPressCompose={onPressCompose}
|
onPressCompose={onPressCompose}
|
||||||
onPressTryAgain={onPressTryAgain}
|
onPressTryAgain={onPressTryAgain}
|
||||||
onScroll={onMainScroll}
|
onScroll={onMainScroll}
|
||||||
/>
|
/>
|
||||||
{defaultFeedView.hasNewLatest ? (
|
{store.me.mainFeed.hasNewLatest ? (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={[
|
style={[
|
||||||
styles.loadLatest,
|
styles.loadLatest,
|
||||||
|
|
Loading…
Reference in New Issue