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

fix: avatar not changed in tooltip when updating avatar #20713

Merged
merged 6 commits into from
Jun 14, 2023
Merged
Changes from 3 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
58 changes: 57 additions & 1 deletion src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ function updateAvatar(file) {
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[personalDetails[currentUserEmail].accountID]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of these, can you please add these only if personalDetails[currentUserEmail].accountID exists?

avatar: file.uri,
errorFields: {
avatar: null,
},
pendingFields: {
avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
},
];
const successData = [
{
Expand All @@ -391,6 +406,17 @@ function updateAvatar(file) {
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[personalDetails[currentUserEmail].accountID]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

pendingFields: {
avatar: null,
},
},
},
},
];
const failureData = [
{
Expand All @@ -406,6 +432,18 @@ function updateAvatar(file) {
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[personalDetails[currentUserEmail].accountID]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well.

avatar: personalDetails[currentUserEmail].avatar,
pendingFields: {
avatar: null,
},
},
},
},
];

API.write('UpdateUserAvatar', {file}, {optimisticData, successData, failureData});
Expand All @@ -416,7 +454,7 @@ function updateAvatar(file) {
*/
function deleteAvatar() {
// We want to use the old dot avatar here as this affects both platforms.
const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail);
const defaultAvatar = UserUtils.getDefaultAvatarURL(currentUserEmail, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s-alves10 Let's not try to change it to true. I'm sure we had it as false due to a reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If set to false, default user avatar URL is different than the ones that are current using. When user removes avatar, there is an inconsistency. You can easily check that.

Please let me know if you still want to change it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the in-consistency, but why does it happen for the avatar in the tooltip and not with avatars elsewhere?

Copy link
Contributor Author

@dummy-1111 dummy-1111 Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other avatars get avatar URL with the below function.

App/src/libs/UserUtils.js

Lines 150 to 152 in 0a471b0

function getAvatar(avatarURL, login) {
return isDefaultAvatar(avatarURL) ? getDefaultAvatar(login) : avatarURL;
}

This function corrects this error, but it seems redundant. I think the current change doesn't affect this function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use this function inside our tooltip like we are using elsewhere? This will prevent us from using true here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s-alves10 Any update on above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks!


API.write(
'DeleteUserAvatar',
Expand All @@ -432,6 +470,15 @@ function deleteAvatar() {
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[personalDetails[currentUserEmail].accountID]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

avatar: defaultAvatar,
},
},
},
],
failureData: [
{
Expand All @@ -443,6 +490,15 @@ function deleteAvatar() {
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[personalDetails[currentUserEmail].accountID]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here lastly.

avatar: personalDetails[currentUserEmail].avatar,
},
},
},
],
},
);
Expand Down