refactor(frontend): extract avatar image component

This commit is contained in:
sam 2024-10-01 14:44:34 +02:00
parent 562ecc46bd
commit b1165c3780
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
3 changed files with 31 additions and 13 deletions

View file

@ -0,0 +1,22 @@
export default function AvatarImage({
src,
width,
alt,
lazyLoad,
}: {
src: string;
width: number;
alt: string;
lazyLoad?: boolean;
}) {
return (
<img
src={src}
alt={alt}
width={width}
height={width}
className="rounded-circle img-fluid"
loading={lazyLoad ? "lazy" : "eager"}
/>
);
}

View file

@ -6,6 +6,7 @@ import ProfileLink from "~/components/profile/ProfileLink";
import ProfileField from "~/components/profile/ProfileField"; import ProfileField from "~/components/profile/ProfileField";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { renderMarkdown } from "~/lib/markdown"; import { renderMarkdown } from "~/lib/markdown";
import AvatarImage from "~/components/profile/AvatarImage";
export type Props = { export type Props = {
name: string; name: string;
@ -31,20 +32,16 @@ export default function BaseProfile({
<div className="row"> <div className="row">
<div className="col-md-4 text-center"> <div className="col-md-4 text-center">
{userI18nKeys ? ( {userI18nKeys ? (
<img <AvatarImage
src={profile.avatar_url || defaultAvatarUrl} src={profile.avatar_url || defaultAvatarUrl}
alt={t("user.avatar-alt", { username: name })}
width={200} width={200}
height={200} alt={t("user.avatar-alt", { username: name })}
className="rounded-circle img-fluid"
/> />
) : ( ) : (
<img <AvatarImage
src={profile.avatar_url || defaultAvatarUrl} src={profile.avatar_url || defaultAvatarUrl}
alt={t("member.avatar-alt", { name: name })}
width={200} width={200}
height={200} alt={t("member.avatar-alt", { name: name })}
className="rounded-circle img-fluid"
/> />
)} )}
{profile.flags && profile.bio && ( {profile.flags && profile.bio && (

View file

@ -10,6 +10,7 @@ import { defaultAvatarUrl } from "~/lib/utils";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { OverlayTrigger, Tooltip } from "react-bootstrap"; import { OverlayTrigger, Tooltip } from "react-bootstrap";
import { Lock } from "react-bootstrap-icons"; import { Lock } from "react-bootstrap-icons";
import AvatarImage from "~/components/profile/AvatarImage";
export default function MemberCard({ user, member }: { user: PartialUser; member: PartialMember }) { export default function MemberCard({ user, member }: { user: PartialUser; member: PartialMember }) {
const { t } = useTranslation(); const { t } = useTranslation();
@ -37,13 +38,11 @@ export default function MemberCard({ user, member }: { user: PartialUser; member
return ( return (
<div className="col"> <div className="col">
<Link to={`/@${user.username}/${member.name}`}> <Link to={`/@${user.username}/${member.name}`}>
<img <AvatarImage
src={member.avatar_url || defaultAvatarUrl} src={member.avatar_url || defaultAvatarUrl}
alt={t("user.member-avatar-alt", { name: member.name })}
width={200} width={200}
height={200} alt={t("user.member-avatar-alt", { name: member.name })}
loading="lazy" lazyLoad
className="rounded-circle img-fluid"
/> />
</Link> </Link>
<p className="m-2"> <p className="m-2">