From c8c6a803491dfe697d3af6d753be4c321209fed0 Mon Sep 17 00:00:00 2001 From: ankit-thanekar007 Date: Mon, 15 Mar 2021 13:07:30 -0700 Subject: Added expansion --- src/screens/main/NotificationsScreen.tsx | 63 ++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/screens/main/NotificationsScreen.tsx b/src/screens/main/NotificationsScreen.tsx index 568c8c73..24be7123 100644 --- a/src/screens/main/NotificationsScreen.tsx +++ b/src/screens/main/NotificationsScreen.tsx @@ -17,6 +17,7 @@ import { Text, View, } from 'react-native'; +import {TouchableOpacity} from 'react-native-gesture-handler'; import {SafeAreaView} from 'react-native-safe-area-context'; import {useDispatch, useSelector} from 'react-redux'; import {TabsGradient, TaggPrompt} from '../../components'; @@ -54,8 +55,13 @@ const NotificationsScreen: React.FC = () => { }[] >([]); + const DEFAULT_NOTIFICATIONS_SIZE = 2; + const [moreFooterEnabled, setMoreFooterEnabled] = useState(false); - const [requestLimit, setrequestLimit] = useState(4); + const [requestLimit, setrequestLimit] = useState(DEFAULT_NOTIFICATIONS_SIZE); + const [allFriendRequests, setFriendRequests] = useState( + [], + ); const dispatch = useDispatch(); @@ -147,7 +153,7 @@ const NotificationsScreen: React.FC = () => { } } } - + setFriendRequests(friendRequests); setSectionedNotifications( todays.length === 0 && yesterdays.length === 0 && @@ -155,13 +161,16 @@ const NotificationsScreen: React.FC = () => { friendRequests.length === 0 ? [] : [ - {title: 'Friend Requests', data: friendRequests}, + { + title: 'Friend Requests', + data: friendRequests.slice(0, requestLimit), + }, {title: 'Today', data: todays}, {title: 'Yesterday', data: yesterdays}, {title: 'This Week', data: thisWeeks}, ], ); - }, [lastViewed, notifications, showSPNotifyPopUp]); + }, [lastViewed, notifications, showSPNotifyPopUp, requestLimit]); const renderNotification = ({item}: {item: NotificationType}) => ( { /> ); - const renderSectionHeader = ({section: {title, data}}) => + const renderSectionHeader = ({ + section: {title, data}, + }: { + section: {title: string; data: NotificationType[]}; + }) => data.length !== 0 && ( { ); - const renderSectionFooter = ({section: {title, data}}) => { - if (title === 'Friend Request' && data.length < requestLimit) { + const renderSectionFooter = ({ + section: {title, data}, + }: { + section: {title: string; data: NotificationType[]}; + }) => { + if (title === 'Friend Requests') { + if (moreFooterEnabled) { + return ( + { + setrequestLimit(DEFAULT_NOTIFICATIONS_SIZE); + setMoreFooterEnabled(false); + }}> + + {'Hide'} + + + ); + } return ( - + { + setrequestLimit(allFriendRequests.length); + setMoreFooterEnabled(true); + }}> - {title} + {`+ ${allFriendRequests.length - requestLimit} More`} - + ); } @@ -248,6 +288,7 @@ const NotificationsScreen: React.FC = () => { refreshControl={ } + extraData={requestLimit} ListEmptyComponent={ -- cgit v1.2.3-70-g09d2