Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement offline behaviour for updateGroupChatAvatar #40884

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,17 +636,50 @@ function updateGroupChatName(reportID: string, reportName: string) {
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME, parameters, {optimisticData});
}

function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageManipulatorResult) {
function updateGroupChatAvatar(reportID: string, previousUrl: string, file?: File | CustomRNImageManipulatorResult) {
nexarvo marked this conversation as resolved.
Show resolved Hide resolved
// If we have no file that means we are removing the avatar.
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {avatarUrl: file?.uri ?? ''},
value: {
avatarUrl: file?.uri ?? '',
pendingFields: {
avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
avatar: null,
},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
avatarUrl: previousUrl,
pendingFields: {
avatar: null,
},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
pendingFields: {
avatar: null,
},
},
},
];
nexarvo marked this conversation as resolved.
Show resolved Hide resolved
const parameters: UpdateGroupChatAvatarParams = {file, reportID};
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_AVATAR, parameters, {optimisticData});
API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_AVATAR, parameters, {optimisticData, failureData, successData});
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,13 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
shouldDisableViewPhoto
onImageRemoved={() => {
// Calling this without a file will remove the avatar
Report.updateGroupChatAvatar(report.reportID ?? '');
Report.updateGroupChatAvatar(report.reportID ?? '', report.avatarUrl ?? '');
}}
onImageSelected={(file) => Report.updateGroupChatAvatar(report.reportID ?? '', file)}
onImageSelected={(file) => Report.updateGroupChatAvatar(report.reportID ?? '', report.avatarUrl ?? '', file)}
editIcon={Expensicons.Camera}
editIconStyle={styles.smallEditIconAccount}
pendingAction={report?.pendingFields?.avatar ?? undefined}
errors={report?.errorFields?.avatar ?? null}
nexarvo marked this conversation as resolved.
Show resolved Hide resolved
/>
) : (
<RoomHeaderAvatars
Expand Down
Loading