aboutsummaryrefslogtreecommitdiff
path: root/src/screens/suggestedPeopleOnboarding
diff options
context:
space:
mode:
authorShravya Ramesh <shravs1208@gmail.com>2021-05-24 14:03:32 -0700
committerShravya Ramesh <shravs1208@gmail.com>2021-05-24 14:03:32 -0700
commite09f37e73b45a58c0a6ebf8ad8b5216c91713f26 (patch)
tree73fc1435227e418be15480ca9b12d865dcb0f8a2 /src/screens/suggestedPeopleOnboarding
parent5afdf9208fd3d7498a2595797e6c9fb5f567fc61 (diff)
Fix yarn lint issues
Diffstat (limited to 'src/screens/suggestedPeopleOnboarding')
-rw-r--r--src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx245
1 files changed, 122 insertions, 123 deletions
diff --git a/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx b/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx
index af5fd579..f5a9f280 100644
--- a/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx
+++ b/src/screens/suggestedPeopleOnboarding/SuggestedPeopleUploadPictureScreen.tsx
@@ -38,139 +38,138 @@ type SuggestedPeopleUploadPictureScreenProps = {
route: SuggestedPeopleUploadPictureScreenRouteProp;
};
-const SuggestedPeopleUploadPictureScreen: React.FC<SuggestedPeopleUploadPictureScreenProps> = ({
- route,
-}) => {
- const {editing} = route.params;
- const [image, setImage] = useState<string | undefined>(undefined);
- const [oldImage, setOldImage] = useState<string | undefined>(undefined);
- const [loading, setLoading] = useState(false);
- const dispatch = useDispatch();
- const navigation = useNavigation();
- const {
- user: {userId: loggedInUserId},
- } = useSelector((state: RootState) => state.user);
+const SuggestedPeopleUploadPictureScreen: React.FC<SuggestedPeopleUploadPictureScreenProps> =
+ ({route}) => {
+ const {editing} = route.params;
+ const [image, setImage] = useState<string | undefined>(undefined);
+ const [oldImage, setOldImage] = useState<string | undefined>(undefined);
+ const [loading, setLoading] = useState(false);
+ const dispatch = useDispatch();
+ const navigation = useNavigation();
+ const {
+ user: {userId: loggedInUserId},
+ } = useSelector((state: RootState) => state.user);
- useEffect(() => {
- const loadData = async () => {
- const response = await getSuggestedPeopleProfile(loggedInUserId);
- if (response) {
- setImage(response.suggested_people_url);
- setOldImage(response.suggested_people_url);
+ useEffect(() => {
+ const loadData = async () => {
+ const response = await getSuggestedPeopleProfile(loggedInUserId);
+ if (response) {
+ setImage(response.suggested_people_url);
+ setOldImage(response.suggested_people_url);
+ }
+ };
+ // if we're in edit SP, attempt to load current sp image
+ if (editing) {
+ loadData();
}
- };
- // if we're in edit SP, attempt to load current sp image
- if (editing) {
- loadData();
- }
- }, []);
+ }, []);
- const openImagePicker = () => {
- ImagePicker.openPicker({
- smartAlbums: [
- 'Favorites',
- 'RecentlyAdded',
- 'SelfPortraits',
- 'Screenshots',
- 'UserLibrary',
- ],
- width: SP_WIDTH,
- height: SP_HEIGHT,
- cropping: true,
- cropperToolbarTitle: 'Select Photo',
- mediaType: 'photo',
- })
- .then((picture) => {
- if ('path' in picture) {
- setImage(picture.path);
- }
+ const openImagePicker = () => {
+ ImagePicker.openPicker({
+ smartAlbums: [
+ 'Favorites',
+ 'RecentlyAdded',
+ 'SelfPortraits',
+ 'Screenshots',
+ 'UserLibrary',
+ ],
+ width: SP_WIDTH,
+ height: SP_HEIGHT,
+ cropping: true,
+ cropperToolbarTitle: 'Select Photo',
+ mediaType: 'photo',
})
- .catch((_) => {});
- };
+ .then((picture) => {
+ if ('path' in picture) {
+ setImage(picture.path);
+ }
+ })
+ .catch((_) => {});
+ };
- const uploadImage = async () => {
- // Uploading image only if initially loaded image is not the same as the image being uploaded
- if (image && oldImage !== image) {
- setLoading(true);
- const success = await sendSuggestedPeoplePhoto(image);
- if (success) {
- dispatch(uploadedSuggestedPeoplePhoto(image));
- if (!editing) {
- navigation.navigate('BadgeSelection', {editing: false});
+ const uploadImage = async () => {
+ // Uploading image only if initially loaded image is not the same as the image being uploaded
+ if (image && oldImage !== image) {
+ setLoading(true);
+ const success = await sendSuggestedPeoplePhoto(image);
+ if (success) {
+ dispatch(uploadedSuggestedPeoplePhoto(image));
+ if (!editing) {
+ navigation.navigate('BadgeSelection', {editing: false});
+ }
+ } else {
+ Alert.alert(ERROR_UPLOAD);
+ }
+ setLoading(false);
+ // Navigated back to Profile if user is editing their Suggested People Picture
+ if (editing) {
+ navigation.goBack();
+ setTimeout(() => {
+ Alert.alert(success ? SUCCESS_PIC_UPLOAD : ERROR_UPLOAD_SP_PHOTO);
+ }, 500);
}
- } else {
- Alert.alert(ERROR_UPLOAD);
- }
- setLoading(false);
- // Navigated back to Profile if user is editing their Suggested People Picture
- if (editing) {
- navigation.goBack();
- setTimeout(() => {
- Alert.alert(success ? SUCCESS_PIC_UPLOAD : ERROR_UPLOAD_SP_PHOTO);
- }, 500);
}
- }
- };
+ };
- return (
- <>
- {loading && <TaggLoadingIndicator fullscreen />}
- <StatusBar barStyle={'light-content'} />
- <SafeAreaView style={styles.container}>
- <Text style={editing ? styles.titleEditSuggested : styles.titlePHOTO}>
- {editing ? 'Edit Suggested' : 'PHOTO'}
- </Text>
- {image ? (
- <Text style={styles.body}>
- {editing
- ? 'Tap to upload new photo'
- : 'Tap again to choose another photo'}
+ return (
+ <>
+ {loading && <TaggLoadingIndicator fullscreen />}
+ <StatusBar barStyle={'light-content'} />
+ <SafeAreaView style={styles.container}>
+ <Text style={editing ? styles.titleEditSuggested : styles.titlePHOTO}>
+ {editing ? 'Edit Suggested' : 'PHOTO'}
</Text>
- ) : (
- <Text style={styles.body}>
- Upload a photo, this is what other users will see
- </Text>
- )}
- {image ? (
- <TouchableOpacity onPress={openImagePicker}>
- <ImageBackground
- source={{uri: image, cache: 'reload'}}
- style={[styles.imageContainer, styles.overlay]}
- borderRadius={30}>
- <Image
- style={styles.overlay}
+ {image ? (
+ <Text style={styles.body}>
+ {editing
+ ? 'Tap to upload new photo'
+ : 'Tap again to choose another photo'}
+ </Text>
+ ) : (
+ <Text style={styles.body}>
+ Upload a photo, this is what other users will see
+ </Text>
+ )}
+ {image ? (
+ <TouchableOpacity onPress={openImagePicker}>
+ <ImageBackground
+ source={{uri: image, cache: 'reload'}}
+ style={[styles.imageContainer, styles.overlay]}
+ borderRadius={30}>
+ <Image
+ style={styles.overlay}
+ source={require('../../assets/images/suggested-people-preview-silhouette.png')}
+ />
+ </ImageBackground>
+ </TouchableOpacity>
+ ) : (
+ <TouchableOpacity onPress={openImagePicker}>
+ <ImageBackground
source={require('../../assets/images/suggested-people-preview-silhouette.png')}
- />
- </ImageBackground>
- </TouchableOpacity>
- ) : (
- <TouchableOpacity onPress={openImagePicker}>
- <ImageBackground
- source={require('../../assets/images/suggested-people-preview-silhouette.png')}
- style={[styles.imageContainer, styles.overlay]}>
- <Image
- style={styles.images}
- source={require('../../assets/images/images.png')}
- />
- <Text style={styles.body}>Upload Photo</Text>
- </ImageBackground>
- </TouchableOpacity>
- )}
- {image && (
- <TaggSquareButton
- onPress={uploadImage}
- title={'Done'}
- buttonStyle={'normal'}
- buttonColor={editing ? 'blue' : 'purple'}
- labelColor={'white'}
- style={styles.buttonStyle}
- labelStyle={styles.buttonLabel}
- />
- )}
- </SafeAreaView>
- </>
- );
-};
+ style={[styles.imageContainer, styles.overlay]}>
+ <Image
+ style={styles.images}
+ source={require('../../assets/images/images.png')}
+ />
+ <Text style={styles.body}>Upload Photo</Text>
+ </ImageBackground>
+ </TouchableOpacity>
+ )}
+ {image && (
+ <TaggSquareButton
+ onPress={uploadImage}
+ title={'Done'}
+ buttonStyle={'normal'}
+ buttonColor={editing ? 'blue' : 'purple'}
+ labelColor={'white'}
+ style={styles.buttonStyle}
+ labelStyle={styles.buttonLabel}
+ />
+ )}
+ </SafeAreaView>
+ </>
+ );
+ };
const styles = StyleSheet.create({
container: {