From 3783bc34f07646384a2ac8841a58b88ec2da2baf Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 11 Sep 2023 17:39:02 -0500 Subject: [PATCH] style: re-work add post button in navbar. feat: add actions modal to post component --- src/components/Navbar.tsx | 17 ++++++---- src/components/Post.tsx | 66 ++++++++++++++++++++++++++++++++---- src/components/UserPosts.tsx | 26 ++++++++------ 3 files changed, 85 insertions(+), 24 deletions(-) diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 7ee0a39..ca8cd82 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -1,6 +1,6 @@ import { SignedIn, SignedOut, currentUser } from '@clerk/nextjs'; import Link from 'next/link'; -import { BiSolidMessageSquareAdd } from 'react-icons/bi'; +import { BiPlus, BiSolidMessageSquare } from 'react-icons/bi'; import ThemeButton from './ThemeButton'; import UserButton from './UserButton'; @@ -36,12 +36,15 @@ export default async function Navbar() { Profile
  • - - - +
    + + + + +
  • diff --git a/src/components/Post.tsx b/src/components/Post.tsx index d067f7a..0d31915 100644 --- a/src/components/Post.tsx +++ b/src/components/Post.tsx @@ -1,9 +1,15 @@ import { PostWithUserDto } from '@/app/types'; import { Text } from '@codemirror/state'; import Image from 'next/image'; +import Link from 'next/link'; +import { useEffect, useRef, useState } from 'react'; +import { BiDotsHorizontalRounded } from 'react-icons/bi'; +import { GoDotFill } from 'react-icons/go'; import PostContent from './PostContent'; export default function Post({ post }: { post: PostWithUserDto }) { + const modalRef = useRef(null); + const [modalOpen, setModalOpen] = useState(false); const username = post.user.clerkUsername ?? post.user._id; const createdPostDate = new Date(post._creationTime); const postYear = createdPostDate.getFullYear(); @@ -21,8 +27,27 @@ export default function Post({ post }: { post: PostWithUserDto }) { // TODO: Add reply and like buttons + useEffect(() => { + function handleClickOutside(e: MouseEvent) { + if ( + modalOpen && + modalRef.current && + modalRef.current.contains(e.target as Node) === false + ) { + setModalOpen(false); + } + } + + document.addEventListener('click', handleClickOutside); + return () => document.removeEventListener('click', handleClickOutside); + }, [modalOpen]); + + function handleDeleteClick() { + throw new Error('Function not implemented.'); + } + return ( -
    +
    user profile image
    -
    -
    -
    {username}
    -
    {`${postMonth} ${dayOfMonth}, ${postYear}`}
    +
    +
    +
    +
    {username}
    + +
    + {`${postMonth} ${dayOfMonth}, ${postYear}`} +
    +
    +
    + +
    +
      +
    • + Edit post +
    • +
    • + +
    • +
    +
    +
    -
    ); } diff --git a/src/components/UserPosts.tsx b/src/components/UserPosts.tsx index d3eff33..70ab51e 100644 --- a/src/components/UserPosts.tsx +++ b/src/components/UserPosts.tsx @@ -19,7 +19,9 @@ export default function UserPosts({ user }: { user: UserDto }) { const postsWithUser = pager.results.map(post => ({ ...post, user })); - if (postsWithUser.length == 0) { + console.log(postsWithUser); + + if (pager.isLoading === false && postsWithUser.length == 0) { return (
    @@ -38,17 +40,19 @@ export default function UserPosts({ user }: { user: UserDto }) { } return ( -
    - {postsWithUser.map(post => ( -
    - -
    - ))} +
    +
    + {postsWithUser.map(post => ( +
    + +
    + ))} +
    {pager.isLoading ? ( -
    +
    Loading...