Skip to content

Commit

Permalink
TW-2112: Fix bug Remove profile picture / avatar doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Dec 18, 2024
1 parent c15a26b commit d5b0bc2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
14 changes: 11 additions & 3 deletions lib/domain/app_state/settings/update_profile_success.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object?> get props => [avatar, displayName, isDeleteAvatar];
List<Object?> get props => [avatar, displayName];
}

class DeleteProfileSuccess extends Success {
final String? displayName;

const DeleteProfileSuccess({
this.displayName,
});
@override
List<Object?> get props => [displayName];
}
9 changes: 8 additions & 1 deletion lib/domain/usecase/settings/update_profile_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,25 @@ class SettingsProfileController extends State<SettingsProfile>
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<Failure, Success>(
DeleteAvatarUIStateSuccess(),
);
}
},
);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/presentation/model/pick_avatar_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ class GetAvatarBigSizeUIStateFailure extends Failure {
@override
List<Object?> get props => [];
}

class DeleteAvatarUIStateSuccess extends PickAvatarState {
DeleteAvatarUIStateSuccess();

@override
List<Object?> get props => [];
}

0 comments on commit d5b0bc2

Please sign in to comment.