about summary refs log tree commit diff
path: root/src/view/screens/Notifications.tsx
diff options
context:
space:
mode:
authorJoão Ferreiro <ferreiro@pinkroom.dev>2022-11-29 10:29:19 +0000
committerJoão Ferreiro <ferreiro@pinkroom.dev>2022-11-29 10:29:19 +0000
commit77ea3bfd0a28f76651ed425cf733abcf01ecaa24 (patch)
tree53f6806d2ca00366f6f3298e378aa6a59ca17e83 /src/view/screens/Notifications.tsx
parent3ce113f1076bbeeffc20888b3a28b2680ada8ab5 (diff)
parent88c868dd808d204fc29deb162609de984745b951 (diff)
downloadvoidsky-77ea3bfd0a28f76651ed425cf733abcf01ecaa24.tar.zst
Merge branch 'main' into upload-image
Diffstat (limited to 'src/view/screens/Notifications.tsx')
-rw-r--r--src/view/screens/Notifications.tsx32
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>
   )
 }