diff options
Diffstat (limited to 'src/view/com/notifications/Feed.tsx')
-rw-r--r-- | src/view/com/notifications/Feed.tsx | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/view/com/notifications/Feed.tsx b/src/view/com/notifications/Feed.tsx new file mode 100644 index 000000000..7c95003c7 --- /dev/null +++ b/src/view/com/notifications/Feed.tsx @@ -0,0 +1,50 @@ +import React from 'react' +import {observer} from 'mobx-react-lite' +import {Text, View, FlatList} from 'react-native' +import {OnNavigateContent} from '../../routes/types' +import { + NotificationsViewModel, + NotificationsViewItemModel, +} from '../../../state/models/notifications-view' +import {FeedItem} from './FeedItem' + +export const Feed = observer(function Feed({ + view, + onNavigateContent, +}: { + view: NotificationsViewModel + onNavigateContent: OnNavigateContent +}) { + // TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf + // 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} onNavigateContent={onNavigateContent} /> + ) + 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)) + } + return ( + <View> + {view.isLoading && !view.isRefreshing && !view.hasContent && ( + <Text>Loading...</Text> + )} + {view.hasError && <Text>{view.error}</Text>} + {view.hasContent && ( + <FlatList + data={view.notifications} + keyExtractor={item => item._reactKey} + renderItem={renderItem} + refreshing={view.isRefreshing} + onRefresh={onRefresh} + onEndReached={onEndReached} + /> + )} + {view.isEmpty && <Text>This feed is empty!</Text>} + </View> + ) +}) |