aboutsummaryrefslogtreecommitdiff
path: root/src/components/moments/Moment.tsx
blob: 0ceb8542f12c6bf26c1b5d7200fa3a458253740e (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import {useNavigation} from '@react-navigation/native';
import React from 'react';
import {Alert, StyleProp, StyleSheet, View, ViewStyle} from 'react-native';
import {Text} from 'react-native-animatable';
import {ScrollView, TouchableOpacity} from 'react-native-gesture-handler';
import ImagePicker from 'react-native-image-crop-picker';
import LinearGradient from 'react-native-linear-gradient';
import DeleteIcon from '../../assets/icons/delete-logo.svg';
import DownIcon from '../../assets/icons/down_icon.svg';
import PlusIcon from '../../assets/icons/plus_icon-01.svg';
import BigPlusIcon from '../../assets/icons/plus_icon-02.svg';
import UpIcon from '../../assets/icons/up_icon.svg';
import {TAGG_LIGHT_BLUE} from '../../constants';
import {ERROR_UPLOAD} from '../../constants/strings';
import {MomentType, ScreenType} from '../../types';
import {normalize, SCREEN_WIDTH} from '../../utils';
import MomentTile from './MomentTile';

interface MomentProps {
  title: string;
  images: MomentType[] | undefined;
  userXId: string | undefined;
  screenType: ScreenType;
  handleMomentCategoryDelete: (_: string) => void;
  shouldAllowDeletion: boolean;
  showUpButton: boolean;
  showDownButton: boolean;
  move?: (direction: 'up' | 'down', title: string) => void;
  externalStyles?: Record<string, StyleProp<ViewStyle>>;
}

const Moment: React.FC<MomentProps> = ({
  title,
  images,
  userXId,
  screenType,
  handleMomentCategoryDelete,
  shouldAllowDeletion,
  showUpButton,
  showDownButton,
  move,
  externalStyles,
}) => {
  const navigation = useNavigation();

  const navigateToImagePicker = () => {
    ImagePicker.openPicker({
      smartAlbums: [
        'Favorites',
        'RecentlyAdded',
        'SelfPortraits',
        'Screenshots',
        'UserLibrary',
      ],
      width: 580,
      height: 580,
      cropping: true,
      cropperToolbarTitle: 'Upload a moment',
      mediaType: 'photo',
    })
      .then((picture) => {
        if ('path' in picture) {
          navigation.navigate('CaptionScreen', {
            screenType,
            title: title,
            image: picture,
          });
        }
      })
      .catch((err) => {
        if (err.code && err.code !== 'E_PICKER_CANCELLED') {
          Alert.alert(ERROR_UPLOAD);
        }
      });
  };

  return (
    <View style={[styles.container, externalStyles?.container]}>
      <View style={[styles.header, externalStyles?.header]}>
        <Text
          style={[styles.titleText, externalStyles?.titleText]}
          numberOfLines={2}>
          {title}
        </Text>
        <View style={styles.buttonsContainer}>
          {!userXId && (
            <View style={styles.row}>
              {showUpButton && move && (
                <UpIcon
                  width={19}
                  height={19}
                  onPress={() => move('up', title)}
                  color={TAGG_LIGHT_BLUE}
                  style={styles.horizontalMargin}
                />
              )}
              {showDownButton && move && (
                <DownIcon
                  width={19}
                  height={19}
                  onPress={() => move('down', title)}
                  color={TAGG_LIGHT_BLUE}
                  style={styles.horizontalMargin}
                />
              )}
            </View>
          )}
          {!userXId && (
            <View style={styles.row}>
              <PlusIcon
                width={23}
                height={23}
                onPress={() => navigateToImagePicker()}
                color={TAGG_LIGHT_BLUE}
                style={styles.horizontalMargin}
              />
              {shouldAllowDeletion && (
                <DeleteIcon
                  onPress={() => handleMomentCategoryDelete(title)}
                  width={19}
                  height={19}
                  style={[styles.horizontalMargin, styles.deleButtonAdjustment]}
                />
              )}
            </View>
          )}
        </View>
      </View>
      <ScrollView
        horizontal
        showsHorizontalScrollIndicator={false}
        style={[styles.scrollContainer, externalStyles?.scrollContainer]}>
        {images &&
          images.map((imageObj: MomentType) => (
            <MomentTile
              key={imageObj.moment_id}
              moment={imageObj}
              userXId={userXId}
              screenType={screenType}
            />
          ))}
        {(images === undefined || images.length === 0) && !userXId && (
          <TouchableOpacity onPress={() => navigateToImagePicker()}>
            <LinearGradient
              colors={['rgba(105, 141, 211, 1)', 'rgba(105, 141, 211, 0.3)']}>
              <View style={styles.defaultImage}>
                <BigPlusIcon width={24} height={24} />
                <Text style={styles.defaultImageText}>
                  Add a moment of your {title?.toLowerCase()}!
                </Text>
              </View>
            </LinearGradient>
          </TouchableOpacity>
        )}
      </ScrollView>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column',
    backgroundColor: '#eee',
  },
  header: {
    flex: 1,
    padding: '3%',
    backgroundColor: 'white',
    flexDirection: 'row',
    alignItems: 'center',
  },
  titleText: {
    fontSize: normalize(16),
    fontWeight: 'bold',
    color: TAGG_LIGHT_BLUE,
    maxWidth: '70%',
  },
  flexer: {
    flex: 1,
  },
  scrollContainer: {
    height: SCREEN_WIDTH / 3.25,
    backgroundColor: '#eee',
  },
  defaultImage: {
    aspectRatio: 1,
    height: '100%',
    alignItems: 'center',
    justifyContent: 'center',
    flexDirection: 'column',
  },
  defaultImageText: {
    fontSize: 14,
    paddingTop: 10,
    color: 'white',
    fontWeight: 'bold',
    width: '80%',
    textAlign: 'center',
  },
  buttonsContainer: {
    flexDirection: 'row',
    flex: 1,
    justifyContent: 'space-between',
    minWidth: 50,
    alignItems: 'center',
  },
  row: {flexDirection: 'row'},
  horizontalMargin: {marginHorizontal: 4},
  deleButtonAdjustment: {top: 2},
});

export default Moment;