Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 이전글 다음글 바로가기 추가 #278

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/pages/Community/components/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useGetPost from '../hooks/useGetPost';

import Comments from './Comments';
import PostFormModal from './PostFormModal';
import PostNavigation from './PostNavigation';
import PostSection from './PostSection';

interface PostProps {
Expand Down Expand Up @@ -52,6 +53,13 @@ export default function Post({ postId, category }: PostProps) {
<Comments postId={Number(postId)} commentAllow={post.commentAllow} />
</ErrorBoundary>
)}
{post && (
<PostNavigation
category={category}
prevPost={post.prev}
nextPost={post.next}
/>
)}
</>
);
}
63 changes: 63 additions & 0 deletions src/pages/Community/components/PostNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Lock } from '@phosphor-icons/react';
import { Link } from 'react-router-dom';

import useBoundStore from '@/stores';
import { AdjacentPost } from '@/types/community';

interface PostNavLinkProps {
type: '이전' | '다음';
category: string;
postInfo: AdjacentPost;
}

function PostNavLink({ type, category, postInfo }: PostNavLinkProps) {
const user = useBoundStore(state => state.user);
const isSecretPost = postInfo.secret && user?.email !== postInfo.writerEmail;
const postTitle = isSecretPost ? '비밀글입니다.' : postInfo?.title;

return (
<div className={'w-full flex items-center gap-20 px-20'}>
<div
className={'min-w-fit max-w-full font-semibold text-sm text-gray-500'}
>{`${type}글`}</div>
<Link
to={`/community/${category}/${postInfo.id}`}
className={'w-full flex items-center gap-5 text-black truncate'}
>
{postTitle}
{isSecretPost && <Lock weight={'fill'} className={'shrink-30'} />}
</Link>
</div>
);
}

interface PostNavigationProps {
category: string;
prevPost: AdjacentPost | null;
nextPost: AdjacentPost | null;
}

function PostNavigation({ category, prevPost, nextPost }: PostNavigationProps) {
return (
<div className={'flex flex-col gap-10'}>
<hr className='border-1 border-gray-300 w-full mt-20' />
{nextPost && (
<PostNavLink type={'다음'} category={category} postInfo={nextPost} />
)}
{prevPost && (
<PostNavLink type={'이전'} category={category} postInfo={prevPost} />
)}
<hr className='border-1 border-gray-300 w-full' />
<div className={'w-full flex-row-center mt-10'}>
<Link
to={`/community/${category}`}
className={'px-40 py-10 bg-primary-75 text-white rounded-md'}
>
목록으로
</Link>
</div>
</div>
);
}

export default PostNavigation;
9 changes: 9 additions & 0 deletions src/types/community.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export interface AdjacentPost {
id: number;
title: string;
secret: boolean;
writerEmail: string;
}

export interface Post {
title: string;
writer: string;
Expand All @@ -9,6 +16,8 @@ export interface Post {
commentAllow: boolean;
commentCount: number;
secret: boolean;
prev: AdjacentPost | null;
next: AdjacentPost | null;
}

export type PostSummary = Omit<Post, 'fileUrl' | 'content' | 'commentAllow'> & {
Expand Down
Loading