Skip to content

Commit

Permalink
[web] Add showSpinner prop to Avatar component
Browse files Browse the repository at this point in the history
Summary:
Add `showSpinner?: boolean` prop to the `Avatar` component and display `LoadingIndicator` over `Avatar` if set to `true`.

---

Depends on D8283

Test Plan:
Looks as expected:
{F600886}

Reviewers: ashoat, ginsu, rohan

Reviewed By: rohan

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8285
  • Loading branch information
atulsmadhugiri committed Jun 23, 2023
1 parent 72b8c7f commit 0bf79d6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
11 changes: 11 additions & 0 deletions web/avatars/avatar.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
.avatarContainer {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}

.editAvatarLoadingSpinner {
position: absolute;
}

.emojiContainer {
display: flex;
align-items: center;
Expand Down
31 changes: 29 additions & 2 deletions web/avatars/avatar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import * as React from 'react';
import type { ResolvedClientAvatar } from 'lib/types/avatar-types.js';

import css from './avatar.css';
import LoadingIndicator from '../loading-indicator.react.js';

type Props = {
+avatarInfo: ResolvedClientAvatar,
+size: 'micro' | 'small' | 'large' | 'profile',
+showSpinner?: boolean,
};

function Avatar(props: Props): React.Node {
const { avatarInfo, size } = props;
const { avatarInfo, size, showSpinner } = props;

const containerSizeClassName = classnames({
[css.imgContainer]: avatarInfo.type === 'image',
Expand Down Expand Up @@ -63,7 +65,32 @@ function Avatar(props: Props): React.Node {
emojiSizeClassName,
]);

return avatar;
let loadingIndicatorSize;
if (size === 'micro') {
loadingIndicatorSize = 'small';
} else if (size === 'small') {
loadingIndicatorSize = 'small';
} else if (size === 'large') {
loadingIndicatorSize = 'medium';
} else {
loadingIndicatorSize = 'large';
}

const loadingIndicator = React.useMemo(
() => (
<div className={css.editAvatarLoadingSpinner}>
<LoadingIndicator status="loading" size={loadingIndicatorSize} />
</div>
),
[loadingIndicatorSize],
);

return (
<div className={css.avatarContainer}>
{showSpinner ? loadingIndicator : null}
{avatar}
</div>
);
}

export default Avatar;
6 changes: 5 additions & 1 deletion web/avatars/emoji-avatar-selection-modal.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ function EmojiAvatarSelectionModal(): React.Node {
<Modal name="Emoji avatar selection" size="large" onClose={popModal}>
<div className={css.modalBody}>
<div className={css.avatarContainer}>
<Avatar avatarInfo={pendingEmojiAvatar} size="profile" />
<Avatar
avatarInfo={pendingEmojiAvatar}
size="profile"
showSpinner={userAvatarSaveInProgress}
/>
</div>
<div className={css.emojiPickerContainer}>
<Picker data={data} theme="dark" onEmojiSelect={onEmojiSelect} />
Expand Down

0 comments on commit 0bf79d6

Please sign in to comment.