Skip to content

Commit

Permalink
Add animated avatar placeholder (#270)
Browse files Browse the repository at this point in the history
* Add animated avatar placeholder

* Fix imports
  • Loading branch information
Reckless-Satoshi authored Oct 6, 2022
1 parent 01bcb03 commit 4c8058d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 18 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/BookTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const BookTable = ({
nickname={params.row.maker_nick}
style={{ width: '3.215em', height: '3.215em' }}
smooth={true}
flipHorizontally={true}
orderType={params.row.type}
statusColor={statusBadgeColor(params.row.maker_status)}
tooltip={t(params.row.maker_status)}
Expand Down
43 changes: 29 additions & 14 deletions frontend/src/components/Robots/RobotAvatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { useEffect, useState } from 'react';
import SmoothImage from 'react-smooth-image';
import { Avatar, Badge, Tooltip } from '@mui/material';
import { Avatar, Badge, Tooltip, useTheme } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { SendReceiveIcon } from '../../Icons';
import { apiClient } from '../../../services/api';
import placeholder from './placeholder.json';

interface Props {
nickname: string;
smooth?: boolean;
flipHorizontally?: boolean;
style?: object;
imageStyle?: object;
statusColor?: 'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning';
Expand All @@ -23,13 +25,14 @@ const RobotAvatar: React.FC<Props> = ({
statusColor,
tooltip,
smooth = false,
flipHorizontally = false,
style = {},
imageStyle = {},
avatarClass = 'flippedSmallAvatar',
imageStyle = {},
onLoad = () => {},
}) => {
const { t } = useTranslation();

const theme = useTheme();
const [avatarSrc, setAvatarSrc] = useState<string>();

useEffect(() => {
Expand All @@ -54,17 +57,29 @@ const RobotAvatar: React.FC<Props> = ({
const getAvatar = () => {
if (smooth) {
return (
<div style={style}>
<SmoothImage
src={avatarSrc}
imageStyles={{
borderRadius: '50%',
transform: 'scaleX(-1)',
border: '0.3px solid #555',
filter: 'dropShadow(0.5px 0.5px 0.5px #000000)',
...imageStyle,
}}
/>
<div
style={{
...style,
imageRendering: 'high-quality',
backgroundSize: '100%',
borderRadius: '50%',
transform: flipHorizontally ? 'scaleX(-1)' : '',
border: '0.3px solid #55555',
filter: 'dropShadow(0.5px 0.5px 0.5px #000000)',
backgroundImage: `url(data:${placeholder.image.mime};base64,${placeholder.image.data})`,
}}
>
<div className={theme.palette.mode === 'dark' ? 'loadingAvatarDark' : 'loadingAvatar'}>
<SmoothImage
src={avatarSrc}
imageStyles={{
borderRadius: '50%',
border: '0.3px solid #55555',
filter: 'dropShadow(0.5px 0.5px 0.5px #000000)',
...imageStyle,
}}
/>
</div>
</div>
);
} else {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions frontend/src/components/Robots/RobotAvatar/placeholder.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions frontend/src/components/UserGenPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ class UserGenPage extends Component {
<Grid item xs={12} align='center'>
<RobotAvatar
nickname={this.state.nickname}
style={{ maxWidth: 200 * fontSizeFactor, maxHeight: 200 * fontSizeFactor }}
smooth={true}
style={{ maxWidth: 203 * fontSizeFactor, maxHeight: 203 * fontSizeFactor }}
imageStyle={{
transform: '',
border: '2px solid #555',
filter: 'drop-shadow(1px 1px 1px #000000)',
height: `${195 * fontSizeFactor}px`,
width: `${200 * fontSizeFactor}px`,
height: `${201 * fontSizeFactor}px`,
width: `${201 * fontSizeFactor}px`,
}}
smooth={true}
tooltip={t('This is your trading avatar')}
/>
<br />
Expand Down
43 changes: 43 additions & 0 deletions frontend/static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,46 @@ input[type='number'] {
width: 100%;
}
}

@keyframes animatedBackground {
from {
background-position: 0 0;
}
to {
background-position: 0 80px;
}
}

.loadingAvatar {
background-size: 100%;
border-radius: 50%;
border: 0.3px solid #555;
filter: dropShadow(0.5px 0.5px 0.5px #000000);
background-image: linear-gradient(
0deg,
#ffffffab 0%,
#cfcfcfc2 40%,
#a3a3a3cc 60%,
#ffffffab 100%
);
background-position: 0px 0px;
background-repeat: repeat;
animation: animatedBackground 5s linear infinite;
}

.loadingAvatarDark {
background-size: 100%;
border-radius: 50%;
border: 0.3px solid #555;
filter: dropShadow(0.5px 0.5px 0.5px #000000);
background-image: linear-gradient(
0deg,
#6e6e6ec2 0%,
#14141479 40%,
#14141479 60%,
#6e6e6ec2 100%
);
background-position: 0px 0px;
background-repeat: repeat;
animation: animatedBackground 5s linear infinite;
}

0 comments on commit 4c8058d

Please sign in to comment.