From 8214878868f541de5253be79a43a218d6557a273 Mon Sep 17 00:00:00 2001 From: Guillaume Dorce Date: Fri, 21 Oct 2022 15:58:53 +0200 Subject: [PATCH] fix some problems with like annd bad usage of state --- client/src/components/AppHeader.tsx | 2 +- client/src/components/Avatar.tsx | 3 +++ client/src/components/Message.tsx | 13 ++++++++++--- client/src/components/Modal.tsx | 14 ++++++-------- client/src/components/User.tsx | 2 +- client/src/controllers/UserController.ts | 16 +++++++++++++--- src/api/posts/likePost.ts | 2 +- src/controller/PostController.ts | 6 +++--- 8 files changed, 38 insertions(+), 20 deletions(-) diff --git a/client/src/components/AppHeader.tsx b/client/src/components/AppHeader.tsx index 9596866..8b5061a 100644 --- a/client/src/components/AppHeader.tsx +++ b/client/src/components/AppHeader.tsx @@ -30,7 +30,7 @@ const AppHeader = () => {
- {meInfo.data && } + {meInfo.data ? : null}
{meInfo.data && }
diff --git a/client/src/components/Avatar.tsx b/client/src/components/Avatar.tsx index 742545f..3b06c89 100644 --- a/client/src/components/Avatar.tsx +++ b/client/src/components/Avatar.tsx @@ -2,9 +2,12 @@ import gravatar from 'gravatar'; import { useState } from 'react'; 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); diff --git a/client/src/components/Message.tsx b/client/src/components/Message.tsx index dbf1e65..6ee7eed 100644 --- a/client/src/components/Message.tsx +++ b/client/src/components/Message.tsx @@ -34,7 +34,7 @@ const Message = ({ message }: any) => { toastError(error as string); }, }); - + return ( <>
{
{message.author && } - {(me.data?.id === message.author.id) || (me.data?.role === 'ADMIN') ? ( + {me.data?.id === message.author.id || me.data?.role === 'ADMIN' || me.data?.role === 'CREATOR' ? ( ) : null}
@@ -60,7 +60,14 @@ const Message = ({ message }: any) => { minute: 'numeric', })}
- 0 && message.likedBy.find((like: any) => like.userId === me.data?.id)) ? true : false} /> + {me.data?.id === message.author.id ? null : ( + 0 && message.likedBy.find((like: any) => like.userId === me.data?.id) ? true : false + } + /> + )}
diff --git a/client/src/components/Modal.tsx b/client/src/components/Modal.tsx index f99591c..d82e1cc 100644 --- a/client/src/components/Modal.tsx +++ b/client/src/components/Modal.tsx @@ -1,13 +1,11 @@ -import { ReactNode } from "react"; +import { ReactNode } from 'react'; -const Modal = ({ children, show, className = '' }: { children: ReactNode; show: boolean, className?: string }) => { +const Modal = ({ children, show, className = '' }: { children: ReactNode; show: boolean; className?: string }) => { + if (!show) { + return null; + } return ( -
+
{children}
diff --git a/client/src/components/User.tsx b/client/src/components/User.tsx index 3a640b8..ea24dcf 100644 --- a/client/src/components/User.tsx +++ b/client/src/components/User.tsx @@ -59,7 +59,7 @@ const User = ({ author }: any) => { return (