2023-06-07 14:34:50 -05:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-06-09 17:31:14 -05:00
|
|
|
import Image from "next/image";
|
2023-05-27 14:05:07 -05:00
|
|
|
|
|
|
|
type Props = {
|
2023-10-27 23:45:14 -05:00
|
|
|
src?: string;
|
2023-05-27 14:05:07 -05:00
|
|
|
className?: string;
|
2023-10-16 12:10:52 -05:00
|
|
|
priority?: boolean;
|
2023-11-27 15:38:38 -06:00
|
|
|
name?: string;
|
2023-12-17 22:32:33 -06:00
|
|
|
large?: boolean;
|
2023-05-27 14:05:07 -05:00
|
|
|
};
|
|
|
|
|
2023-11-27 15:38:38 -06:00
|
|
|
export default function ProfilePhoto({
|
|
|
|
src,
|
|
|
|
className,
|
|
|
|
priority,
|
|
|
|
name,
|
2023-12-17 22:32:33 -06:00
|
|
|
large,
|
2023-11-27 15:38:38 -06:00
|
|
|
}: Props) {
|
2023-10-27 23:45:14 -05:00
|
|
|
const [image, setImage] = useState("");
|
2023-06-07 14:34:50 -05:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-10-27 23:45:14 -05:00
|
|
|
if (src && !src?.includes("base64"))
|
|
|
|
setImage(`/api/v1/${src.replace("uploads/", "").replace(".jpg", "")}`);
|
|
|
|
else if (!src) setImage("");
|
|
|
|
else {
|
|
|
|
setImage(src);
|
|
|
|
}
|
|
|
|
}, [src]);
|
2023-06-11 08:55:36 -05:00
|
|
|
|
2023-10-27 23:45:14 -05:00
|
|
|
return !image ? (
|
2023-12-01 13:00:52 -06:00
|
|
|
<div
|
2023-12-05 03:39:01 -06:00
|
|
|
className={`avatar drop-shadow-md placeholder ${className || ""} ${
|
2023-12-17 22:32:33 -06:00
|
|
|
large ? "w-28 h-28" : "w-8 h-8"
|
2023-12-01 13:00:52 -06:00
|
|
|
}`}
|
|
|
|
>
|
2023-12-10 14:26:44 -06:00
|
|
|
<div className="bg-base-100 text-neutral rounded-full w-full h-full ring-2 ring-neutral-content select-none">
|
2023-11-27 15:38:38 -06:00
|
|
|
{name ? (
|
|
|
|
<span className="text-2xl capitalize">{name.slice(0, 1)}</span>
|
|
|
|
) : (
|
2023-12-17 22:32:33 -06:00
|
|
|
<i className={`bi-person ${large ? "text-5xl" : "text-xl"}`}></i>
|
2023-11-27 15:38:38 -06:00
|
|
|
)}
|
|
|
|
</div>
|
2023-06-07 14:34:50 -05:00
|
|
|
</div>
|
|
|
|
) : (
|
2023-12-01 13:00:52 -06:00
|
|
|
<div
|
2023-12-12 09:43:40 -06:00
|
|
|
className={`avatar skeleton rounded-full drop-shadow-md ${
|
|
|
|
className || ""
|
2023-12-17 22:32:33 -06:00
|
|
|
} ${large || "w-8 h-8"}`}
|
2023-12-01 13:00:52 -06:00
|
|
|
>
|
2023-11-27 23:29:11 -06:00
|
|
|
<div className="rounded-full w-full h-full ring-2 ring-neutral-content">
|
2023-11-27 15:38:38 -06:00
|
|
|
<Image
|
|
|
|
alt=""
|
|
|
|
src={image}
|
|
|
|
height={112}
|
|
|
|
width={112}
|
|
|
|
priority={priority}
|
|
|
|
draggable={false}
|
|
|
|
onError={() => setImage("")}
|
|
|
|
className="aspect-square rounded-full"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-27 14:05:07 -05:00
|
|
|
);
|
|
|
|
}
|