From 080e76350c2570eeb096fad40fe95f1b766b4539 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 11 Jan 2021 16:11:11 -0500 Subject: created strings.ts and linting --- src/services/BlockUserService.ts | 23 ++++-------- src/services/MomentCategoryService.ts | 7 ++-- src/services/MomentServices.ts | 17 +++------ src/services/ReportingService.ts | 10 ++++-- src/services/SocialLinkingService.ts | 12 +++---- src/services/UserFriendsServices.ts | 11 ++---- src/services/UserProfileService.ts | 68 ++++++++++++++--------------------- 7 files changed, 58 insertions(+), 90 deletions(-) (limited to 'src/services') diff --git a/src/services/BlockUserService.ts b/src/services/BlockUserService.ts index 21e259b6..12ea0184 100644 --- a/src/services/BlockUserService.ts +++ b/src/services/BlockUserService.ts @@ -2,6 +2,7 @@ import {Alert} from 'react-native'; import {BLOCK_USER_ENDPOINT} from '../constants'; +import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings'; export const loadBlockedUsers = async (userId: string, token: string) => { try { @@ -44,18 +45,12 @@ export const blockOrUnblockUser = async ( return true; } else { console.log(await response.json()); - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } } catch (error) { console.log(error); - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } }; @@ -77,18 +72,12 @@ export const isUserBlocked = async ( if (Math.floor(response.status / 100) === 2) { const data = await response.json(); - return data['is_blocked']; + return data.is_blocked; } else { console.log(await response.json()); - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } } catch (error) { - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } }; diff --git a/src/services/MomentCategoryService.ts b/src/services/MomentCategoryService.ts index 57e64830..bb2c5542 100644 --- a/src/services/MomentCategoryService.ts +++ b/src/services/MomentCategoryService.ts @@ -1,5 +1,6 @@ import {Alert} from 'react-native'; import {MOMENT_CATEGORY_ENDPOINT} from '../constants'; +import {ERROR_CATEGORY_CREATION} from '../constants/strings'; export const loadMomentCategories: ( userId: string, @@ -44,10 +45,10 @@ export const postMomentCategories: ( const status = response.status; const data = await response.json(); if (status === 200) { - return data['profile_completion_stage']; + return data.profile_completion_stage; } else { - Alert.alert('There was a problem updating categories!'); - console.log('Unable to update categories'); + Alert.alert(ERROR_CATEGORY_CREATION); + console.log('Could not post categories!'); } } catch (err) { console.log(err); diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 91ecf712..76f353ce 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,6 +1,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; +import {ERROR_FAILED_TO_COMMENT} from '../constants/strings'; import {MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; @@ -48,20 +49,12 @@ export const postMomentComment = async ( }, body: request, }); - const status = response.status; - if (status === 200) { - const response_data = await response.json(); - return response_data; - } else { - Alert.alert('Something went wrong! 😭', 'Not able to post a comment'); - return {}; + if (response.status !== 200) { + throw 'server error'; } + return await response.json(); } catch (error) { - Alert.alert( - 'Something went wrong! 😭', - 'Not able to post a comment', - error, - ); + Alert.alert(ERROR_FAILED_TO_COMMENT); return {}; } }; diff --git a/src/services/ReportingService.ts b/src/services/ReportingService.ts index 1563d086..8c0a4bfb 100644 --- a/src/services/ReportingService.ts +++ b/src/services/ReportingService.ts @@ -3,6 +3,10 @@ import {REPORT_ISSUE_ENDPOINT} from '../constants'; import {Alert} from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; +import { + ERROR_SOMETHING_WENT_WRONG, + MARKED_AS_MSG, +} from '../constants/strings'; export const sendReport = async ( moment_id: string, @@ -25,15 +29,15 @@ export const sendReport = async ( let statusCode = response.status; if (statusCode === 200) { - Alert.alert('Marked as ' + message.split(' ')[2]); + Alert.alert(MARKED_AS_MSG(message.split(' ')[2])); } else { - Alert.alert('Something went wrong!', 'Please try again.'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); } if (callback) { callback(); } } catch (error) { - Alert.alert('Something went wrong!', 'Please try again.'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); console.log( 'Something went wrong! 😭', 'Unable able to retrieve data', diff --git a/src/services/SocialLinkingService.ts b/src/services/SocialLinkingService.ts index 4a01ee50..1423c8c0 100644 --- a/src/services/SocialLinkingService.ts +++ b/src/services/SocialLinkingService.ts @@ -12,6 +12,8 @@ import { LINK_TWITTER_ENDPOINT, LINK_TWITTER_OAUTH, } from '../constants'; +import {COMING_SOON_MSG, ERROR_LINK, SUCCESS_LINK} from '../constants/strings'; +import {CategorySelection} from '../screens'; // A list of endpoint strings for all the integrated socials export const integratedEndpoints: {[social: string]: [string, string]} = { @@ -124,7 +126,7 @@ export const handlePressForAuthBrowser: ( ) => Promise = async (socialType: string) => { try { if (!(socialType in integratedEndpoints)) { - Alert.alert('Coming soon!'); + Alert.alert(COMING_SOON_MSG); return false; } @@ -168,7 +170,7 @@ export const handlePressForAuthBrowser: ( if (!success) { throw 'Unable to register with backend'; } - Alert.alert(`Successfully linked ${socialType} πŸŽ‰`); + Alert.alert(SUCCESS_LINK(socialType)); return true; } else if (response.type === 'cancel') { return false; @@ -178,14 +180,12 @@ export const handlePressForAuthBrowser: ( }) .catch((error) => { console.log(error); - Alert.alert( - `Something went wrong, we can't link with ${socialType} πŸ˜”`, - ); + Alert.alert(ERROR_LINK(socialType)); return false; }); } catch (error) { console.log(error); - Alert.alert(`Something went wrong, we can't link with ${socialType} πŸ˜”`); + Alert.alert(ERROR_LINK(socialType)); } return false; }; diff --git a/src/services/UserFriendsServices.ts b/src/services/UserFriendsServices.ts index 0b138fc3..f7a39abf 100644 --- a/src/services/UserFriendsServices.ts +++ b/src/services/UserFriendsServices.ts @@ -2,6 +2,7 @@ import {Alert} from 'react-native'; import {FRIENDS_ENDPOINT} from '../constants'; +import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings'; export const loadFriends = async (userId: string, token: string) => { try { @@ -46,18 +47,12 @@ export const friendOrUnfriendUser = async ( return true; } else { console.log(await response.json()); - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } } catch (error) { console.log(error); - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); return false; } }; diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 793ee44d..830fbbb9 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -17,6 +17,17 @@ import { SEND_OTP_ENDPOINT, PROFILE_PHOTO_THUMBNAIL_ENDPOINT, } from '../constants'; +import { + ERROR_DOUBLE_CHECK_CONNECTION, + ERROR_DUP_OLD_PWD, + ERROR_INVALID_PWD_CODE, + ERROR_PWD_ACCOUNT, + ERROR_SOMETHING_WENT_WRONG, + ERROR_SOMETHING_WENT_WRONG_REFRESH, + ERROR_VERIFICATION_FAILED, + SUCCESS_PWD_RESET, + SUCCESS_VERIFICATION_CODE_SENT, +} from '../constants/strings'; export const loadProfileInfo = async (token: string, userId: string) => { try { @@ -56,10 +67,7 @@ export const loadProfileInfo = async (token: string, userId: string) => { throw 'Unable to load profile data'; } } catch (error) { - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } }; @@ -174,10 +182,7 @@ export const handlePasswordResetRequest = async (value: string) => { `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`, ); } else { - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } console.log(response); @@ -185,7 +190,7 @@ export const handlePasswordResetRequest = async (value: string) => { } } catch (error) { console.log(error); - Alert.alert('Something went wrong! 😭', 'Looks like our servers are down'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } }; @@ -211,16 +216,11 @@ export const handlePasswordCodeVerification = async ( return true; } else { if (status == 404) { - Alert.alert( - `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`, - ); + Alert.alert(ERROR_PWD_ACCOUNT(TAGG_CUSTOMER_SUPPORT)); } else if (status === 401) { - Alert.alert('Looks like you have entered the wrong code'); + Alert.alert(ERROR_INVALID_PWD_CODE); } else { - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); } console.log(response); @@ -228,7 +228,7 @@ export const handlePasswordCodeVerification = async ( } } catch (error) { console.log(error); - Alert.alert('Something went wrong! 😭', 'Looks like our servers are down'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } }; @@ -248,27 +248,22 @@ export const handlePasswordReset = async (value: string, password: string) => { }); const status = response.status; if (status === 200) { - Alert.alert('Your password was reset successfully'); + Alert.alert(SUCCESS_PWD_RESET); return true; } else { if (status == 404) { - Alert.alert( - `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`, - ); + Alert.alert(ERROR_PWD_ACCOUNT(TAGG_CUSTOMER_SUPPORT)); } else if (status == 406) { - Alert.alert('You may not use an already used password'); + Alert.alert(ERROR_DUP_OLD_PWD); } else { - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } console.log(response); return false; } } catch (error) { console.log(error); - Alert.alert('Something went wrong! 😭', 'Looks like our servers are down'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } }; @@ -292,17 +287,11 @@ export const verifyOtp = async (phone: string, otp: string) => { 'Try again. Tap the resend code button if you need a new code.', ); } else { - Alert.alert( - 'Something went wrong! 😭', - "Would you believe me if I told you that I don't know what happened?", - ); + Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } } } catch (error) { - Alert.alert( - 'Verifiation failed πŸ˜“', - 'Please double-check your network connection and retry.', - ); + Alert.alert(ERROR_VERIFICATION_FAILED, ERROR_DOUBLE_CHECK_CONNECTION); return { name: 'Verification error', description: error, @@ -322,13 +311,10 @@ export const sendOtp = async (phone: string) => { let status = response.status; if (status === 200) { - Alert.alert( - 'New verification code sent!', - 'Check your phone messages for your code.', - ); + Alert.alert(SUCCESS_VERIFICATION_CODE_SENT); return true; } else { - Alert.alert('Something went wrong!'); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); return false; } } catch (error) { -- cgit v1.2.3-70-g09d2 From f4ff28b1094c65d0bb3dcda4045ab64cab108cd0 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 13 Jan 2021 16:16:18 -0500 Subject: fixed merge --- src/services/MomentServices.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/services') diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 76f353ce..217b5857 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,7 +1,11 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; -import {ERROR_FAILED_TO_COMMENT} from '../constants/strings'; +import { + ERROR_FAILED_TO_COMMENT, + ERROR_UPLOAD, + SUCCESS_PIC_UPLOAD, +} from '../constants/strings'; import {MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; @@ -129,15 +133,15 @@ export const postMoment: ( }); let statusCode = response.status; let data = await response.json(); - if (statusCode === 200 && checkImageUploadStatus(data['moments'])) { - Alert.alert('The picture was uploaded successfully!'); - return data['profile_completion_stage']; + if (statusCode === 200 && checkImageUploadStatus(data.moments)) { + Alert.alert(SUCCESS_PIC_UPLOAD); + return data.profile_completion_stage; } else { - Alert.alert('An error occured while uploading. Please try again!'); + Alert.alert(ERROR_UPLOAD); } } catch (err) { console.log(err); - Alert.alert('An error occured during authenticaion. Please login again!'); + Alert.alert(ERROR_UPLOAD); } return undefined; }; -- cgit v1.2.3-70-g09d2 From cc52dabaaf529763e9c1c4683ba94ed55c5671a8 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 15 Jan 2021 14:35:06 -0500 Subject: updated some strings --- src/components/moments/Moment.tsx | 4 +- src/constants/strings.ts | 51 +++++++++++----------- .../onboarding/InvitationCodeVerification.tsx | 4 +- src/screens/onboarding/ProfileOnboarding.tsx | 4 +- src/services/UserProfileService.ts | 4 +- 5 files changed, 34 insertions(+), 33 deletions(-) (limited to 'src/services') diff --git a/src/components/moments/Moment.tsx b/src/components/moments/Moment.tsx index 56093d65..7905e8a9 100644 --- a/src/components/moments/Moment.tsx +++ b/src/components/moments/Moment.tsx @@ -12,7 +12,7 @@ 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_TEXT_LIGHT_BLUE} from '../../constants'; -import {ERROR_UPLOAD_MOMENT} from '../../constants/strings'; +import {ERROR_UPLOAD_MOMENT_SHORT} from '../../constants/strings'; import {SCREEN_WIDTH} from '../../utils'; import MomentTile from './MomentTile'; @@ -69,7 +69,7 @@ const Moment: React.FC = ({ }) .catch((err) => { if (err.code && err.code !== 'E_PICKER_CANCELLED') { - Alert.alert(ERROR_UPLOAD_MOMENT); + Alert.alert(ERROR_UPLOAD_MOMENT_SHORT); } }); }; diff --git a/src/constants/strings.ts b/src/constants/strings.ts index 3b9b6dad..b5344afd 100644 --- a/src/constants/strings.ts +++ b/src/constants/strings.ts @@ -1,46 +1,47 @@ /* eslint-disable */ // Below is the regex to convert this into a csv for the Google Sheet // export const (.*) = .*?(['|"|`])(.*)\2; +// replace with: $1\t$3 export const COMING_SOON_MSG = 'Creating more fun things for you, surprises coming soon πŸ˜‰'; export const ERROR_AUTHENTICATION = 'An error occurred during authentication. Please login again!'; -export const ERROR_CATEGORY_CREATION = 'There was a problem creating categories!'; -export const ERROR_CATEGORY_UPDATE = 'There was a problem updating categories!'; -export const ERROR_DELETE_CATEGORY = 'There was a problem while deleting category!'; -export const ERROR_DELETE_MOMENT = 'We were unable to delete that moment 😭 , please try again later!'; +export const ERROR_CATEGORY_CREATION = 'There was a problem creating your categories. Please refresh and try again.'; +export const ERROR_CATEGORY_UPDATE = 'There was a problem updating your categories. Please refresh and try again'; +export const ERROR_DELETE_CATEGORY = 'There was a problem while deleting category. Please try again'; +export const ERROR_DELETE_MOMENT = 'Unable to delete moment, please try again later!'; export const ERROR_DOUBLE_CHECK_CONNECTION = 'Please double-check your network connection and retry'; -export const ERROR_DUP_OLD_PWD = 'You may not use an already used password'; +export const ERROR_DUP_OLD_PWD = 'You may not use a previously used password'; export const ERROR_EMAIL_IN_USE = 'Email already in use, please try another one'; export const ERROR_FAILED_LOGIN_INFO = 'Login failed, please try re-entering your login information'; export const ERROR_FAILED_TO_COMMENT = 'Unable to post comment, refresh and try again!'; export const ERROR_INVALID_INVITATION_CODE = 'Invitation code invalid, try again or talk to the friend that sent it 😬'; export const ERROR_INVALID_LOGIN = 'Invalid login, Please login again'; -export const ERROR_INVALID_PWD_CODE = 'Looks like you have entered the wrong code'; -export const ERROR_INVALID_VERIFICATION_CODE = 'Invalid verification code, try again. πŸ€” Tap the resend code button to get a new one'; -export const ERROR_INVALID_VERIFICATION_CODE_FORMAT = 'Please enter a valid 6 digit code'; +export const ERROR_INVALID_PWD_CODE = 'Looks like you have entered the wrong code, please try again'; +export const ERROR_INVALID_VERIFICATION_CODE = 'Invalid verification code, try re-entering or tap the resend code button for a new code'; +export const ERROR_INVALID_VERIFICATION_CODE_FORMAT = 'Please enter the 6 digit code sent to your phone'; export const ERROR_INVLAID_CODE = 'The code entered is not valid!'; -export const ERROR_LINK = (str: string) => `Something went wrong, we can\'t link with ${str}, Please refresh and try again`; -export const ERROR_LOGIN = 'There was a problem logging you in, please refresh and try again '; -export const ERROR_LOGIN_FAILED = 'Login failed πŸ˜“'; -export const ERROR_NEXT_PAGE = 'There was a problem while loading the next page πŸ˜“, try again in a couple minutes. Were sorry for the inconvenience.'; -export const ERROR_PROFILE_CREATION = 'Profile creation failed πŸ˜“'; +export const ERROR_LINK = (str: string) => `Unable to link with ${str}, Please check your login and try again`; +export const ERROR_LOGIN = 'There was a problem logging you in, please refresh and try again'; +export const ERROR_LOGIN_FAILED = 'Login failed. Check your username and passoword, and try again'; +export const ERROR_NEXT_PAGE = 'There was a problem while loading the next page πŸ˜“, try again in a couple minutes'; +export const ERROR_PROFILE_CREATION_SHORT = 'Profile creation failed πŸ˜“'; export const ERROR_PWD_ACCOUNT = (str: string) => `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${str}`; export const ERROR_REGISTRATION = (str: string) => `Registration failed πŸ˜”, ${str}`; -export const ERROR_SELECT_CLASS_YEAR = 'Please select Class Year'; +export const ERROR_SELECT_CLASS_YEAR = 'Please select your Class Year'; export const ERROR_SERVER_DOWN = 'mhm, looks like our servers are down, please refresh and try again in a few mins'; -export const ERROR_SOMETHING_WENT_WRONG = "Something went wrong! We don't know what happened... Please give it another try"; +export const ERROR_SOMETHING_WENT_WRONG = "Oh dear, don’t worry someone will be held responsible for this error, In the meantime refresh the app"; export const ERROR_SOMETHING_WENT_WRONG_REFRESH = "Ha, looks like this one's on us, please refresh and try again"; export const ERROR_SOMETHING_WENT_WRONG_RELOAD = "You broke it, Just kidding! we don't know what happened... Please reload the app and try again"; -export const ERROR_UNABLE_TO_FIND_PROFILE = 'We were unable to find this profile πŸ˜”'; -export const ERROR_UNABLE_TO_VIEW_PROFILE = 'You cannot view this profile'; +export const ERROR_UNABLE_TO_FIND_PROFILE = 'We were unable to find this profile. Please check username and try again'; +export const ERROR_UNABLE_TO_VIEW_PROFILE = 'Unable to view this profile'; export const ERROR_UPLOAD = 'An error occurred while uploading. Please try again!'; -export const ERROR_UPLOAD_LARGE_PROFILE_PIC = 'Cant have the first image seen on the profile be blank, please upload a large picture '; -export const ERROR_UPLOAD_MOMENT = 'Unable to upload moment!'; -export const ERROR_UPLOAD_SMALL_PROFILE_PIC = 'Cant have a profile without a pic to represent you, please upload a small profile picture '; -export const ERROR_VERIFICATION_FAILED = 'Verification failed πŸ˜“'; +export const ERROR_UPLOAD_LARGE_PROFILE_PIC = "Can't have the first image seen on the profile be blank, please upload a large picture"; +export const ERROR_UPLOAD_MOMENT = 'Unable to upload moment. Please retry'; +export const ERROR_UPLOAD_SMALL_PROFILE_PIC = "Can't have a profile without a pic to represent you, please upload a small profile picture"; +export const ERROR_VERIFICATION_FAILED_SHORT = 'Verification failed πŸ˜“'; export const MARKED_AS_MSG = (str: string) => `Marked as ${str}`; -export const MOMENT_DELETED_MSG = 'Moment deleted!'; -export const SUCCESS_CATEGORY_DELETE = 'The category was successfully deleted!'; +export const MOMENT_DELETED_MSG = 'Moment deleted....Some moments have to go, to create space for greater ones'; +export const SUCCESS_CATEGORY_DELETE = 'Category successfully deleted, but its memory will live on'; export const SUCCESS_LINK = (str: string) => `Successfully linked ${str} πŸŽ‰`; -export const SUCCESS_PIC_UPLOAD = 'The picture was uploaded successfully!'; -export const SUCCESS_PWD_RESET = 'Your password was reset successfully'; +export const SUCCESS_PIC_UPLOAD = 'Beautiful, the picture was uploaded successfully!'; +export const SUCCESS_PWD_RESET = 'Your password was reset successfully!'; export const SUCCESS_VERIFICATION_CODE_SENT = 'New verification code sent! Check your phone messages for your code'; diff --git a/src/screens/onboarding/InvitationCodeVerification.tsx b/src/screens/onboarding/InvitationCodeVerification.tsx index 875523d3..903a9912 100644 --- a/src/screens/onboarding/InvitationCodeVerification.tsx +++ b/src/screens/onboarding/InvitationCodeVerification.tsx @@ -35,7 +35,7 @@ import { ERROR_DOUBLE_CHECK_CONNECTION, ERROR_INVALID_INVITATION_CODE, ERROR_INVLAID_CODE, - ERROR_VERIFICATION_FAILED, + ERROR_VERIFICATION_FAILED_SHORT, } from '../../constants/strings'; type InvitationCodeVerificationScreenNavigationProp = StackNavigationProp< @@ -78,7 +78,7 @@ const InvitationCodeVerification: React.FC = ({ Alert.alert(ERROR_INVALID_INVITATION_CODE); } } catch (error) { - Alert.alert(ERROR_VERIFICATION_FAILED, ERROR_DOUBLE_CHECK_CONNECTION); + Alert.alert(ERROR_VERIFICATION_FAILED_SHORT, ERROR_DOUBLE_CHECK_CONNECTION); return { name: 'Verification error', description: error, diff --git a/src/screens/onboarding/ProfileOnboarding.tsx b/src/screens/onboarding/ProfileOnboarding.tsx index d0a63a23..127cd9cd 100644 --- a/src/screens/onboarding/ProfileOnboarding.tsx +++ b/src/screens/onboarding/ProfileOnboarding.tsx @@ -34,7 +34,7 @@ import Animated from 'react-native-reanimated'; import {SCREEN_WIDTH} from '../../utils'; import { ERROR_DOUBLE_CHECK_CONNECTION, - ERROR_PROFILE_CREATION, + ERROR_PROFILE_CREATION_SHORT, ERROR_SELECT_CLASS_YEAR, ERROR_SOMETHING_WENT_WRONG_REFRESH, ERROR_UPLOAD_LARGE_PROFILE_PIC, @@ -374,7 +374,7 @@ const ProfileOnboarding: React.FC = ({ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); } } catch (error) { - Alert.alert(ERROR_PROFILE_CREATION, ERROR_DOUBLE_CHECK_CONNECTION); + Alert.alert(ERROR_PROFILE_CREATION_SHORT, ERROR_DOUBLE_CHECK_CONNECTION); return { name: 'Profile creation error', description: error, diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 830fbbb9..37d00659 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -24,7 +24,7 @@ import { ERROR_PWD_ACCOUNT, ERROR_SOMETHING_WENT_WRONG, ERROR_SOMETHING_WENT_WRONG_REFRESH, - ERROR_VERIFICATION_FAILED, + ERROR_VERIFICATION_FAILED_SHORT, SUCCESS_PWD_RESET, SUCCESS_VERIFICATION_CODE_SENT, } from '../constants/strings'; @@ -291,7 +291,7 @@ export const verifyOtp = async (phone: string, otp: string) => { } } } catch (error) { - Alert.alert(ERROR_VERIFICATION_FAILED, ERROR_DOUBLE_CHECK_CONNECTION); + Alert.alert(ERROR_VERIFICATION_FAILED_SHORT, ERROR_DOUBLE_CHECK_CONNECTION); return { name: 'Verification error', description: error, -- cgit v1.2.3-70-g09d2 From de4e8228d85d2b91e3152e1000ce1f1b644bba4e Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 30 Dec 2020 21:01:49 -0500 Subject: finished --- src/components/notifications/Notification.tsx | 51 ++++++++++----------------- src/constants/api.ts | 1 + src/services/MomentServices.ts | 28 ++++++++++++++- 3 files changed, 47 insertions(+), 33 deletions(-) (limited to 'src/services') diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index 184e3f27..2bcee89e 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -1,22 +1,9 @@ import {useNavigation} from '@react-navigation/native'; import React, {useEffect, useState} from 'react'; -import { - ActivityIndicatorBase, - Alert, - Image, - StyleSheet, - Text, - View, -} from 'react-native'; +import {Image, StyleSheet, Text, View} from 'react-native'; import {TouchableWithoutFeedback} from 'react-native-gesture-handler'; import {useDispatch, useSelector, useStore} from 'react-redux'; -import {MomentCommentsScreen} from '../../screens'; -import {loadAvatar} from '../../services'; -import { - EMPTY_MOMENTS_LIST, - EMPTY_MOMENT_CATEGORIES, -} from '../../store/initialStates'; -import {userSocialsReducer} from '../../store/reducers'; +import {loadAvatar, loadMomentThumbnail} from '../../services'; import {RootState} from '../../store/rootReducer'; import {NotificationType, ScreenType} from '../../types'; import { @@ -70,20 +57,21 @@ const Notification: React.FC = (props) => { }; }, [id]); - // TODO: this should be moment thumbnail, waiting for that to complete - // useEffect(() => { - // let mounted = true; - // const loadMomentImage = async (user_id: string) => { - // const response = await loadAvatar(user_id, true); - // if (mounted) { - // setMomentURI(response); - // } - // }; - // loadMomentImage(id); - // return () => { - // mounted = false; - // }; - // }, [id, notification_object]); + useEffect(() => { + let mounted = true; + const loadMomentImage = async (moment_id: string) => { + const response = await loadMomentThumbnail(moment_id); + if (mounted) { + setMomentURI(response); + } + }; + if (notification_type === 'CMT' && notification_object) { + loadMomentImage(notification_object.moment_id); + return () => { + mounted = false; + }; + } + }, [id, notification_object, notification_type]); const onNotificationTap = async () => { switch (notification_type) { @@ -144,13 +132,12 @@ const Notification: React.FC = (props) => { {verbage} - {/* TODO: Still WIP */} - {/* {notification_type === 'CMT' && notification_object && ( + {notification_type === 'CMT' && notification_object && ( - )} */} + )} ); }; diff --git a/src/constants/api.ts b/src/constants/api.ts index de43b94d..701070eb 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -18,6 +18,7 @@ export const GET_FB_POSTS_ENDPOINT: string = API_URL + 'posts-fb/'; export const GET_TWITTER_POSTS_ENDPOINT: string = API_URL + 'posts-twitter/'; export const SEARCH_ENDPOINT: string = API_URL + 'search/'; export const MOMENTS_ENDPOINT: string = API_URL + 'moments/'; +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/'; export const FRIENDS_ENDPOINT: string = API_URL + 'friends/'; diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 217b5857..6d16de96 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,6 +1,11 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; -import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; +import RNFetchBlob from 'rn-fetch-blob'; +import { + COMMENTS_ENDPOINT, + MOMENTS_ENDPOINT, + MOMENT_THUMBNAIL_ENDPOINT, +} from '../constants'; import { ERROR_FAILED_TO_COMMENT, ERROR_UPLOAD, @@ -190,3 +195,24 @@ export const deleteMoment = async (momentId: string) => { return false; } }; + +export const loadMomentThumbnail = async (momentId: string) => { + try { + const token = await AsyncStorage.getItem('token'); + const response = await RNFetchBlob.config({ + fileCache: true, + appendExt: 'jpg', + }).fetch('GET', MOMENT_THUMBNAIL_ENDPOINT + `${momentId}/`, { + Authorization: 'Token ' + token, + }); + const status = response.info().status; + if (status === 200) { + return response.path(); + } else { + return ''; + } + } catch (error) { + console.log(error); + return ''; + } +}; -- cgit v1.2.3-70-g09d2 From b138c10822e399c84e54c35e2775e4eb53da1567 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 15 Jan 2021 17:53:05 -0500 Subject: fixed some bugs --- src/components/notifications/Notification.tsx | 6 ++---- src/screens/main/NotificationsScreen.tsx | 8 +------- src/services/MomentServices.ts | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-) (limited to 'src/services') diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index 62aa0a0b..5efa8b98 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -15,7 +15,6 @@ import { interface NotificationProps { item: NotificationType; - userXId: string | undefined; screenType: ScreenType; } @@ -28,7 +27,6 @@ const Notification: React.FC = (props) => { notification_object, unread, }, - userXId, screenType, } = props; const navigation = useNavigation(); @@ -62,7 +60,7 @@ const Notification: React.FC = (props) => { let mounted = true; const loadMomentImage = async (moment_id: string) => { const response = await loadMomentThumbnail(moment_id); - if (mounted) { + if (mounted && response) { setMomentURI(response); } }; @@ -97,7 +95,7 @@ const Notification: React.FC = (props) => { if (moment) { navigation.push('IndividualMoment', { moment, - userXId, + userXId: undefined, // we're only viewing our own moment here screenType, }); setTimeout(() => { diff --git a/src/screens/main/NotificationsScreen.tsx b/src/screens/main/NotificationsScreen.tsx index ba52d988..da1e7a2b 100644 --- a/src/screens/main/NotificationsScreen.tsx +++ b/src/screens/main/NotificationsScreen.tsx @@ -96,13 +96,7 @@ const NotificationsScreen: React.FC = () => { }, [lastViewed, notifications]); const renderNotification = ({item}: {item: NotificationType}) => ( - + ); const renderSectionHeader = ({section: {title, data}}) => diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 6d16de96..514b674c 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -209,10 +209,10 @@ export const loadMomentThumbnail = async (momentId: string) => { if (status === 200) { return response.path(); } else { - return ''; + return undefined; } } catch (error) { console.log(error); - return ''; + return undefined; } }; -- cgit v1.2.3-70-g09d2