Merge pull request #2021 from ecency/nt/notification-pagination-fix

Nt - Notification Pagination Fix
This commit is contained in:
Feruz M 2021-08-04 15:51:34 +03:00 committed by GitHub
commit 9eea520954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 19 deletions

View File

@ -1,6 +1,6 @@
/* eslint-disable react/jsx-wrap-multilines */ /* eslint-disable react/jsx-wrap-multilines */
import React, { PureComponent, Fragment } from 'react'; import React, { PureComponent } from 'react';
import { View, FlatList, ActivityIndicator, RefreshControl, Text } from 'react-native'; import { View, FlatList, ActivityIndicator, RefreshControl, Text, SectionList } from 'react-native';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
// Constants // Constants
@ -95,41 +95,40 @@ class NotificationView extends PureComponent {
title: intl.formatMessage({ title: intl.formatMessage({
id: 'notification.recent', id: 'notification.recent',
}), }),
notifications: [], data: [],
}, },
{ {
title: intl.formatMessage({ title: intl.formatMessage({
id: 'notification.yesterday', id: 'notification.yesterday',
}), }),
notifications: [], data: [],
}, },
{ {
title: intl.formatMessage({ title: intl.formatMessage({
id: 'notification.this_week', id: 'notification.this_week',
}), }),
notifications: [], data: [],
}, },
{ {
title: intl.formatMessage({ title: intl.formatMessage({
id: 'notification.this_month', id: 'notification.this_month',
}), }),
notifications: [], data: [],
}, },
{ {
title: intl.formatMessage({ title: intl.formatMessage({
id: 'notification.older_then', id: 'notification.older_then',
}), }),
notifications: [], data: [],
}, },
]; ];
notifications.forEach((item) => { notifications.forEach((item) => {
const listIndex = this._getTimeListIndex(item.timestamp); const listIndex = this._getTimeListIndex(item.timestamp);
notificationArray[listIndex].data.push(item);
notificationArray[listIndex].notifications.push(item);
}); });
return notificationArray.filter((item) => item.notifications.length > 0); return notificationArray.filter((item) => item.data.length > 0).map((item, index)=>{item.index = index; return item});
}; };
_getTimeListIndex = (timestamp) => { _getTimeListIndex = (timestamp) => {
@ -152,18 +151,26 @@ class NotificationView extends PureComponent {
return 4; return 4;
}; };
_getActivityIndicator = () => ( _getActivityIndicator = () => (
<View style={styles.loading}> <View style={styles.loading}>
<ActivityIndicator animating size="large" /> <ActivityIndicator animating size="large" />
</View> </View>
); );
_renderItem = ({ item, index }) => (
<Fragment> _renderSectionHeader = ({ section: { title, index} }) => (
<ContainerHeader hasSeperator={index !== 0} isBoldTitle title={item.title} key={item.title} /> <ContainerHeader hasSeperator={index !== 0} isBoldTitle title={title} key={title} />
{this._renderList(item.notifications)} )
</Fragment>
);
_renderItem = ({ item }) => (
<NotificationLine
notification={item}
handleOnPressNotification={this.props.navigateToNotificationRoute}
/>
)
render() { render() {
const { readAllNotification, getActivities, isNotificationRefreshing, intl } = this.props; const { readAllNotification, getActivities, isNotificationRefreshing, intl } = this.props;
@ -187,13 +194,14 @@ class NotificationView extends PureComponent {
<ThemeContainer> <ThemeContainer>
{({ isDarkTheme }) => {({ isDarkTheme }) =>
_notifications && _notifications.length > 0 ? ( _notifications && _notifications.length > 0 ? (
<FlatList <SectionList
data={_notifications} sections={_notifications}
keyExtractor={(item) => item.title} keyExtractor={(item, index) => item.title + index}
onEndReached={() => getActivities(selectedFilter, true)} onEndReached={() => getActivities(selectedFilter, true)}
ListFooterComponent={this._renderFooterLoading} ListFooterComponent={this._renderFooterLoading}
ListEmptyComponent={<ListPlaceHolder />} ListEmptyComponent={<ListPlaceHolder />}
contentContainerStyle={styles.listContentContainer} contentContainerStyle={styles.listContentContainer}
stickySectionHeadersEnabled={false}
refreshControl={ refreshControl={
<RefreshControl <RefreshControl
refreshing={isNotificationRefreshing} refreshing={isNotificationRefreshing}
@ -205,6 +213,7 @@ class NotificationView extends PureComponent {
/> />
} }
renderItem={this._renderItem} renderItem={this._renderItem}
renderSectionHeader={this._renderSectionHeader}
/> />
) : ( ) : (
<Text style={globalStyles.hintText}> <Text style={globalStyles.hintText}>