From ddaf0797be48876eade913d2b9b5c1357ce6bc5e Mon Sep 17 00:00:00 2001
From: Ivan Chen <ivan@tagg.id>
Date: Tue, 2 Feb 2021 16:17:47 -0500
Subject: fixed thumbnail reuse bug, added gradient

---
 src/components/notifications/Notification.tsx | 82 ++++++++++++++++-----------
 1 file changed, 50 insertions(+), 32 deletions(-)

(limited to 'src/components/notifications/Notification.tsx')

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()
   );
 };
 
-- 
cgit v1.2.3-70-g09d2

