2023-01-16 17:31:17 +00:00
|
|
|
import "./Avatar.css";
|
2023-01-31 09:43:14 +00:00
|
|
|
import Nostrich from "nostrich.webp";
|
2023-01-16 17:31:17 +00:00
|
|
|
import { CSSProperties } from "react";
|
2023-01-20 11:11:50 +00:00
|
|
|
import type { UserMetadata } from "Nostr";
|
2023-01-30 23:17:59 +00:00
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
import { RootState } from "State/Store";
|
|
|
|
import { ApiHost } from "Const";
|
2023-01-16 17:31:17 +00:00
|
|
|
|
2023-01-30 23:17:59 +00:00
|
|
|
const Avatar = ({ user, ...rest }: { user?: UserMetadata, onClick?: () => void }) => {
|
|
|
|
const useImageProxy = useSelector((s: RootState) => s.login.preferences.useImageProxy);
|
2023-01-16 17:31:17 +00:00
|
|
|
|
2023-01-30 23:17:59 +00:00
|
|
|
const avatarUrl = (user?.picture?.length ?? 0) === 0 ? Nostrich :
|
|
|
|
(useImageProxy ? `${ApiHost}/api/v1/imgproxy/${window.btoa(user!.picture!)}` : user?.picture)
|
|
|
|
const backgroundImage = `url(${avatarUrl})`
|
|
|
|
const domain = user?.nip05 && user.nip05.split('@')[1]
|
|
|
|
const style = { '--img-url': backgroundImage } as CSSProperties
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
{...rest}
|
|
|
|
style={style}
|
|
|
|
className="avatar"
|
|
|
|
data-domain={domain?.toLowerCase()}
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
)
|
2023-01-16 17:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Avatar
|