about summary refs log tree commit diff
path: root/src/view/screens/Notifications.tsx
blob: 60627385f7378cccf40926723679a62e6e55b4ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React, {useState, useEffect} from 'react'
import {View} from 'react-native'
import {Feed} from '../com/notifications/Feed'
import {useStores} from '../../state'
import {NotificationsViewModel} from '../../state/models/notifications-view'
import {ScreenParams} from '../routes'

export const Notifications = ({visible}: ScreenParams) => {
  const [hasSetup, setHasSetup] = useState<boolean>(false)
  const [notesView, setNotesView] = useState<
    NotificationsViewModel | undefined
  >()
  const store = useStores()

  useEffect(() => {
    if (!visible) {
      return
    }
    if (hasSetup) {
      console.log('Updating notifications feed')
      notesView?.update()
    } else {
      store.nav.setTitle('Notifications')
      console.log('Fetching notifications feed')
      const newNotesView = new NotificationsViewModel(store, {})
      setNotesView(newNotesView)
      newNotesView.setup().then(() => setHasSetup(true))
    }
  }, [visible, store])

  return <View>{notesView && <Feed view={notesView} />}</View>
}