diff --git a/client/src/components/Avatar.tsx b/client/src/components/Avatar.tsx index 3b06c89..999e36e 100644 --- a/client/src/components/Avatar.tsx +++ b/client/src/components/Avatar.tsx @@ -1,13 +1,11 @@ import gravatar from 'gravatar'; import { useState } from 'react'; +import Image from './Image'; const Avatar = ({ user }: any) => { - // console.log(user); - 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 avatarUi = `https://ui-avatars.com/api/?name=GD&background=0D8ABC&color=fff&size=64`; const [avatar, setAvatar] = useState(avatarUi); const [firstLoad, setFirstLoad] = useState(true); @@ -22,7 +20,7 @@ const Avatar = ({ user }: any) => { return (
- avatar + avatar
); }; diff --git a/client/src/components/Image.tsx b/client/src/components/Image.tsx new file mode 100644 index 0000000..09a3015 --- /dev/null +++ b/client/src/components/Image.tsx @@ -0,0 +1,48 @@ +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 [error, setError] = useState(false); + const [modal, setModal] = useState(false); + + const onError = () => { + if (!error) { + setError(true); + } + }; + + const onClick = () => { + setModal(true); + }; + + return ( + <> + {modal && ( +
setModal(false)}> + + setModal(!modal)} + /> + {alt} + +
+ )} + {alt} + + ); +}; + +export default Image; diff --git a/client/src/components/Message.tsx b/client/src/components/Message.tsx index 6ee7eed..0c48a51 100644 --- a/client/src/components/Message.tsx +++ b/client/src/components/Message.tsx @@ -5,18 +5,7 @@ import { getMeInfo } from '@controllers/UserController'; import { useQuery } from '@tanstack/react-query'; import { toastError } from '@controllers/Toasts'; import User from './User'; - -const Image = ({ image }: { image: string }) => { - if (image === '' || image === null) { - return null; - } - - return ( -
- image -
- ); -}; +import Image from './Image'; const Text = ({ text }: { text: string }) => { if (text === '') { @@ -50,7 +39,7 @@ const Message = ({ message }: any) => { ) : null} - + {message.image && image}
{new Date(message.createdAt).toLocaleDateString(undefined, { year: 'numeric',