diff options
Diffstat (limited to 'src/view/screens/Notifications.tsx')
-rw-r--r-- | src/view/screens/Notifications.tsx | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx index 1e7abdb90..b168ffaff 100644 --- a/src/view/screens/Notifications.tsx +++ b/src/view/screens/Notifications.tsx @@ -7,43 +7,33 @@ import {NotificationsViewModel} from '../../state/models/notifications-view' import {ScreenParams} from '../routes' export const Notifications = ({navIdx, visible}: ScreenParams) => { - const [hasSetup, setHasSetup] = useState<boolean>(false) - const [notesView, setNotesView] = useState< - NotificationsViewModel | undefined - >() const store = useStores() useEffect(() => { - let aborted = false if (!visible) { return } + console.log('Updating notifications feed') store.me.refreshMemberships() // needed for the invite notifications - if (hasSetup) { - console.log('Updating notifications feed') - notesView?.update() - } else { - store.nav.setTitle(navIdx, 'Notifications') - const newNotesView = new NotificationsViewModel(store, {}) - setNotesView(newNotesView) - newNotesView.setup().then(() => { - if (aborted) return - setHasSetup(true) + store.me.notifications + .update() + .catch(e => { + console.error('Error while updating notifications feed', e) }) - } - return () => { - aborted = true - } + .then(() => { + store.me.notifications.updateReadState() + }) + store.nav.setTitle(navIdx, 'Notifications') }, [visible, store]) const onPressTryAgain = () => { - notesView?.refresh() + store.me.notifications.refresh() } return ( <View style={{flex: 1}}> <ViewHeader title="Notifications" /> - {notesView && <Feed view={notesView} onPressTryAgain={onPressTryAgain} />} + <Feed view={store.me.notifications} onPressTryAgain={onPressTryAgain} /> </View> ) } |