aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/CommentReactionScreen.tsx
blob: 0596a1840945364e94838d234308a60a7fa75d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {RouteProp, useNavigation} from '@react-navigation/native';
import React, {useEffect, useState} from 'react';
import {Alert, ScrollView, StyleSheet, View} from 'react-native';
import {SafeAreaView} from 'react-native-safe-area-context';
import {Friends} from '../../components';
import {ERROR_SOMETHING_WENT_WRONG} from '../../constants/strings';
import {MainStackParams} from '../../routes/main';
import {getUsersReactedToAComment} from '../../services';
import {ProfilePreviewType} from '../../types';
import {HeaderHeight, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils';

type CommentReactionScreenRouteProps = RouteProp<
  MainStackParams,
  'CommentReactionScreen'
>;

interface CommentReactionScreenProps {
  route: CommentReactionScreenRouteProps;
}

const CommentReactionScreen: React.FC<CommentReactionScreenProps> = ({
  route,
}) => {
  const navigation = useNavigation();
  const {comment, screenType} = route.params;
  const [users, setUsers] = useState<ProfilePreviewType[]>([]);

  useEffect(() => {
    const loadUsers = async () => {
      const response = await getUsersReactedToAComment(comment);
      if (response.length !== 0) {
        setUsers(response);
      } else {
        Alert.alert(ERROR_SOMETHING_WENT_WRONG);
        navigation.goBack();
      }
    };
    loadUsers();
  }, []);

  return (
    <View style={styles.background}>
      <SafeAreaView>
        <ScrollView style={styles.container}>
          <Friends
            result={users}
            screenType={screenType}
            userId={undefined}
            hideFriendsFeature
          />
        </ScrollView>
      </SafeAreaView>
    </View>
  );
};

const styles = StyleSheet.create({
  background: {
    backgroundColor: 'white',
    width: SCREEN_WIDTH,
    height: SCREEN_HEIGHT,
  },
  container: {
    marginTop: HeaderHeight,
    height: SCREEN_HEIGHT - HeaderHeight,
  },
});

export default CommentReactionScreen;