From fd210c4713f7101ad91a627d516ee70dda7c9917 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Mon, 10 Apr 2023 11:59:00 -0300 Subject: [PATCH] feat: Change Avatar View (#4746) * [NEW] Change Avatar View * change avatar view and avatar suggestion * avatar Url * change avatar for profile it's done, missing fix revalidate the avatar in profile and drawer * pick image * clean profile view * Finished the profile and fixed the avatar when change the user profile * fix the profile update through all the app * refactor avatar suggestion * fix the delete from rooms and finished RoomInfoView, missing RoomInfoEditView * room info edit view * ipad navigation * refactor the submit function * refactor the e2e test * minor tweak with themes and buttons * minor tweak in edit button * minor tweaks * tweak IAvatarContainer * fixing pt-br * removed the avatarETagUser and search by username and text * created the useHooke useAvatarETag * fix lint * refactor image.ts and test * refactor avatar component * fix the edit button * refactor useAvatarETag * fix the pt-br translation * minor tweak tests * back handleError to views and refactor the submit * avatar suggestion item * types for change avatar view context * fix avatar on header for tablets * minor tweak changeavatarview * refactor avatar url to use hook form * tweak on yup validation * minor tweak with handle error * minor tweak * minor tweak * interface avatar container * minor tweak * Refactor all the changeAvatarView and fix how to test the image url * fixed the layout * minor refactor * minor tweaks * fix the visual bug when the user change the avatar to new then clear cache * fix the flicker when upload an image * update package.json * test the reset, discard alert, cancel and discard * separate the avatar test from profile and create new tests for change avatar * mock imagepicker * minor tweak, adding console and add echo to config.yml * use RUNNING_E2E_TESTS as env to other files * exprt env at android build * change the to way to set the running e2e test env * update test * delete the .env and update the e2e/readme and the file review * minor tweak * minor tweak * update the test, fixing how to dismiss the keyboard --------- Co-authored-by: Gleidson Daniel Silva --- .circleci/config.yml | 4 +- .env | 2 - .../Avatar/{index.tsx => AvatarContainer.tsx} | 54 +--- app/containers/Avatar/AvatarWithEdit.tsx | 85 ++++++ app/containers/Avatar/index.ts | 5 + app/containers/Avatar/useAvatarETag.ts | 67 +++++ app/containers/Button/index.tsx | 2 +- app/definitions/IProfile.ts | 10 +- app/definitions/TChangeAvatarViewContext.ts | 1 + app/i18n/locales/en.json | 8 + app/i18n/locales/pt-BR.json | 8 + app/lib/constants/colors.ts | 3 + app/lib/methods/helpers/image.ts | 10 + app/lib/methods/helpers/index.ts | 1 + app/lib/methods/helpers/review.ts | 4 +- app/lib/methods/subscriptions/rooms.ts | 8 +- app/lib/services/restApi.ts | 4 +- app/sagas/login.js | 16 ++ app/stacks/InsideStack.tsx | 3 + app/stacks/MasterDetailStack/index.tsx | 2 + app/stacks/MasterDetailStack/types.ts | 7 + app/stacks/types.ts | 13 + .../ChangeAvatarView/AvatarSuggestion.tsx | 56 ++++ .../ChangeAvatarView/AvatarSuggestionItem.tsx | 40 +++ app/views/ChangeAvatarView/AvatarUrl.tsx | 29 ++ .../ChangeAvatarView/ImagePicker.mock.ts | 36 +++ app/views/ChangeAvatarView/ImagePicker.ts | 4 + app/views/ChangeAvatarView/index.tsx | 250 ++++++++++++++++++ app/views/ChangeAvatarView/styles.ts | 27 ++ app/views/ChangeAvatarView/submitHelpers.ts | 14 + app/views/ChangeAvatarView/submitServices.ts | 29 ++ app/views/ProfileView/index.tsx | 181 ++----------- app/views/ProfileView/styles.ts | 2 +- app/views/RoomInfoEditView/index.tsx | 90 +------ app/views/RoomInfoEditView/styles.ts | 3 +- app/views/RoomInfoView/index.tsx | 21 +- app/views/RoomInfoView/styles.ts | 5 +- app/views/RoomView/LeftButtons.tsx | 4 +- app/views/RoomView/index.tsx | 1 + e2e/README.md | 3 +- e2e/helpers/data_setup.ts | 5 + e2e/tests/assorted/03-profile.spec.ts | 44 +-- e2e/tests/assorted/15-change-avatar.spec.ts | 94 +++++++ e2e/tests/room/08-roominfo.spec.ts | 5 +- e2e/tests/team/01-createteam.spec.ts | 2 +- metro.config.js | 5 +- package.json | 3 +- yarn.lock | 2 +- 48 files changed, 926 insertions(+), 346 deletions(-) delete mode 100644 .env rename app/containers/Avatar/{index.tsx => AvatarContainer.tsx} (54%) create mode 100644 app/containers/Avatar/AvatarWithEdit.tsx create mode 100644 app/containers/Avatar/index.ts create mode 100644 app/containers/Avatar/useAvatarETag.ts create mode 100644 app/definitions/TChangeAvatarViewContext.ts create mode 100644 app/lib/methods/helpers/image.ts create mode 100644 app/views/ChangeAvatarView/AvatarSuggestion.tsx create mode 100644 app/views/ChangeAvatarView/AvatarSuggestionItem.tsx create mode 100644 app/views/ChangeAvatarView/AvatarUrl.tsx create mode 100644 app/views/ChangeAvatarView/ImagePicker.mock.ts create mode 100644 app/views/ChangeAvatarView/ImagePicker.ts create mode 100644 app/views/ChangeAvatarView/index.tsx create mode 100644 app/views/ChangeAvatarView/styles.ts create mode 100644 app/views/ChangeAvatarView/submitHelpers.ts create mode 100644 app/views/ChangeAvatarView/submitServices.ts create mode 100644 e2e/tests/assorted/15-change-avatar.spec.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index 23c414a05..599170715 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -484,7 +484,7 @@ jobs: - run: name: Build Android command: | - echo "RUNNING_E2E_TESTS=true" > ./.env + export RUNNING_E2E_TESTS=true yarn e2e:android-build - save_cache: *save-gradle-cache - store_artifacts: @@ -582,7 +582,7 @@ jobs: /usr/libexec/PlistBuddy -c "Set :bugsnag:apiKey $BUGSNAG_KEY" ./ios/RocketChatRN/Info.plist /usr/libexec/PlistBuddy -c "Set :bugsnag:apiKey $BUGSNAG_KEY" ./ios/ShareRocketChatRN/Info.plist yarn detox clean-framework-cache && yarn detox build-framework-cache - echo "RUNNING_E2E_TESTS=true" > ./.env + export RUNNING_E2E_TESTS=true yarn e2e:ios-build - persist_to_workspace: root: /Users/distiller/project diff --git a/.env b/.env deleted file mode 100644 index 2c6f3252a..000000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -# DON'T COMMIT THIS FILE -RUNNING_E2E_TESTS= \ No newline at end of file diff --git a/app/containers/Avatar/index.tsx b/app/containers/Avatar/AvatarContainer.tsx similarity index 54% rename from app/containers/Avatar/index.tsx rename to app/containers/Avatar/AvatarContainer.tsx index 9f762308d..d529c7481 100644 --- a/app/containers/Avatar/index.tsx +++ b/app/containers/Avatar/AvatarContainer.tsx @@ -1,13 +1,11 @@ -import { Q } from '@nozbe/watermelondb'; -import React, { useEffect, useRef, useState } from 'react'; +import React from 'react'; import { shallowEqual, useSelector } from 'react-redux'; -import { Observable, Subscription } from 'rxjs'; -import { IApplicationState, TSubscriptionModel, TUserModel } from '../../definitions'; -import database from '../../lib/database'; +import { IApplicationState } from '../../definitions'; import { getUserSelector } from '../../selectors/login'; import Avatar from './Avatar'; import { IAvatar } from './interfaces'; +import { useAvatarETag } from './useAvatarETag'; const AvatarContainer = ({ style, @@ -23,17 +21,13 @@ const AvatarContainer = ({ isStatic, rid }: IAvatar): React.ReactElement => { - const subscription = useRef(); - const [avatarETag, setAvatarETag] = useState(''); - - const isDirect = () => type === 'd'; - const server = useSelector((state: IApplicationState) => state.share.server.server || state.server.server); const serverVersion = useSelector((state: IApplicationState) => state.share.server.version || state.server.version); - const { id, token } = useSelector( + const { id, token, username } = useSelector( (state: IApplicationState) => ({ id: getUserSelector(state).id, - token: getUserSelector(state).token + token: getUserSelector(state).token, + username: getUserSelector(state).username }), shallowEqual ); @@ -48,41 +42,7 @@ const AvatarContainer = ({ true ); - const init = async () => { - const db = database.active; - const usersCollection = db.get('users'); - const subsCollection = db.get('subscriptions'); - - let record; - try { - if (isDirect()) { - const [user] = await usersCollection.query(Q.where('username', text)).fetch(); - record = user; - } else if (rid) { - record = await subsCollection.find(rid); - } - } catch { - // Record not found - } - - if (record) { - const observable = record.observe() as Observable; - subscription.current = observable.subscribe(r => { - setAvatarETag(r.avatarETag); - }); - } - }; - - useEffect(() => { - if (!avatarETag) { - init(); - } - return () => { - if (subscription?.current?.unsubscribe) { - subscription.current.unsubscribe(); - } - }; - }, [text, type, size, avatarETag, externalProviderUrl]); + const { avatarETag } = useAvatarETag({ username, text, type, rid, id }); return ( { + handleEdit?: () => void; +} + +const AvatarWithEdit = ({ + style, + text = '', + avatar, + emoji, + borderRadius, + type, + children, + onPress, + getCustomEmoji, + isStatic, + rid, + handleEdit +}: IAvatarContainer): React.ReactElement => { + const { colors } = useTheme(); + + const { serverVersion } = useAppSelector(state => ({ + serverVersion: state.server.version + })); + + return ( + <> + + {handleEdit && serverVersion && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.6.0') ? ( +