about summary refs log tree commit diff
path: root/src/view/com/notifications/Feed.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/com/notifications/Feed.tsx')
-rw-r--r--src/view/com/notifications/Feed.tsx41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/view/com/notifications/Feed.tsx b/src/view/com/notifications/Feed.tsx
index d3a911f2a..a6af0f88a 100644
--- a/src/view/com/notifications/Feed.tsx
+++ b/src/view/com/notifications/Feed.tsx
@@ -1,15 +1,14 @@
 import React from 'react'
 import {observer} from 'mobx-react-lite'
 import {View, FlatList} from 'react-native'
-import {
-  NotificationsViewModel,
-  NotificationsViewItemModel,
-} from '../../../state/models/notifications-view'
+import {NotificationsViewModel} from '../../../state/models/notifications-view'
 import {FeedItem} from './FeedItem'
 import {NotificationFeedLoadingPlaceholder} from '../util/LoadingPlaceholder'
 import {ErrorMessage} from '../util/ErrorMessage'
 import {EmptyState} from '../util/EmptyState'
 
+const EMPTY_FEED_ITEM = {_reactKey: '__empty__'}
+
 export const Feed = observer(function Feed({
   view,
   onPressTryAgain,
@@ -21,20 +20,35 @@ export const Feed = observer(function Feed({
   //   VirtualizedList: You have a large list that is slow to update - make sure your
   //   renderItem function renders components that follow React performance best practices
   //   like PureComponent, shouldComponentUpdate, etc
-  const renderItem = ({item}: {item: NotificationsViewItemModel}) => (
-    <FeedItem item={item} />
-  )
+  const renderItem = ({item}: {item: any}) => {
+    if (item === EMPTY_FEED_ITEM) {
+      return (
+        <EmptyState
+          icon="bell"
+          message="No notifications yet!"
+          style={{paddingVertical: 40}}
+        />
+      )
+    }
+    return <FeedItem item={item} />
+  }
   const onRefresh = () => {
     view.refresh().catch(err => console.error('Failed to refresh', err))
   }
   const onEndReached = () => {
     view.loadMore().catch(err => console.error('Failed to load more', err))
   }
+  let data
+  if (view.hasLoaded) {
+    if (view.isEmpty) {
+      data = [EMPTY_FEED_ITEM]
+    } else {
+      data = view.notifications
+    }
+  }
   return (
     <View style={{flex: 1}}>
-      {view.isLoading && !view.isRefreshing && !view.hasContent && (
-        <NotificationFeedLoadingPlaceholder />
-      )}
+      {view.isLoading && !data && <NotificationFeedLoadingPlaceholder />}
       {view.hasError && (
         <ErrorMessage
           dark
@@ -43,9 +57,9 @@ export const Feed = observer(function Feed({
           onPressTryAgain={onPressTryAgain}
         />
       )}
-      {view.hasLoaded && (
+      {data && (
         <FlatList
-          data={view.notifications}
+          data={data}
           keyExtractor={item => item._reactKey}
           renderItem={renderItem}
           refreshing={view.isRefreshing}
@@ -53,9 +67,6 @@ export const Feed = observer(function Feed({
           onEndReached={onEndReached}
         />
       )}
-      {view.hasLoaded && view.isEmpty && (
-        <EmptyState icon="bell" message="No notifications yet!" />
-      )}
     </View>
   )
 })