aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/notifications/Notification.tsx42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx
index d40c65ed..6d473b11 100644
--- a/src/components/notifications/Notification.tsx
+++ b/src/components/notifications/Notification.tsx
@@ -2,7 +2,8 @@ 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 {useDispatch, useStore} from 'react-redux';
+import {useDispatch, useSelector, useStore} from 'react-redux';
+import {ERROR_DELETED_OBJECT} from '../../constants/strings';
import {
loadImageFromURL,
loadMoments,
@@ -12,15 +13,17 @@ import {
acceptFriendRequest,
declineFriendRequest,
loadUserNotifications,
+ loadUserX,
+ loadUserXSpecifics,
updateReplyPosted,
updateUserXFriends,
} from '../../store/actions';
+import {NO_MOMENTS} from '../../store/initialStates';
import {RootState} from '../../store/rootReducer';
import {MomentType, NotificationType, ScreenType} from '../../types';
import {
fetchUserX,
getTokenOrLogout,
- handleOpenSocialUrlOnBrowser,
SCREEN_HEIGHT,
userXInStore,
} from '../../utils';
@@ -52,6 +55,7 @@ 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(() => {
(async () => {
@@ -63,6 +67,22 @@ const Notification: React.FC<NotificationProps> = (props) => {
}, []);
useEffect(() => {
+ if (onTapLoadProfile) {
+ dispatch(
+ loadUserXSpecifics(
+ {userId: id, username: username},
+ ['Profile', 'Moments'],
+ screenType,
+ ),
+ );
+ }
+ return () => {
+ setOnTapLoadProfile(false);
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [onTapLoadProfile]);
+
+ useEffect(() => {
let mounted = true;
const loadMomentImage = async (moment_id: string) => {
const response = await loadMomentThumbnail(moment_id);
@@ -101,7 +121,7 @@ const Notification: React.FC<NotificationProps> = (props) => {
case 'CMT':
//Notification object is set to null if the comment / comment_thread / moment gets deleted
if (!notification_object) {
- Alert.alert('The comment / moment was probably deleted by the user');
+ Alert.alert(ERROR_DELETED_OBJECT);
break;
}
let {moment_id} = notification_object;
@@ -125,17 +145,13 @@ const Notification: React.FC<NotificationProps> = (props) => {
if (!moment) {
let moments: MomentType[] = [];
try {
- if (!userXInStore(state, screenType, id)) {
- const token = await getTokenOrLogout(dispatch);
- moments = await loadMoments(id, token);
- } else {
- moments = state.userX[screenType][id].moments;
- }
+ //Populate local state in the mean time
+ setOnTapLoadProfile(true);
+ const token = await getTokenOrLogout(dispatch);
+ moments = await loadMoments(id, token);
} catch (err) {
console.log(err);
}
-
- setTimeout(() => {}, 700);
moment = moments?.find((m) => m.moment_id === moment_id);
userXId = id;
}
@@ -165,7 +181,9 @@ const Notification: React.FC<NotificationProps> = (props) => {
};
const handleAcceptRequest = async () => {
- await dispatch(acceptFriendRequest({id, username, first_name, last_name}));
+ await dispatch(
+ acceptFriendRequest({id, username, first_name, last_name, thumbnail_url}),
+ );
await dispatch(updateUserXFriends(id, state));
dispatch(loadUserNotifications());
};