mirror of
https://github.com/RoboSats/robosats.git
synced 2025-08-04 16:20:06 +00:00

commit a5b63aed93e084fae19d9e444e06238a52f24f3a Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sun Oct 30 10:46:05 2022 -0700 Small fixes commit d64adfc2bf9b9c31dca47ab113c06a1268c347c6 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sun Oct 30 06:02:06 2022 -0700 wip work on federation settings commit ca35d6b3d2776812b07109e197d2e1d46f9f4e81 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sun Oct 30 04:05:33 2022 -0700 Refactor confirmation Dialogs commit c660a5b0d1345d4996efb10cb8999987689bede9 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sat Oct 29 13:36:59 2022 -0700 refactor login (clean separation robot/info. Style navbar. commit b9dc7f7c95a683e3aca024ec6d7857176b4e3a25 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Fri Oct 28 09:54:38 2022 -0700 Add size slider and settings widget commit 20b2b3dcd6838b129741705f1c65d445271e231d Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Fri Oct 28 05:41:48 2022 -0700 Add show more and Dialogs commit da8b70091b5f28139cdec1a8895f4563d64d8e88 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Thu Oct 27 16:26:07 2022 -0700 Add sliding pages commit 6dd90aa1182a7a5e0f0189d1467ba474b68c28c2 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Thu Oct 27 06:34:58 2022 -0700 Add settings forms commit d3d0f3ee1a52bbf1829714050cc798d2542af8f6 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Wed Oct 26 04:16:06 2022 -0700 Refactor utils
140 lines
3.7 KiB
TypeScript
140 lines
3.7 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import SmoothImage from 'react-smooth-image';
|
|
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 | null;
|
|
smooth?: boolean;
|
|
flipHorizontally?: boolean;
|
|
style?: object;
|
|
imageStyle?: object;
|
|
statusColor?: 'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning';
|
|
orderType?: number;
|
|
tooltip?: string;
|
|
tooltipPosition?: string;
|
|
avatarClass?: string;
|
|
onLoad?: () => void;
|
|
}
|
|
|
|
const RobotAvatar: React.FC<Props> = ({
|
|
nickname,
|
|
orderType,
|
|
statusColor,
|
|
tooltip,
|
|
tooltipPosition = 'right',
|
|
smooth = false,
|
|
flipHorizontally = false,
|
|
style = {},
|
|
avatarClass = 'flippedSmallAvatar',
|
|
imageStyle = {},
|
|
onLoad = () => {},
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const theme = useTheme();
|
|
const [avatarSrc, setAvatarSrc] = useState<string>();
|
|
|
|
useEffect(() => {
|
|
if (nickname != null) {
|
|
apiClient.fileImageUrl('/static/assets/avatars/' + nickname + '.png').then(setAvatarSrc);
|
|
}
|
|
}, [nickname]);
|
|
|
|
const statusBadge = (
|
|
<div style={{ position: 'relative', left: '0.428em', top: '0.07em' }}>
|
|
{orderType === 0 ? (
|
|
<SendReceiveIcon
|
|
sx={{ transform: 'scaleX(-1)', height: '0.8em', width: '0.8em' }}
|
|
color='secondary'
|
|
/>
|
|
) : (
|
|
<SendReceiveIcon sx={{ height: '0.8em', width: '0.8em' }} color='primary' />
|
|
)}
|
|
</div>
|
|
);
|
|
|
|
const getAvatar = () => {
|
|
if (smooth) {
|
|
return (
|
|
<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 {
|
|
return (
|
|
<Avatar
|
|
className={avatarClass}
|
|
style={style}
|
|
alt={nickname}
|
|
src={avatarSrc}
|
|
imgProps={{
|
|
sx: { transform: flipHorizontally ? 'scaleX(-1)' : '' },
|
|
style: { transform: flipHorizontally ? 'scaleX(-1)' : '' },
|
|
onLoad,
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
};
|
|
|
|
const getAvatarWithBadges = () => {
|
|
let component = getAvatar();
|
|
|
|
if (statusColor) {
|
|
component = (
|
|
<Badge variant='dot' overlap='circular' badgeContent='' color={statusColor}>
|
|
{component}
|
|
</Badge>
|
|
);
|
|
}
|
|
|
|
if (orderType !== undefined) {
|
|
component = (
|
|
<Badge
|
|
overlap='circular'
|
|
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
|
|
badgeContent={statusBadge}
|
|
>
|
|
{component}
|
|
</Badge>
|
|
);
|
|
}
|
|
|
|
return component;
|
|
};
|
|
|
|
return tooltip ? (
|
|
<Tooltip placement={tooltipPosition} enterTouchDelay={0} title={tooltip}>
|
|
{getAvatarWithBadges()}
|
|
</Tooltip>
|
|
) : (
|
|
getAvatarWithBadges()
|
|
);
|
|
};
|
|
|
|
export default RobotAvatar;
|