el.xwx.moe/components/ProfilePhoto.tsx

34 lines
876 B
TypeScript
Raw Normal View History

2023-06-07 14:34:50 -05:00
import React, { useEffect, useState } from "react";
2023-05-27 14:05:07 -05:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faUser } from "@fortawesome/free-solid-svg-icons";
type Props = {
src: string;
className?: string;
};
export default function ProfilePhoto({ src, className }: Props) {
2023-06-07 14:34:50 -05:00
const [error, setError] = useState(false);
useEffect(() => {
2023-06-08 08:39:22 -05:00
setError(false);
}, [src]);
2023-06-07 14:34:50 -05:00
return error || !src ? (
<div
className={`bg-sky-500 text-white h-10 w-10 shadow rounded-full border-[3px] border-slate-200 flex items-center justify-center ${className}`}
2023-05-27 14:05:07 -05:00
>
2023-06-08 08:39:22 -05:00
<FontAwesomeIcon icon={faUser} className="w-1/2 h-1/2" />
2023-06-07 14:34:50 -05:00
</div>
) : (
<img
alt=""
src={src}
className={`h-10 w-10 shadow rounded-full border-[3px] border-slate-200 ${className}`}
onError={() => {
setError(true);
}}
/>
2023-05-27 14:05:07 -05:00
);
}