From 1e948b556fd53c02d7462576b183cdd6c4c793bb Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 13 May 2021 17:59:29 -0400 Subject: Revert "[TMA-844] Plus sign for profile and header in profile, ability to add on the sc…" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/icons/grey-purple-plus.svg | 5 -- src/assets/icons/purple-plus.svg | 15 ----- src/components/profile/Cover.tsx | 108 +++++----------------------------- src/components/profile/TaggAvatar.tsx | 67 ++------------------- src/utils/common.ts | 17 ------ src/utils/users.ts | 82 -------------------------- 6 files changed, 18 insertions(+), 276 deletions(-) delete mode 100644 src/assets/icons/grey-purple-plus.svg delete mode 100644 src/assets/icons/purple-plus.svg (limited to 'src') diff --git a/src/assets/icons/grey-purple-plus.svg b/src/assets/icons/grey-purple-plus.svg deleted file mode 100644 index 2053d4a7..00000000 --- a/src/assets/icons/grey-purple-plus.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/src/assets/icons/purple-plus.svg b/src/assets/icons/purple-plus.svg deleted file mode 100644 index 20949b6d..00000000 --- a/src/assets/icons/purple-plus.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/components/profile/Cover.tsx b/src/components/profile/Cover.tsx index 5d5b4234..27777b64 100644 --- a/src/components/profile/Cover.tsx +++ b/src/components/profile/Cover.tsx @@ -1,93 +1,28 @@ -import React, {useState, useEffect} from 'react'; -import { - Image, - StyleSheet, - View, - TouchableOpacity, - Text, - ImageBackground, -} from 'react-native'; +import React from 'react'; +import {Image, StyleSheet, View} from 'react-native'; +import {useSelector} from 'react-redux'; import {COVER_HEIGHT, IMAGE_WIDTH} from '../../constants'; -import {ScreenType} from '../../types'; -import GreyPurplePlus from '../../assets/icons/grey-purple-plus.svg'; -import {useDispatch, useSelector} from 'react-redux'; -import {loadUserData, resetHeaderAndProfileImage} from '../../store/actions'; import {RootState} from '../../store/rootreducer'; -import {normalize, patchProfile, validateImageLink} from '../../utils'; +import {ScreenType} from '../../types'; interface CoverProps { userXId: string | undefined; screenType: ScreenType; } const Cover: React.FC = ({userXId, screenType}) => { - const dispatch = useDispatch(); - const {cover, user} = useSelector((state: RootState) => + const {cover} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, ); - const [needsUpdate, setNeedsUpdate] = useState(false); - const [loading, setLoading] = useState(false); - const [validImage, setValidImage] = useState(true); - - useEffect(() => { - checkAvatar(cover); - }, []); - - useEffect(() => { - if (needsUpdate) { - const userId = user.userId; - const username = user.username; - dispatch(resetHeaderAndProfileImage()); - dispatch(loadUserData({userId, username})); - } - }, [dispatch, needsUpdate]); - - const handleNewImage = async () => { - setLoading(true); - const result = await patchProfile('header', user.userId); - setLoading(true); - if (result) { - setNeedsUpdate(true); - } else { - setLoading(false); - } - }; - - const checkAvatar = async (url: string | undefined) => { - const valid = await validateImageLink(url); - if (valid !== validImage) { - setValidImage(valid); - } - }; - - if (!validImage && userXId === undefined && !loading) { - return ( - - - handleNewImage()}> - - Add Picture - - - - ); - } else { - return ( - - - - ); - } + return ( + + + + ); }; const styles = StyleSheet.create({ @@ -98,20 +33,5 @@ const styles = StyleSheet.create({ width: IMAGE_WIDTH, height: COVER_HEIGHT, }, - plus: { - position: 'absolute', - top: 75, - right: 125, - }, - text: { - color: 'white', - position: 'absolute', - fontSize: normalize(16), - top: 80, - right: 20, - }, - touch: { - flex: 1, - }, }); export default Cover; diff --git a/src/components/profile/TaggAvatar.tsx b/src/components/profile/TaggAvatar.tsx index 304b9e3a..ea0bdb65 100644 --- a/src/components/profile/TaggAvatar.tsx +++ b/src/components/profile/TaggAvatar.tsx @@ -1,12 +1,9 @@ -import React, {useState, useEffect} from 'react'; -import {StyleSheet, TouchableOpacity} from 'react-native'; +import React from 'react'; +import {StyleSheet} from 'react-native'; +import {useSelector} from 'react-redux'; import {RootState} from '../../store/rootreducer'; import {ScreenType} from '../../types'; import {Avatar} from '../common'; -import {useDispatch, useSelector} from 'react-redux'; -import {loadUserData, resetHeaderAndProfileImage} from '../../store/actions'; -import PurplePlus from '../../assets/icons/purple-plus.svg'; -import {patchProfile, validateImageLink} from '../../utils'; const PROFILE_DIM = 100; @@ -23,59 +20,8 @@ const TaggAvatar: React.FC = ({ const {avatar} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, ); - const dispatch = useDispatch(); - const [needsUpdate, setNeedsUpdate] = useState(false); - const [loading, setLoading] = useState(false); - const [validImage, setValidImage] = useState(true); - const {user} = useSelector((state: RootState) => - userXId ? state.userX[screenType][userXId] : state.user, - ); - - useEffect(() => { - checkAvatar(avatar); - }, []); - - useEffect(() => { - if (needsUpdate) { - const userId = user.userId; - const username = user.username; - dispatch(resetHeaderAndProfileImage()); - dispatch(loadUserData({userId, username})); - } - }, [dispatch, needsUpdate]); - const handleNewImage = async () => { - setLoading(true); - const result = await patchProfile('profile', user.userId); - if (result) { - setNeedsUpdate(true); - } else { - setLoading(false); - } - }; - - const checkAvatar = async (url: string | undefined) => { - const valid = await validateImageLink(url); - if (valid !== validImage) { - setValidImage(valid); - } - }; - - if (!validImage && userXId === undefined && !loading) { - return ( - <> - - handleNewImage()}> - - - - ); - } else { - return ; - } + return ; }; const styles = StyleSheet.create({ @@ -84,11 +30,6 @@ const styles = StyleSheet.create({ width: PROFILE_DIM, borderRadius: PROFILE_DIM / 2, }, - plus: { - position: 'absolute', - bottom: 35, - right: 0, - }, }); export default TaggAvatar; diff --git a/src/utils/common.ts b/src/utils/common.ts index 95e77f64..ce4ab7d1 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -180,20 +180,3 @@ const _crestIcon = (university: UniversityType) => { return require('../assets/images/bwbadges.png'); } }; - -export const validateImageLink = async (url: string | undefined) => { - if (!url) { - return false; - } - return fetch(url) - .then((res) => { - if (res.status === 200) { - return true; - } else { - return false; - } - }) - .catch((_) => { - return false; - }); -}; diff --git a/src/utils/users.ts b/src/utils/users.ts index 430c843f..334cb3c0 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -1,4 +1,3 @@ -import {Alert} from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; import {INTEGRATED_SOCIAL_LIST} from '../constants'; import {isUserBlocked, loadSocialPosts, removeBadgesService} from '../services'; @@ -25,8 +24,6 @@ import { UserType, UniversityBadge, } from './../types/types'; -import ImagePicker from 'react-native-image-crop-picker'; -import {patchEditProfile} from '../services'; const loadData = async (dispatch: AppDispatch, user: UserType) => { await Promise.all([ @@ -243,82 +240,3 @@ export const navigateToProfile = async ( screenType, }); }; - -export const patchProfile = async ( - title: 'profile' | 'header', - userId: string, -) => { - let imageSettings = {}; - let screenTitle: string; - let requestTitle: string; - let fileName: string; - switch (title) { - case 'header': - screenTitle = 'Select Header Picture'; - requestTitle = 'largeProfilePicture'; - fileName = 'large_profile_pic.jpg'; - imageSettings = { - smartAlbums: [ - 'Favorites', - 'RecentlyAdded', - 'SelfPortraits', - 'Screenshots', - 'UserLibrary', - ], - width: 580, - height: 580, - cropping: true, - cropperToolbarTitle: screenTitle, - mediaType: 'photo', - }; - break; - case 'profile': - screenTitle = 'Select Profile Picture'; - requestTitle = 'smallProfilePicture'; - fileName = 'small_profile_pic.jpg'; - imageSettings = { - smartAlbums: [ - 'Favorites', - 'RecentlyAdded', - 'SelfPortraits', - 'Screenshots', - 'UserLibrary', - ], - width: 580, - height: 580, - cropping: true, - cropperToolbarTitle: screenTitle, - mediaType: 'photo', - cropperCircleOverlay: true, - }; - break; - default: - screenTitle = ''; - requestTitle = ''; - fileName = ''; - } - - return await ImagePicker.openPicker(imageSettings) - .then((picture) => { - if ('path' in picture) { - const request = new FormData(); - request.append(requestTitle, { - uri: picture.path, - name: fileName, - type: 'image/jpg', - }); - - return patchEditProfile(request, userId) - .then((_) => { - return true; - }) - .catch((error) => { - Alert.alert(error); - return false; - }); - } - }) - .catch((_) => { - return false; - }); -}; -- cgit v1.2.3-70-g09d2