aboutsummaryrefslogtreecommitdiff
path: root/src/components/notifications/Notification.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/notifications/Notification.tsx')
-rw-r--r--src/components/notifications/Notification.tsx102
1 files changed, 68 insertions, 34 deletions
diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx
index e0ae231e..951a5bf6 100644
--- a/src/components/notifications/Notification.tsx
+++ b/src/components/notifications/Notification.tsx
@@ -2,7 +2,9 @@ import {useNavigation} from '@react-navigation/native';
import React, {useEffect, useState} from 'react';
import {Alert, Image, StyleSheet, Text, View} from 'react-native';
import {TouchableWithoutFeedback} from 'react-native-gesture-handler';
+import LinearGradient from 'react-native-linear-gradient';
import {useDispatch, useStore} from 'react-redux';
+import {BACKGROUND_GRADIENT_MAP} from '../../constants';
import {ERROR_DELETED_OBJECT} from '../../constants/strings';
import {
loadImageFromURL,
@@ -51,7 +53,6 @@ const Notification: React.FC<NotificationProps> = (props) => {
const [avatar, setAvatar] = useState<string | undefined>(undefined);
const [momentURI, setMomentURI] = useState<string | undefined>(undefined);
- const backgroundColor = unread ? '#DCF1F1' : 'rgba(0,0,0,0)';
const [onTapLoadProfile, setOnTapLoadProfile] = useState<boolean>(false);
useEffect(() => {
@@ -59,6 +60,8 @@ const Notification: React.FC<NotificationProps> = (props) => {
const response = await loadImageFromURL(thumbnail_url);
if (response) {
setAvatar(response);
+ } else {
+ setAvatar(undefined);
}
})();
}, []);
@@ -79,9 +82,17 @@ const Notification: React.FC<NotificationProps> = (props) => {
const response = await loadMomentThumbnail(moment_id);
if (mounted && response) {
setMomentURI(response);
+ } else {
+ // if not set to empty, it will re-use the previous notification's state
+ setMomentURI(undefined);
}
};
- if (notification_type === 'CMT' && notification_object) {
+ if (
+ (notification_type === 'CMT' ||
+ notification_type === 'MOM_3+' ||
+ notification_type === 'MOM_FRIEND') &&
+ notification_object
+ ) {
loadMomentImage(
notification_object.moment_id
? notification_object.moment_id
@@ -166,6 +177,20 @@ const Notification: React.FC<NotificationProps> = (props) => {
}, 500);
}
break;
+ case 'MOM_3+':
+ case 'MOM_FRIEND':
+ const object = notification_object as MomentType;
+ await fetchUserX(
+ dispatch,
+ {userId: id, username: username},
+ screenType,
+ );
+ navigation.push('IndividualMoment', {
+ moment: object,
+ userXId: id,
+ screenType,
+ });
+ break;
default:
break;
}
@@ -184,48 +209,57 @@ const Notification: React.FC<NotificationProps> = (props) => {
dispatch(loadUserNotifications());
};
- return (
- <>
- <TouchableWithoutFeedback
- style={[styles.container, {backgroundColor}]}
- onPress={onNotificationTap}>
- <View style={styles.avatarContainer}>
- <Image
- style={styles.avatar}
- source={
- avatar
- ? {uri: avatar}
- : require('../../assets/images/avatar-placeholder.png')
- }
+ const renderContent = () => (
+ <TouchableWithoutFeedback
+ style={styles.container}
+ onPress={onNotificationTap}>
+ <View style={styles.avatarContainer}>
+ <Image
+ style={styles.avatar}
+ source={
+ avatar
+ ? {uri: avatar}
+ : require('../../assets/images/avatar-placeholder.png')
+ }
+ />
+ </View>
+ <View style={styles.contentContainer}>
+ <Text style={styles.actorName}>
+ {first_name} {last_name}
+ </Text>
+ <Text>{verbage}</Text>
+ </View>
+ {notification_type === 'FRD_REQ' && (
+ <View style={styles.buttonsContainer}>
+ <AcceptDeclineButtons
+ requester={{id, username, first_name, last_name}}
+ onAccept={handleAcceptRequest}
+ onReject={handleDeclineFriendRequest}
/>
</View>
- <View style={styles.contentContainer}>
- <Text style={styles.actorName}>
- {first_name} {last_name}
- </Text>
- <Text>{verbage}</Text>
- </View>
- {notification_type === 'FRD_REQ' && (
- <View style={styles.buttonsContainer}>
- <AcceptDeclineButtons
- requester={{id, username, first_name, last_name}}
- onAccept={handleAcceptRequest}
- onReject={handleDeclineFriendRequest}
- />
- </View>
- )}
- {notification_type === 'CMT' && notification_object && (
+ )}
+ {(notification_type === 'CMT' ||
+ notification_type === 'MOM_3+' ||
+ notification_type === 'MOM_FRIEND') &&
+ notification_object && (
<Image style={styles.moment} source={{uri: momentURI}} />
)}
- </TouchableWithoutFeedback>
- </>
+ </TouchableWithoutFeedback>
+ );
+
+ return unread ? (
+ <LinearGradient colors={BACKGROUND_GRADIENT_MAP[2]} useAngle angle={90}>
+ {renderContent()}
+ </LinearGradient>
+ ) : (
+ renderContent()
);
};
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
- height: SCREEN_HEIGHT / 10,
+ height: Math.round(SCREEN_HEIGHT / 10),
flex: 1,
alignItems: 'center',
},