From 3b973252fc13aaa93f0fafc7fa05de3c077f8685 Mon Sep 17 00:00:00 2001 From: Aaron William Po Date: Mon, 6 Nov 2023 15:56:25 -0500 Subject: [PATCH] Feat: fix profile avatars in comments This reverts the change to the comment content body component in the previous commit. --- .../BeerBreweryComments/CommentCardBody.tsx | 43 ++++++--- .../CommentContentBody.tsx | 96 ++++++++----------- .../BeerBreweryComments/EditCommentBody.tsx | 2 +- .../seed/create/createNewUserAvatars.ts | 3 +- 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/components/BeerBreweryComments/CommentCardBody.tsx b/src/components/BeerBreweryComments/CommentCardBody.tsx index f7ae738..2191983 100644 --- a/src/components/BeerBreweryComments/CommentCardBody.tsx +++ b/src/components/BeerBreweryComments/CommentCardBody.tsx @@ -4,7 +4,7 @@ import { FC, useState } from 'react'; import { useInView } from 'react-intersection-observer'; import { z } from 'zod'; import CreateCommentValidationSchema from '@/services/schema/CommentSchema/CreateCommentValidationSchema'; - +import Image from 'next/image'; import CommentContentBody from './CommentContentBody'; import EditCommentBody from './EditCommentBody'; @@ -28,19 +28,36 @@ const CommentCardBody: FC = ({ }) => { const [inEditMode, setInEditMode] = useState(false); + const { userAvatar } = comment.postedBy; return ( -
- {!inEditMode ? ( - - ) : ( - - )} +
+
+
+ {!userAvatar ? null : ( + user avatar + )} +
+
+ +
+ {!inEditMode ? ( + + ) : ( + + )} +
); }; diff --git a/src/components/BeerBreweryComments/CommentContentBody.tsx b/src/components/BeerBreweryComments/CommentContentBody.tsx index 747c43a..1b014c9 100644 --- a/src/components/BeerBreweryComments/CommentContentBody.tsx +++ b/src/components/BeerBreweryComments/CommentContentBody.tsx @@ -5,7 +5,7 @@ import { Dispatch, FC, SetStateAction, useContext } from 'react'; import { Rating } from 'react-daisyui'; import Link from 'next/link'; import CommentQueryResult from '@/services/schema/CommentSchema/CommentQueryResult'; -import Image from 'next/image'; + import { z } from 'zod'; import CommentCardDropdown from './CommentCardDropdown'; @@ -19,65 +19,47 @@ const CommentContentBody: FC = ({ comment, setInEditMod const timeDistance = useTimeDistance(new Date(comment.createdAt)); return ( -
-
-
-
- {comment.postedBy.userAvatar ? ( - {comment.postedBy.userAvatar.alt} - ) : ( -
- {comment.postedBy.username[0]} -
- )} -
-
-
-
-
-

- - {comment.postedBy.username} - -

- - posted{' '} - {' '} - ago - -
- - {user && ( - - )} -
-
- - {Array.from({ length: 5 }).map((val, index) => ( - - ))} - -
+
+
+
-

{comment.content}

+

+ + {comment.postedBy.username} + +

+ + posted{' '} + {' '} + ago +
+ + {user && ( + + )}
+
+ + {Array.from({ length: 5 }).map((val, index) => ( + + ))} + +
+
+
+

{comment.content}

); diff --git a/src/components/BeerBreweryComments/EditCommentBody.tsx b/src/components/BeerBreweryComments/EditCommentBody.tsx index f9439e4..8d18c3f 100644 --- a/src/components/BeerBreweryComments/EditCommentBody.tsx +++ b/src/components/BeerBreweryComments/EditCommentBody.tsx @@ -81,7 +81,7 @@ const EditCommentBody: FC = ({ }; return ( -
+
diff --git a/src/prisma/seed/create/createNewUserAvatars.ts b/src/prisma/seed/create/createNewUserAvatars.ts index 84363e3..0c92b40 100644 --- a/src/prisma/seed/create/createNewUserAvatars.ts +++ b/src/prisma/seed/create/createNewUserAvatars.ts @@ -18,8 +18,9 @@ const createNewUserAvatars = async ({ }: CreateNewUserAvatarsArgs) => { const userAvatars: UserAvatarData[] = []; - const path = imageUrls[Math.floor(Math.random() * imageUrls.length)]; users.forEach((user) => { + const path = imageUrls[Math.floor(Math.random() * imageUrls.length)]; + userAvatars.push({ path, alt: `${user.firstName} ${user.lastName}`,