From d5b0bc274f49953b1e4eef58e564d66b0b88f1a2 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Wed, 18 Dec 2024 12:08:20 +0700 Subject: [PATCH] TW-2112: Fix bug Remove profile picture / avatar doesn't work --- .../settings/update_profile_success.dart | 14 +++++++++++--- .../settings/update_profile_interactor.dart | 9 ++++++++- .../settings_profile/settings_profile.dart | 19 ++++++++++++++++--- lib/presentation/model/pick_avatar_state.dart | 7 +++++++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/domain/app_state/settings/update_profile_success.dart b/lib/domain/app_state/settings/update_profile_success.dart index eebecda062..5291f166ca 100644 --- a/lib/domain/app_state/settings/update_profile_success.dart +++ b/lib/domain/app_state/settings/update_profile_success.dart @@ -8,14 +8,22 @@ class UpdateProfileInitial extends Success { class UpdateProfileSuccess extends Success { final Uri? avatar; final String? displayName; - final bool isDeleteAvatar; const UpdateProfileSuccess({ this.avatar, this.displayName, - this.isDeleteAvatar = false, }); @override - List get props => [avatar, displayName, isDeleteAvatar]; + List get props => [avatar, displayName]; +} + +class DeleteProfileSuccess extends Success { + final String? displayName; + + const DeleteProfileSuccess({ + this.displayName, + }); + @override + List get props => [displayName]; } diff --git a/lib/domain/usecase/settings/update_profile_interactor.dart b/lib/domain/usecase/settings/update_profile_interactor.dart index ff4f7aa7d3..ac921c2995 100644 --- a/lib/domain/usecase/settings/update_profile_interactor.dart +++ b/lib/domain/usecase/settings/update_profile_interactor.dart @@ -30,11 +30,18 @@ class UpdateProfileInteractor { displayName, ); } + if (isDeleteAvatar) { + yield Right( + DeleteProfileSuccess( + displayName: displayName, + ), + ); + return; + } yield Right( UpdateProfileSuccess( displayName: displayName, avatar: avatarUrl, - isDeleteAvatar: isDeleteAvatar, ), ); } catch (e) { diff --git a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart index 00938a36b7..31ddfcd4fe 100644 --- a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart +++ b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart @@ -455,12 +455,25 @@ class SettingsProfileController extends State avatarUrl: success.avatar ?? currentProfile.value?.avatarUrl, ); _sendAccountDataEvent(profile: newProfile); - if (!success.isDeleteAvatar) { - isEditedProfileNotifier.toggle(); - } + isEditedProfileNotifier.toggle(); _getCurrentProfile(client, isUpdated: true); TwakeDialog.hideLoadingDialog(context); } + + if (success is DeleteProfileSuccess) { + final newProfile = Profile( + userId: client.userID!, + displayName: success.displayName ?? displayName, + avatarUrl: null, + ); + _sendAccountDataEvent(profile: newProfile); + isEditedProfileNotifier.toggle(); + _getCurrentProfile(client, isUpdated: true); + TwakeDialog.hideLoadingDialog(context); + pickAvatarUIState.value = Right( + DeleteAvatarUIStateSuccess(), + ); + } }, ); } diff --git a/lib/presentation/model/pick_avatar_state.dart b/lib/presentation/model/pick_avatar_state.dart index 139b630333..5f21d37987 100644 --- a/lib/presentation/model/pick_avatar_state.dart +++ b/lib/presentation/model/pick_avatar_state.dart @@ -38,3 +38,10 @@ class GetAvatarBigSizeUIStateFailure extends Failure { @override List get props => []; } + +class DeleteAvatarUIStateSuccess extends PickAvatarState { + DeleteAvatarUIStateSuccess(); + + @override + List get props => []; +}