style: re-work add post button in navbar. feat: add actions modal to post component
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { SignedIn, SignedOut, currentUser } from '@clerk/nextjs';
|
import { SignedIn, SignedOut, currentUser } from '@clerk/nextjs';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { BiSolidMessageSquareAdd } from 'react-icons/bi';
|
import { BiPlus, BiSolidMessageSquare } from 'react-icons/bi';
|
||||||
import ThemeButton from './ThemeButton';
|
import ThemeButton from './ThemeButton';
|
||||||
import UserButton from './UserButton';
|
import UserButton from './UserButton';
|
||||||
|
|
||||||
@@ -36,12 +36,15 @@ export default async function Navbar() {
|
|||||||
<Link href={`/profile/${user?.id}`}>Profile</Link>
|
<Link href={`/profile/${user?.id}`}>Profile</Link>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
<div className='mx-4'>
|
||||||
<Link
|
<Link
|
||||||
href='/posts/add'
|
href='/posts/add'
|
||||||
className='text-primary-accent'
|
className='relative'
|
||||||
>
|
>
|
||||||
<BiSolidMessageSquareAdd className='w-10 h-10' />
|
<BiSolidMessageSquare className='absolute w-10 h-10 top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-primary-accent' />
|
||||||
|
<BiPlus className='absolute w-5 h-5 top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-white' />
|
||||||
</Link>
|
</Link>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</SignedIn>
|
</SignedIn>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
+58
-4
@@ -1,9 +1,15 @@
|
|||||||
import { PostWithUserDto } from '@/app/types';
|
import { PostWithUserDto } from '@/app/types';
|
||||||
import { Text } from '@codemirror/state';
|
import { Text } from '@codemirror/state';
|
||||||
import Image from 'next/image';
|
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';
|
import PostContent from './PostContent';
|
||||||
|
|
||||||
export default function Post({ post }: { post: PostWithUserDto }) {
|
export default function Post({ post }: { post: PostWithUserDto }) {
|
||||||
|
const modalRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
const username = post.user.clerkUsername ?? post.user._id;
|
const username = post.user.clerkUsername ?? post.user._id;
|
||||||
const createdPostDate = new Date(post._creationTime);
|
const createdPostDate = new Date(post._creationTime);
|
||||||
const postYear = createdPostDate.getFullYear();
|
const postYear = createdPostDate.getFullYear();
|
||||||
@@ -21,8 +27,27 @@ export default function Post({ post }: { post: PostWithUserDto }) {
|
|||||||
|
|
||||||
// TODO: Add reply and like buttons
|
// 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 (
|
return (
|
||||||
<div className='flex w-full h-full gap-4 p-8 bg-white dark:bg-secondary-gray'>
|
<div className='flex w-full gap-4 p-8 bg-white dark:bg-secondary-gray'>
|
||||||
<div>
|
<div>
|
||||||
<Image
|
<Image
|
||||||
alt='user profile image'
|
alt='user profile image'
|
||||||
@@ -32,17 +57,46 @@ export default function Post({ post }: { post: PostWithUserDto }) {
|
|||||||
className='rounded-full object-cover border-4 border-primary-accent'
|
className='rounded-full object-cover border-4 border-primary-accent'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col gap-2'>
|
<div className='flex flex-1 flex-col gap-2'>
|
||||||
|
<div className='flex items-center justify-between gap-2'>
|
||||||
<div className='flex items-center gap-2'>
|
<div className='flex items-center gap-2'>
|
||||||
<div>{username}</div>
|
<div>{username}</div>
|
||||||
<div className='text-xs'>{`${postMonth} ${dayOfMonth}, ${postYear}`}</div>
|
<GoDotFill className='w-3 h-3' />
|
||||||
|
<div className='text-xs'>
|
||||||
|
{`${postMonth} ${dayOfMonth}, ${postYear}`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='relative'>
|
||||||
|
<button onClick={() => setModalOpen(!modalOpen)}>
|
||||||
|
<BiDotsHorizontalRounded />
|
||||||
|
</button>
|
||||||
|
<div
|
||||||
|
ref={modalRef}
|
||||||
|
className={`${
|
||||||
|
modalOpen ? '' : 'hidden'
|
||||||
|
} max-w-min whitespace-nowrap absolute top-5 right-0 rounded-md py-2 pl-4 pr-10 shadow-md bg-white dark:bg-primary-gray`}
|
||||||
|
>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<Link href={`/posts/${post._id}/edit`}>Edit post</Link>
|
||||||
|
</li>
|
||||||
|
<li className='text-red-600'>
|
||||||
|
<button
|
||||||
|
onClick={handleDeleteClick}
|
||||||
|
type='button'
|
||||||
|
>
|
||||||
|
Delete post
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<PostContent content={Text.of(post.content).toString()} />
|
<PostContent content={Text.of(post.content).toString()} />
|
||||||
</div>
|
</div>
|
||||||
<div></div>
|
<div></div>
|
||||||
</div>
|
</div>
|
||||||
<div></div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ export default function UserPosts({ user }: { user: UserDto }) {
|
|||||||
|
|
||||||
const postsWithUser = pager.results.map(post => ({ ...post, user }));
|
const postsWithUser = pager.results.map(post => ({ ...post, user }));
|
||||||
|
|
||||||
if (postsWithUser.length == 0) {
|
console.log(postsWithUser);
|
||||||
|
|
||||||
|
if (pager.isLoading === false && postsWithUser.length == 0) {
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col items-center justify-center border-t border-gray-600 w-full h-full'>
|
<div className='flex flex-col items-center justify-center border-t border-gray-600 w-full h-full'>
|
||||||
<div className='flex flex-col items-center gap-2'>
|
<div className='flex flex-col items-center gap-2'>
|
||||||
@@ -38,17 +40,19 @@ export default function UserPosts({ user }: { user: UserDto }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col items-center w-full h-full'>
|
<div className='flex flex-col items-center w-full'>
|
||||||
|
<div className='flex flex-col items-center w-full'>
|
||||||
{postsWithUser.map(post => (
|
{postsWithUser.map(post => (
|
||||||
<div
|
<div
|
||||||
key={post._id}
|
key={post._id}
|
||||||
className='w-full h-full border border-b-0 border-gray-600 last:border-b'
|
className='w-full border border-t-0 border-gray-600 first:border-t last:rounded-b-md p-1'
|
||||||
>
|
>
|
||||||
<Post post={post} />
|
<Post post={post} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
</div>
|
||||||
{pager.isLoading ? (
|
{pager.isLoading ? (
|
||||||
<div className='flex items-center gap-2 p-5'>
|
<div className='flex w-full items-center justify-center gap-2 p-5 border-t border-gray-600'>
|
||||||
<SpinningLoader className='animate-spin w-5 h-5' />
|
<SpinningLoader className='animate-spin w-5 h-5' />
|
||||||
Loading...
|
Loading...
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user