refactored how avatars are being handled
This commit is contained in:
@@ -68,7 +68,7 @@ export default function CollectionCard({ collection, className }: Props) {
|
||||
return (
|
||||
<ProfilePhoto
|
||||
key={i}
|
||||
src={`/api/v1/avatar/${e.userId}?${Date.now()}`}
|
||||
src={e.user.image ? e.user.image : undefined}
|
||||
className="-mr-3 border-[3px]"
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -238,7 +238,7 @@ export default function TeamManagement({
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
<ProfilePhoto
|
||||
src={`/api/v1/avatar/${e.userId}?${Date.now()}`}
|
||||
src={e.user.image ? e.user.image : undefined}
|
||||
className="border-[3px]"
|
||||
/>
|
||||
<div>
|
||||
@@ -425,7 +425,7 @@ export default function TeamManagement({
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<ProfilePhoto
|
||||
src={`/api/v1/avatar/${collection.ownerId}?${Date.now()}`}
|
||||
src={`uploads/avatar/${collection.ownerId}.jpg`}
|
||||
className="border-[3px]"
|
||||
/>
|
||||
<div>
|
||||
|
||||
@@ -83,7 +83,7 @@ export default function Navbar() {
|
||||
id="profile-dropdown"
|
||||
>
|
||||
<ProfilePhoto
|
||||
src={account.profilePic}
|
||||
src={account.image ? account.image : undefined}
|
||||
priority={true}
|
||||
className="sm:group-hover:h-8 sm:group-hover:w-8 duration-100 border-[3px]"
|
||||
/>
|
||||
|
||||
+13
-23
@@ -2,38 +2,28 @@ import React, { useEffect, useState } from "react";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faUser } from "@fortawesome/free-solid-svg-icons";
|
||||
import Image from "next/image";
|
||||
import avatarExists from "@/lib/client/avatarExists";
|
||||
|
||||
type Props = {
|
||||
src: string;
|
||||
src?: string;
|
||||
className?: string;
|
||||
emptyImage?: boolean;
|
||||
status?: Function;
|
||||
priority?: boolean;
|
||||
};
|
||||
|
||||
export default function ProfilePhoto({
|
||||
src,
|
||||
className,
|
||||
emptyImage,
|
||||
status,
|
||||
priority,
|
||||
}: Props) {
|
||||
const [error, setError] = useState<boolean>(emptyImage || true);
|
||||
|
||||
const checkAvatarExistence = async () => {
|
||||
const canPass = await avatarExists(src);
|
||||
|
||||
setError(!canPass);
|
||||
};
|
||||
export default function ProfilePhoto({ src, className, priority }: Props) {
|
||||
const [image, setImage] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (src) checkAvatarExistence();
|
||||
console.log(src);
|
||||
if (src && !src?.includes("base64"))
|
||||
setImage(`/api/v1/${src.replace("uploads/", "").replace(".jpg", "")}`);
|
||||
else if (!src) setImage("");
|
||||
else {
|
||||
setImage(src);
|
||||
}
|
||||
}, [src]);
|
||||
|
||||
status && status(error || !src);
|
||||
}, [src, error]);
|
||||
|
||||
return error || !src ? (
|
||||
return !image ? (
|
||||
<div
|
||||
className={`bg-sky-600 dark:bg-sky-600 text-white h-10 w-10 aspect-square shadow rounded-full border border-slate-200 dark:border-neutral-700 flex items-center justify-center ${className}`}
|
||||
>
|
||||
@@ -42,7 +32,7 @@ export default function ProfilePhoto({
|
||||
) : (
|
||||
<Image
|
||||
alt=""
|
||||
src={src}
|
||||
src={image}
|
||||
height={112}
|
||||
width={112}
|
||||
priority={priority}
|
||||
|
||||
Reference in New Issue
Block a user