From adc3712b1144bbf62d62ed02b015c8e8c489bffb Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 19 May 2021 16:44:40 -0700 Subject: Add common function to get suggested list pf users --- src/constants/index.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'src/constants') diff --git a/src/constants/index.ts b/src/constants/index.ts index a9cfe947..96ed3fb0 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,3 +1,4 @@ export * from './api'; export * from './constants'; export * from './regex'; +export * from './badges'; -- cgit v1.2.3-70-g09d2 From 5b57d5c82a0d8b30a58fd66acd79f083e3019cfc Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 21 May 2021 14:07:19 -0700 Subject: Add colors through types --- src/components/common/TaggRadioButton.tsx | 5 +++-- src/constants/constants.ts | 1 + src/screens/chat/ChatScreen.tsx | 3 ++- src/screens/onboarding/BasicInfoOnboarding.tsx | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/constants') diff --git a/src/components/common/TaggRadioButton.tsx b/src/components/common/TaggRadioButton.tsx index fc4008e5..25d00ec9 100644 --- a/src/components/common/TaggRadioButton.tsx +++ b/src/components/common/TaggRadioButton.tsx @@ -1,5 +1,6 @@ import React from 'react'; import {StyleSheet, TouchableOpacity, View} from 'react-native'; +import {RADIO_BUTTON_GREY, TAGG_LIGHT_BLUE_2} from '../../constants/constants'; interface TaggRadioButtonProps { pressed: boolean; @@ -10,11 +11,11 @@ const TaggRadioButton: React.FC = ({ onPress, }) => { const activeOuterStyle = { - borderColor: pressed ? '#6EE7E7' : '#BEBEBE', + borderColor: pressed ? TAGG_LIGHT_BLUE_2 : RADIO_BUTTON_GREY, }; const activeInnerStyle = { - backgroundColor: pressed ? '#6EE7E7' : 'white', + backgroundColor: pressed ? TAGG_LIGHT_BLUE_2 : 'white', }; return ( = ({navigation}) => { const insets = useSafeAreaInsets(); const chatTheme: DeepPartial = { colors: { - accent_blue: '#6EE7E7', + accent_blue: TAGG_LIGHT_BLUE_2, }, messageList: { container: { diff --git a/src/screens/onboarding/BasicInfoOnboarding.tsx b/src/screens/onboarding/BasicInfoOnboarding.tsx index 3058a04e..e5e6f59b 100644 --- a/src/screens/onboarding/BasicInfoOnboarding.tsx +++ b/src/screens/onboarding/BasicInfoOnboarding.tsx @@ -27,6 +27,7 @@ import { nameRegex, passwordRegex, phoneRegex, + TAGG_LIGHT_BLUE_2, usernameRegex, } from '../../constants'; import { @@ -70,9 +71,8 @@ const BasicInfoOnboarding: React.FC = ({route}) => { const [invalidWithError, setInvalidWithError] = useState( 'Please enter a valid ', ); - const [autoCapitalize, setAutoCap] = useState< - 'none' | 'sentences' | 'words' | 'characters' | undefined - >('none'); + const [autoCapitalize, setAutoCap] = + useState<'none' | 'sentences' | 'words' | 'characters' | undefined>('none'); const [fadeValue, setFadeValue] = useState>( new Animated.Value(0), ); @@ -565,7 +565,7 @@ const styles = StyleSheet.create({ alignItems: 'center', }, arrow: { - color: '#6EE7E7', + color: TAGG_LIGHT_BLUE_2, }, showPassContainer: { marginVertical: '1%', -- cgit v1.2.3-70-g09d2 From 923e1084e18ce5636cf4448096907bc95f1018ff Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 21 May 2021 21:23:55 -0400 Subject: Add api calls --- src/constants/api.ts | 1 + src/screens/profile/CaptionScreen.tsx | 58 +++++++++++++++++++++++++---------- src/services/MomentService.ts | 47 ++++++++++++++++++++++------ 3 files changed, 80 insertions(+), 26 deletions(-) (limited to 'src/constants') diff --git a/src/constants/api.ts b/src/constants/api.ts index d52fc203..f02ee407 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -32,6 +32,7 @@ export const SEARCH_ENDPOINT_MESSAGES: string = API_URL + 'search/messages/'; export const SEARCH_ENDPOINT_SUGGESTED: string = API_URL + 'search/suggested/'; export const MOMENTS_ENDPOINT: string = API_URL + 'moments/'; export const MOMENT_TAGS_ENDPOINT: string = API_URL + 'moments/tags/'; +export const MOMENTTAG_ENDPOINT: string = API_URL + 'moment-tag/'; export const MOMENT_THUMBNAIL_ENDPOINT: string = API_URL + 'moment-thumbnail/'; export const VERIFY_INVITATION_CODE_ENDPOUNT: string = API_URL + 'verify-code/'; export const COMMENTS_ENDPOINT: string = API_URL + 'comments/'; diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 2093a1f9..2fe30645 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -23,7 +23,7 @@ import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator'; import {TAGG_LIGHT_BLUE_2} from '../../constants'; import {ERROR_UPLOAD, SUCCESS_PIC_UPLOAD} from '../../constants/strings'; import {MainStackParams} from '../../routes'; -import {postMoment} from '../../services'; +import {postMoment, postMomentTags} from '../../services'; import { loadUserMoments, updateProfileCompletionStage, @@ -85,27 +85,51 @@ const CaptionScreen: React.FC = ({route, navigation}) => { }; const handleShare = async () => { + const handleFailed = () => { + setLoading(false); + setTimeout(() => { + Alert.alert(ERROR_UPLOAD); + }, 500); + }; + const handleSuccess = () => { + setLoading(false); + navigateToProfile(); + setTimeout(() => { + Alert.alert(SUCCESS_PIC_UPLOAD); + }, 500); + }; setLoading(true); if (!image.filename) { return; } - postMoment(image.filename, image.path, caption, title, userId).then( - (data) => { - setLoading(false); - if (data) { - dispatch(loadUserMoments(userId)); - dispatch(updateProfileCompletionStage(data)); - navigateToProfile(); - setTimeout(() => { - Alert.alert(SUCCESS_PIC_UPLOAD); - }, 500); - } else { - setTimeout(() => { - Alert.alert(ERROR_UPLOAD); - }, 500); - } - }, + const momentResponse = await postMoment( + image.filename, + image.path, + caption, + title, + userId, + ); + if (!momentResponse) { + handleFailed(); + return; + } + const momentTagResponse = await postMomentTags( + momentResponse.moment_id, + taggedUsers.map((u, index) => ({ + x: index * 50 - 150, + y: index * 50 - 150, + user_id: u.id, + })), + ); + if (!momentTagResponse) { + handleFailed(); + return; + } + dispatch(loadUserMoments(userId)); + dispatch( + updateProfileCompletionStage(momentResponse.profile_completion_stage), ); + handleSuccess(); }; return ( diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index a26a1abb..46b55066 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -2,24 +2,19 @@ import AsyncStorage from '@react-native-community/async-storage'; import RNFetchBlob from 'rn-fetch-blob'; import { MOMENTS_ENDPOINT, + MOMENTTAG_ENDPOINT, MOMENT_TAGS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT, } from '../constants'; import {MomentTagType, MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; -export const postMoment: ( +export const postMoment = async ( fileName: string, uri: string, caption: string, category: string, userId: string, -) => Promise = async ( - fileName, - uri, - caption, - category, - userId, ) => { try { const request = new FormData(); @@ -45,9 +40,13 @@ export const postMoment: ( body: request, }); let statusCode = response.status; - let data = await response.json(); + let data: { + moments: any; + moment_id: string; + profile_completion_stage: number; + } = await response.json(); if (statusCode === 200 && checkImageUploadStatus(data.moments)) { - return data.profile_completion_stage; + return data; } } catch (err) { console.log(err); @@ -142,3 +141,33 @@ export const loadMomentTags = async (moment_id: string) => { return []; } }; + +export const postMomentTags = async ( + moment_id: string, + tags: { + x: number; + y: number; + user_id: string; + }[], +) => { + try { + const token = await AsyncStorage.getItem('token'); + const form = new FormData(); + form.append('moment_id', moment_id); + form.append('tags', JSON.stringify(tags)); + const response = await fetch( + MOMENTTAG_ENDPOINT + `?moment_id=${moment_id}`, + { + method: 'POST', + headers: { + Authorization: 'Token ' + token, + }, + body: form, + }, + ); + return response.status === 201 || response.status === 200; + } catch (error) { + console.error(error); + return false; + } +}; -- cgit v1.2.3-70-g09d2