diff --git a/client/src/components/Avatar.tsx b/client/src/components/Avatar.tsx index d3be981..6067dca 100644 --- a/client/src/components/Avatar.tsx +++ b/client/src/components/Avatar.tsx @@ -6,28 +6,21 @@ const Avatar = ({ user }: any) => { const initials = user.firstName[0] + user.lastName[0]; const gravatarUrl = gravatar.url(user.email, { s: '64', r: 'x', d: '404' }, true); const avatarUi = `https://ui-avatars.com/api/?name=${initials}&background=0D8ABC&color=fff&size=64`; - const [avatar, setAvatar] = useState(avatarUi); - const [firstLoad, setFirstLoad] = useState(true); + const [error, setError] = useState(false); - if (firstLoad) { - fetch(gravatarUrl) - .then((response) => { - if (response.ok) { - setAvatar(gravatarUrl); - } - setFirstLoad(false); - }) - .catch((e) => { - setFirstLoad(false); - }); - } + const handleError = (err: any) => { + if (!error) { + setError(true); + } + }; return (
avatar
); diff --git a/client/src/components/Image.tsx b/client/src/components/Image.tsx index 09a3015..0f679ad 100644 --- a/client/src/components/Image.tsx +++ b/client/src/components/Image.tsx @@ -2,14 +2,17 @@ import { useState } from 'react'; import { FaTimes } from 'react-icons/fa'; import Modal from './Modal'; -const Image = ({ src, alt, className }: { src: string; alt?: string; className?: string }) => { +const Image = ({ src, alt, className, onError }: { src: string; alt?: string; className?: string, onError?: (err: any) => void }) => { const [error, setError] = useState(false); const [modal, setModal] = useState(false); - const onError = () => { + const handleError = (err: any) => { if (!error) { setError(true); } + if (onError) { + onError(err); + } }; const onClick = () => { @@ -26,18 +29,18 @@ const Image = ({ src, alt, className }: { src: string; alt?: string; className?: onClick={() => setModal(!modal)} /> {alt} )} {alt} diff --git a/client/src/components/Like.tsx b/client/src/components/Like.tsx index 916b677..1dd8e75 100644 --- a/client/src/components/Like.tsx +++ b/client/src/components/Like.tsx @@ -24,6 +24,7 @@ const Like = ({ messageId, isLiked }: { messageId: string; isLiked: boolean }) = diff --git a/client/src/components/ScrollToBottom.tsx b/client/src/components/ScrollToBottom.tsx index f353cdb..4b99e82 100644 --- a/client/src/components/ScrollToBottom.tsx +++ b/client/src/components/ScrollToBottom.tsx @@ -38,6 +38,7 @@ const ScrollToBottom = ({ children, className = '' }: { children: ReactNode; cla