Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web][space] Preserve loaded image during profile removal

r4khulfc302800d97f
diff --git a/web/apps/space/src/components/ProfileImagePages.tsx b/web/apps/space/src/components/ProfileImagePages.tsx
index 72b90414f5..6c4027544d 100644
--- a/web/apps/space/src/components/ProfileImagePages.tsx
+++ b/web/apps/space/src/components/ProfileImagePages.tsx
@@ -71,7 +71,31 @@ export const SpaceProfileImageViewerPage: React.FC<{
variant == "cover"
? await removeSpaceProfileCover(profile)
: await removeSpaceProfileAvatar(profile);
- setProfile(savedProfile);
+ setProfile((currentProfile) => {
+ if (
+ !currentProfile ||
+ currentProfile.spaceId != savedProfile.spaceId
+ ) {
+ return currentProfile;
+ }
+ if (variant == "cover") {
+ return currentProfile.avatarObjectID ==
+ savedProfile.avatarObjectID &&
+ currentProfile.avatarKeyVersion ==
+ savedProfile.avatarKeyVersion
+ ? {
+ ...savedProfile,
+ avatarUrl: currentProfile.avatarUrl,
+ }
+ : savedProfile;
+ }
+ return currentProfile.coverObjectID ==
+ savedProfile.coverObjectID &&
+ currentProfile.coverKeyVersion ==
+ savedProfile.coverKeyVersion
+ ? { ...savedProfile, coverUrl: currentProfile.coverUrl }
+ : savedProfile;
+ });
} catch (error) {
log.error("Space profile image removal failed", error);
throw new Error(
diff --git a/web/apps/space/src/state/AppStateProvider.tsx b/web/apps/space/src/state/AppStateProvider.tsx
index ec86a0425c..88515eda45 100644
--- a/web/apps/space/src/state/AppStateProvider.tsx
+++ b/web/apps/space/src/state/AppStateProvider.tsx
@@ -208,7 +208,9 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
[],
);
- const applyProfile = useCallback((nextProfile: SetupProfile | null) => {
+ const applyProfile = useCallback<SpaceAppState["setProfile"]>((update) => {
+ const nextProfile =
+ typeof update == "function" ? update(profileRef.current) : update;
setCachedProfileAvatarUrl(undefined);
const previousAvatarURL = avatarURLRef.current;
if (previousAvatarURL && previousAvatarURL != nextProfile?.avatarUrl) {
diff --git a/web/apps/space/src/state/app-state.tsx b/web/apps/space/src/state/app-state.tsx
index a419147de3..d1d6e8a78d 100644
--- a/web/apps/space/src/state/app-state.tsx
+++ b/web/apps/space/src/state/app-state.tsx
@@ -119,7 +119,7 @@ export interface SpaceAppState {
setPendingCreateProfile: React.Dispatch<
React.SetStateAction<PendingCreateProfile | null>
>;
- setProfile: (profile: SetupProfile | null) => void;
+ setProfile: React.Dispatch<React.SetStateAction<SetupProfile | null>>;
setSignupEmail: React.Dispatch<React.SetStateAction<string>>;
}