From d667654caf1aa4e5f4814fa927e835f13efc0650 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 22 Jan 2021 16:30:46 -0500 Subject: changed constant name --- src/screens/search/SearchScreen.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/screens') diff --git a/src/screens/search/SearchScreen.tsx b/src/screens/search/SearchScreen.tsx index 9f98b4d7..f231cb78 100644 --- a/src/screens/search/SearchScreen.tsx +++ b/src/screens/search/SearchScreen.tsx @@ -20,7 +20,7 @@ import { SearchResultsBackground, TabsGradient, } from '../../components'; -import {SEARCH_ENDPOINT, TAGG_TEXT_LIGHT_BLUE} from '../../constants'; +import {SEARCH_ENDPOINT, TAGG_LIGHT_BLUE} from '../../constants'; import {loadRecentlySearched, resetScreenType} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {ProfilePreviewType, ScreenType, UserType} from '../../types'; @@ -213,7 +213,7 @@ const styles = StyleSheet.create({ clear: { fontSize: 17, fontWeight: 'bold', - color: TAGG_TEXT_LIGHT_BLUE, + color: TAGG_LIGHT_BLUE, }, image: { width: SCREEN_WIDTH, -- cgit v1.2.3-70-g09d2 From 5f2159489e75a05dbe6bede792cb8a97971b824a Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 22 Jan 2021 16:31:35 -0500 Subject: finished styling the input box --- src/assets/icons/up_arrow.svg | 1 + src/components/comments/AddComment.tsx | 153 +++++++++++++++------------ src/screens/profile/MomentCommentsScreen.tsx | 46 ++++---- src/services/MomentServices.ts | 7 +- 4 files changed, 114 insertions(+), 93 deletions(-) create mode 100644 src/assets/icons/up_arrow.svg (limited to 'src/screens') diff --git a/src/assets/icons/up_arrow.svg b/src/assets/icons/up_arrow.svg new file mode 100644 index 00000000..fc92b551 --- /dev/null +++ b/src/assets/icons/up_arrow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/comments/AddComment.tsx b/src/components/comments/AddComment.tsx index c6c816b9..24b3473c 100644 --- a/src/components/comments/AddComment.tsx +++ b/src/components/comments/AddComment.tsx @@ -1,16 +1,17 @@ -import * as React from 'react'; +import React, {useEffect} from 'react'; import { Image, + Keyboard, KeyboardAvoidingView, Platform, StyleSheet, View, } from 'react-native'; -import AsyncStorage from '@react-native-community/async-storage'; -import {TaggBigInput} from '../onboarding'; +import {TextInput, TouchableOpacity} from 'react-native-gesture-handler'; +import {useSelector} from 'react-redux'; +import UpArrowIcon from '../../assets/icons/up_arrow.svg'; +import {TAGG_LIGHT_BLUE} from '../../constants'; import {postMomentComment} from '../../services'; -import {logout} from '../../store/actions'; -import {useSelector, useDispatch} from 'react-redux'; import {RootState} from '../../store/rootreducer'; import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; @@ -30,98 +31,114 @@ const AddComment: React.FC = ({ moment_id, }) => { const [comment, setComment] = React.useState(''); + const [keyboardVisible, setKeyboardVisible] = React.useState(false); - const dispatch = useDispatch(); const { avatar, user: {userId}, } = useSelector((state: RootState) => state.user); - const handleCommentUpdate = (comment: string) => { - setComment(comment); - }; - const postComment = async () => { - try { - const token = await AsyncStorage.getItem('token'); - if (!token) { - dispatch(logout()); - return; - } - const postedComment = await postMomentComment( - userId, - comment, - moment_id, - token, - ); - - if (postedComment) { - //Set the current comment to en empty string if the comment was posted successfully. - handleCommentUpdate(''); + const postedComment = await postMomentComment( + userId, + comment.trim(), + moment_id, + ); - //Indicate the MomentCommentsScreen that it needs to download the new comments again - setNewCommentsAvailable(true); - } - } catch (err) { - console.log('Error while posting comment!'); + if (postedComment) { + setComment(''); + setNewCommentsAvailable(true); } }; + useEffect(() => { + const showKeyboard = () => setKeyboardVisible(true); + Keyboard.addListener('keyboardWillShow', showKeyboard); + return () => Keyboard.removeListener('keyboardWillShow', showKeyboard); + }, []); + + useEffect(() => { + const hideKeyboard = () => setKeyboardVisible(false); + Keyboard.addListener('keyboardWillHide', hideKeyboard); + return () => Keyboard.removeListener('keyboardWillHide', hideKeyboard); + }, []); + return ( - - - - + keyboardVerticalOffset={SCREEN_HEIGHT * 0.1}> + + + + + + + + + + ); }; const styles = StyleSheet.create({ container: { - flexDirection: 'row', - justifyContent: 'flex-start', + backgroundColor: '#f7f7f7', + alignItems: 'center', width: SCREEN_WIDTH, - marginTop: '5%', }, textContainer: { - width: '100%', - alignItems: 'flex-start', - marginVertical: 11, + width: '95%', + flexDirection: 'row', + backgroundColor: '#e8e8e8', + alignItems: 'center', + justifyContent: 'space-between', + margin: '3%', + borderRadius: 25, }, text: { - backgroundColor: 'white', - width: '70%', - paddingLeft: '2%', - paddingRight: '2%', - paddingBottom: '1%', - paddingTop: '1%', - height: 60, + flex: 1, + padding: '1%', + marginHorizontal: '1%', }, avatar: { - height: 40, - width: 40, + height: 35, + width: 35, borderRadius: 30, marginRight: 10, - marginLeft: 20, + marginLeft: '3%', + marginVertical: '2%', + alignSelf: 'flex-end', + }, + submitButton: { + height: 35, + width: 35, + backgroundColor: TAGG_LIGHT_BLUE, + borderRadius: 999, + justifyContent: 'center', + alignItems: 'center', + marginRight: '3%', + marginVertical: '2%', + alignSelf: 'flex-end', }, }); diff --git a/src/screens/profile/MomentCommentsScreen.tsx b/src/screens/profile/MomentCommentsScreen.tsx index b2611b62..6434477e 100644 --- a/src/screens/profile/MomentCommentsScreen.tsx +++ b/src/screens/profile/MomentCommentsScreen.tsx @@ -1,19 +1,21 @@ -import * as React from 'react'; import {RouteProp, useNavigation} from '@react-navigation/native'; -import {ProfileStackParams} from '../../routes/main'; +import React, {useEffect, useRef} from 'react'; +import { + ScrollView, + StyleSheet, + Text, + TouchableOpacity, + View, +} from 'react-native'; +import {SafeAreaView} from 'react-native-safe-area-context'; +import {useDispatch} from 'react-redux'; +import {getMomentComments} from '../..//services'; +import BackIcon from '../../assets/icons/back-arrow.svg'; import {CommentTile, TabsGradient} from '../../components'; +import {AddComment} from '../../components/'; +import {ProfileStackParams} from '../../routes/main'; import {CommentType} from '../../types'; -import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'; import {SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils/screenDimensions'; -import {AddComment} from '../../components/'; -import {useEffect} from 'react'; -import AsyncStorage from '@react-native-community/async-storage'; -import {getMomentComments} from '../..//services'; -import {useDispatch} from 'react-redux'; -import {logout} from '../../store/actions'; -import {SafeAreaView} from 'react-native-safe-area-context'; -import Animated from 'react-native-reanimated'; -import BackIcon from '../../assets/icons/back-arrow.svg'; /** * Comments Screen for an image uploaded @@ -36,19 +38,20 @@ const MomentCommentsScreen: React.FC = ({route}) => { const [commentsList, setCommentsList] = React.useState([]); const [newCommentsAvailable, setNewCommentsAvailable] = React.useState(true); const dispatch = useDispatch(); + const ref = useRef(null); useEffect(() => { const loadComments = async () => { - const token = await AsyncStorage.getItem('token'); - if (!token) { - dispatch(logout()); - return; - } - getMomentComments(moment_id, setCommentsList, token); + getMomentComments(moment_id, setCommentsList); setNewCommentsAvailable(false); }; if (newCommentsAvailable) { loadComments(); + setTimeout(() => { + ref.current?.scrollToEnd({ + animated: true, + }); + }, 500); } }, [dispatch, moment_id, newCommentsAvailable]); @@ -68,7 +71,8 @@ const MomentCommentsScreen: React.FC = ({route}) => { - {commentsList && @@ -79,7 +83,7 @@ const MomentCommentsScreen: React.FC = ({route}) => { screenType={screenType} /> ))} - + { try { + const token = await AsyncStorage.getItem('token'); const response = await fetch(COMMENTS_ENDPOINT + '?moment_id=' + momentId, { method: 'GET', headers: { @@ -35,14 +35,13 @@ export const getMomentComments = async ( } }; -//Post a comment on a moment export const postMomentComment = async ( commenter: string, comment: string, momentId: string, - token: string, ) => { try { + const token = await AsyncStorage.getItem('token'); const request = new FormData(); request.append('moment_id', momentId); request.append('commenter', commenter); @@ -60,7 +59,7 @@ export const postMomentComment = async ( return await response.json(); } catch (error) { Alert.alert(ERROR_FAILED_TO_COMMENT); - return {}; + return undefined; } }; -- cgit v1.2.3-70-g09d2 From 3ea488de07376f2a3339d92a9b316acd38446883 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Fri, 22 Jan 2021 15:20:55 -0800 Subject: Done --- src/screens/profile/EditProfile.tsx | 41 +++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/screens') diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index 3b3fa36e..3bf5c23c 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -29,9 +29,10 @@ import { websiteRegex, bioRegex, genderRegex, + CLASS_YEAR_LIST, } from '../../constants'; import AsyncStorage from '@react-native-community/async-storage'; -import {ProfileStackParams} from '../../routes'; +import {MainStackParams} from '../../routes'; import Animated from 'react-native-reanimated'; import {HeaderHeight, SCREEN_HEIGHT} from '../../utils'; import {RootState} from '../../store/rootReducer'; @@ -47,12 +48,12 @@ import { import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator'; type EditProfileNavigationProp = StackNavigationProp< - ProfileStackParams, + MainStackParams, 'EditProfile' >; interface EditProfileProps { - route: RouteProp; + route: RouteProp; navigation: EditProfileNavigationProp; } @@ -65,7 +66,7 @@ const EditProfile: React.FC = ({route, navigation}) => { const y: Animated.Value = Animated.useValue(0); const {userId, username} = route.params; const { - profile: {website, biography, gender, snapchat, tiktok}, + profile: {website, biography, gender, snapchat, tiktok, university_class}, avatar, cover, } = useSelector((state: RootState) => state.user); @@ -99,6 +100,13 @@ const EditProfile: React.FC = ({route, navigation}) => { isValidSnapchat: true, isValidTiktok: true, attemptedSubmit: false, + classYear: university_class, + }); + + var classYearList: Array = []; + + CLASS_YEAR_LIST.map((value) => { + classYearList.push({label: value, value: value}); }); /** @@ -254,6 +262,14 @@ const EditProfile: React.FC = ({route, navigation}) => { }); }; + const handleClassYearUpdate = (value: string) => { + const classYear = Number.parseInt(value); + setForm({ + ...form, + classYear, + }); + }; + const handleSubmit = useCallback(async () => { if (!form.largePic) { Alert.alert(ERROR_UPLOAD_LARGE_PROFILE_PIC); @@ -335,6 +351,10 @@ const EditProfile: React.FC = ({route, navigation}) => { invalidFields = true; } + if (form.classYear !== university_class) { + request.append('university_class', form.classYear); + } + if (invalidFields) { return; } @@ -487,6 +507,19 @@ const EditProfile: React.FC = ({route, navigation}) => { value={form.customGenderText} /> )} + + + handleClassYearUpdate(value) + } + items={classYearList} + placeholder={{ + label: 'Class Year', + value: null, + color: '#ddd', + }} + /> {snapchat !== '' && ( -- cgit v1.2.3-70-g09d2 From 5b6e94378dce751da5be2afa5ab6b2847eb43992 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Fri, 22 Jan 2021 15:37:34 -0800 Subject: Done --- src/screens/profile/EditProfile.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/screens') diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index 3bf5c23c..c5cf4a59 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -264,6 +264,7 @@ const EditProfile: React.FC = ({route, navigation}) => { const handleClassYearUpdate = (value: string) => { const classYear = Number.parseInt(value); + console.log(classYear); setForm({ ...form, classYear, @@ -352,7 +353,13 @@ const EditProfile: React.FC = ({route, navigation}) => { } if (form.classYear !== university_class) { - request.append('university_class', form.classYear); + console.log(form.classYear); + if (!form.classYear) { + invalidFields = true; + Alert.alert('Please select a valid class year'); + } else { + request.append('university_class', form.classYear); + } } if (invalidFields) { -- cgit v1.2.3-70-g09d2 From d016131c2d1fd66bf7a91be78901b17dc7634174 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Fri, 22 Jan 2021 15:39:29 -0800 Subject: fix --- src/screens/profile/EditProfile.tsx | 1 - 1 file changed, 1 deletion(-) (limited to 'src/screens') diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index c5cf4a59..809312a9 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -264,7 +264,6 @@ const EditProfile: React.FC = ({route, navigation}) => { const handleClassYearUpdate = (value: string) => { const classYear = Number.parseInt(value); - console.log(classYear); setForm({ ...form, classYear, -- cgit v1.2.3-70-g09d2 From 14f99e8bdd5d911355122615b08bbbcbd2562df9 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Fri, 22 Jan 2021 15:39:52 -0800 Subject: fix --- src/screens/profile/EditProfile.tsx | 1 - 1 file changed, 1 deletion(-) (limited to 'src/screens') diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index 809312a9..36de2bfa 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -352,7 +352,6 @@ const EditProfile: React.FC = ({route, navigation}) => { } if (form.classYear !== university_class) { - console.log(form.classYear); if (!form.classYear) { invalidFields = true; Alert.alert('Please select a valid class year'); -- cgit v1.2.3-70-g09d2