diff options
author | Ivan Chen <ivan@tagg.id> | 2021-02-02 16:17:47 -0500 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-02-02 16:17:47 -0500 |
commit | ddaf0797be48876eade913d2b9b5c1357ce6bc5e (patch) | |
tree | c0a7d8243582332975e2959a8423255547fd36a5 | |
parent | f8a3e57ab04af5658cb48aaa3fded31126bdaa8b (diff) |
fixed thumbnail reuse bug, added gradient
-rw-r--r-- | src/components/notifications/Notification.tsx | 82 | ||||
-rw-r--r-- | src/services/CommonService.ts | 2 |
2 files changed, 51 insertions, 33 deletions
diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index 28a5d912..4258e288 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -53,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(() => { @@ -61,6 +60,8 @@ const Notification: React.FC<NotificationProps> = (props) => { const response = await loadImageFromURL(thumbnail_url); if (response) { setAvatar(response); + } else { + setAvatar(''); } })(); }, []); @@ -81,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(''); } }; - 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 @@ -200,41 +209,50 @@ const Notification: React.FC<NotificationProps> = (props) => { dispatch(loadUserNotifications()); }; - return ( - <LinearGradient colors={BACKGROUND_GRADIENT_MAP[2]} useAngle angle={90}> - <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() ); }; diff --git a/src/services/CommonService.ts b/src/services/CommonService.ts index 4f9fb47a..dfbbf70e 100644 --- a/src/services/CommonService.ts +++ b/src/services/CommonService.ts @@ -6,7 +6,7 @@ export const loadImageFromURL = async (url: string) => { return undefined; } const response = await RNFetchBlob.config({ - fileCache: true, + fileCache: false, appendExt: 'jpg', }).fetch('GET', url); const status = response.info().status; |