Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
[C-1608 C-2750] Fix edit profile/cover photo (#3735)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Jul 13, 2023
1 parent 97368b1 commit 37d76af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
34 changes: 25 additions & 9 deletions packages/common/src/store/cache/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,25 @@ export const mergeCustomizer = (objValue: any, srcValue: any, key: string) => {
}
}

const updateImageCache = (existing: Metadata, next: Metadata, merged: any) => {
if (
'profile_picture_sizes' in existing &&
'profile_picture_sizes' in next &&
existing.profile_picture_sizes !== next.profile_picture_sizes
) {
merged._profile_picture_sizes = {}
}
if (
'cover_photo_sizes' in existing &&
'cover_photo_sizes' in next &&
existing.cover_photo_sizes !== next.cover_photo_sizes
) {
merged._cover_photo_sizes = {}
}

return merged
}

const addEntries = (state: CacheState, entries: any[], replace?: boolean) => {
const { cacheType } = state
const newEntries = { ...state.entries }
Expand Down Expand Up @@ -181,12 +200,13 @@ const addEntries = (state: CacheState, entries: any[], replace?: boolean) => {
) {
// do nothing
} else if (existing) {
const newMetadata = mergeWith(
let newMetadata = mergeWith(
{},
existing,
entity.metadata,
mergeCustomizer
)
newMetadata = updateImageCache(existing, entity.metadata, newMetadata)
if (cacheType === 'safe-fast' && isEqual(existing, newMetadata)) {
// do nothing
} else {
Expand Down Expand Up @@ -248,14 +268,10 @@ const actionsMap = {
const newSubscriptions = { ...state.subscriptions }

action.entries.forEach((e: { id: string | number; metadata: any }) => {
newEntries[e.id] = wrapEntry(
mergeWith(
{},
{ ...unwrapEntry(state.entries[e.id]) },
e.metadata,
mergeCustomizer
)
)
const existing = { ...unwrapEntry(state.entries[e.id]) }
let newEntry = mergeWith({}, existing, e.metadata, mergeCustomizer)
newEntry = updateImageCache(existing, e.metadata, newEntry)
newEntries[e.id] = wrapEntry(newEntry)
})

action.subscriptions.forEach((s: { id: any; kind: any; uids: any }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const useStyles = makeStyles(({ palette, spacing }) => ({
coverPhoto: {
height: 96,
width: '100%',
borderRadius: 0
borderRadius: 0,
aspectRatio: undefined
},
profilePicture: {
position: 'absolute',
Expand Down

0 comments on commit 37d76af

Please sign in to comment.