-
Notifications
You must be signed in to change notification settings - Fork 5
Feat: 알바 토크 목록, 마이페이지 내가 쓴 글 등 #134
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
26d1739
feat: 알바 토크 목록, 검색, 정렬 컴포넌트 추가 및 자잘한 수정
cccwon2 661466e
feat: 마이페이지 > 내가 쓴 글 CardBoad 연동 관련 컴포넌트 수정
cccwon2 79317c6
Merge branch 'dev' into feat/albatalk-list
cccwon2 3a352bb
design: CardBoard > sm 을 lg 로 수정 등
cccwon2 b65a308
design: CardBoard > sm 을 lg 로 수정 등
cccwon2 c018a09
design: CardBoard > sm 을 lg 로 수정 등
cccwon2 522fdae
Merge branch 'dev' into feat/albatalk-list
cccwon2 1ca4b3e
chore: 자잘한 수정 등
cccwon2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React, { Suspense } from "react"; | ||
|
|
||
| export default function AlbaTalkLayout({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <div className="mx-auto max-w-screen-xl px-4 py-8"> | ||
| <Suspense | ||
| fallback={ | ||
| <div className="flex h-[calc(100vh-200px)] items-center justify-center"> | ||
| <div>로딩 중...</div> | ||
| </div> | ||
| } | ||
| > | ||
| {children} | ||
| </Suspense> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,137 @@ | ||
| "use client"; | ||
|
|
||
| import React, { useEffect } from "react"; | ||
| import { useInView } from "react-intersection-observer"; | ||
| import { usePosts } from "@/hooks/queries/post/usePosts"; | ||
| import { usePathname, useSearchParams } from "next/navigation"; | ||
| import SortSection from "@/app/components/layout/posts/SortSection"; | ||
| import SearchSection from "@/app/components/layout/posts/SearchSection"; | ||
| import { useUser } from "@/hooks/queries/user/me/useUser"; | ||
| import Link from "next/link"; | ||
| import { RiEdit2Fill } from "react-icons/ri"; | ||
| import FloatingBtn from "@/app/components/button/default/FloatingBtn"; | ||
| import CardBoard from "@/app/components/card/board/CardBoard"; | ||
|
|
||
| const POSTS_PER_PAGE = 10; | ||
|
|
||
| export default function AlbaTalk() { | ||
| return <div>AlbaTalk</div>; | ||
| const pathname = usePathname(); | ||
| const searchParams = useSearchParams(); | ||
| const { user } = useUser(); | ||
|
|
||
| // URL 쿼리 파라미터에서 키워드와 정렬 기준 가져오기 | ||
| const keyword = searchParams.get("keyword"); | ||
| const orderBy = searchParams.get("orderBy"); | ||
|
|
||
| // 무한 스크롤을 위한 Intersection Observer 설정 | ||
| const { ref, inView } = useInView({ | ||
| threshold: 0.1, | ||
| triggerOnce: false, | ||
| rootMargin: "100px", | ||
| }); | ||
|
|
||
| // 게시글 목록 조회 | ||
| const { data, isLoading, error, hasNextPage, fetchNextPage, isFetchingNextPage } = usePosts({ | ||
| limit: POSTS_PER_PAGE, | ||
| keyword: keyword || undefined, | ||
| orderBy: orderBy || undefined, | ||
| }); | ||
|
|
||
| // 스크롤이 하단에 도달하면 다음 페이지 로드 | ||
| useEffect(() => { | ||
| if (inView && hasNextPage && !isFetchingNextPage) { | ||
| fetchNextPage(); | ||
| } | ||
| }, [inView, hasNextPage, fetchNextPage, isFetchingNextPage]); | ||
|
|
||
| // 에러 상태 처리 | ||
| if (error) { | ||
| return ( | ||
| <div className="flex h-[calc(100vh-200px)] items-center justify-center"> | ||
| <p className="text-red-500">게시글 목록을 불러오는데 실패했습니다.</p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // 로딩 상태 처리 | ||
| if (isLoading) { | ||
| return ( | ||
| <div className="flex h-[calc(100vh-200px)] items-center justify-center"> | ||
| <div>로딩 중...</div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex min-h-screen flex-col items-center"> | ||
| {/* 검색 섹션과 정렬 옵션을 고정 위치로 설정 */} | ||
| <div className="fixed left-0 right-0 top-16 z-40 bg-white shadow-sm"> | ||
| {/* 검색 섹션 */} | ||
| <div className="w-full border-b border-grayscale-100"> | ||
| <div className="mx-auto flex max-w-screen-2xl flex-col gap-4 px-4 py-4 md:px-6 lg:px-8"> | ||
| <div className="flex items-center justify-between"> | ||
| <SearchSection /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* 정렬 옵션 섹션 */} | ||
| <div className="w-full border-b border-grayscale-100"> | ||
| <div className="mx-auto flex max-w-screen-2xl items-center justify-end gap-2 px-4 py-4 md:px-6 lg:px-8"> | ||
| <div className="flex items-center gap-4"> | ||
| <SortSection pathname={pathname} searchParams={searchParams} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* 메인 콘텐츠 영역 */} | ||
| <div className="w-full pt-[132px]"> | ||
| {/* 글쓰기 버튼 - 고정 위치 */} | ||
| {user && ( | ||
| <Link href="/albatalk/addtalk" className="fixed bottom-[50%] right-4 z-[9999] translate-y-1/2"> | ||
| <FloatingBtn icon={<RiEdit2Fill className="size-6" />} variant="orange" /> | ||
| </Link> | ||
| )} | ||
|
|
||
| {!data?.pages?.[0]?.data?.length ? ( | ||
| <div className="flex h-[calc(100vh-200px)] flex-col items-center justify-center"> | ||
| <p className="text-grayscale-500">등록된 게시글이 없습니다.</p> | ||
| </div> | ||
| ) : ( | ||
| <div className="mx-auto mt-4 w-full max-w-screen-xl px-3"> | ||
| <div className="flex flex-col gap-4"> | ||
| {data?.pages.map((page) => ( | ||
| <React.Fragment key={page.nextCursor}> | ||
| {page.data.map((post) => ( | ||
| <div key={post.id} className="rounded-lg border border-grayscale-100 p-4 hover:bg-grayscale-50"> | ||
| <Link href={`/albatalk/${post.id}`}> | ||
| <CardBoard | ||
| title={post.title} | ||
| content={post.content} | ||
| nickname={post.writer.nickname} | ||
| updatedAt={post.updatedAt} | ||
| commentCount={post.commentCount} | ||
| likeCount={post.likeCount} | ||
| /> | ||
| </Link> | ||
| </div> | ||
| ))} | ||
| </React.Fragment> | ||
| ))} | ||
| </div> | ||
|
|
||
| {/* 무한 스크롤 트리거 영역 */} | ||
| <div ref={ref} className="h-4 w-full"> | ||
| {isFetchingNextPage && ( | ||
| <div className="flex justify-center py-4"> | ||
| <div className="h-6 w-6 animate-spin rounded-full border-2 border-primary-orange-300 border-t-transparent" /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,31 +2,32 @@ | |
|
|
||
| import React, { useEffect, useState } from "react"; | ||
| import Image from "next/image"; | ||
| import { formatLocalDate } from "@/utils/workDayFormatter"; | ||
|
|
||
| export interface CardBoardProps { | ||
| title: string; | ||
| content: string; | ||
| userName: string; | ||
| date: string; | ||
| comments: number; | ||
| likes: number; | ||
| nickname: string; | ||
| updatedAt: Date; | ||
| commentCount: number; | ||
| likeCount: number; | ||
| variant?: "default" | "primary"; | ||
| onKebabClick?: () => void; // 케밥 버튼 클릭 핸들러 | ||
| } | ||
|
|
||
| const CardBoard: React.FC<CardBoardProps> = ({ | ||
| title, | ||
| content, | ||
| userName, | ||
| date, | ||
| comments, | ||
| likes, | ||
| nickname, | ||
| updatedAt, | ||
| commentCount, | ||
| likeCount, | ||
| variant = "default", | ||
| onKebabClick, | ||
| }) => { | ||
| const [isLargeScreen, setIsLargeScreen] = useState(false); | ||
| const [isLiked, setIsLiked] = useState(false); | ||
| const [likeCount, setLikeCount] = useState(likes); | ||
| const [likeDisplayCount, setLikeDisplayCount] = useState(likeCount); | ||
|
|
||
| useEffect(() => { | ||
| const handleResize = () => { | ||
|
|
@@ -41,9 +42,9 @@ const CardBoard: React.FC<CardBoardProps> = ({ | |
|
|
||
| const handleLikeClick = () => { | ||
| if (isLiked) { | ||
| setLikeCount((prev) => prev - 1); // 좋아요 취소 시 감소 | ||
| setLikeDisplayCount((prev) => prev - 1); // 좋아요 취소 시 감소 | ||
| } else { | ||
| setLikeCount((prev) => prev + 1); // 좋아요 클릭 시 증가 | ||
| setLikeDisplayCount((prev) => prev + 1); // 좋아요 클릭 시 증가 | ||
| } | ||
| setIsLiked((prev) => !prev); // 좋아요 상태 토글 | ||
| }; | ||
|
|
@@ -94,14 +95,14 @@ const CardBoard: React.FC<CardBoardProps> = ({ | |
| width={28} | ||
| height={28} | ||
| /> | ||
| {/* 이름 + 날짜 */} | ||
| {/* 닉네임 + 수정일 */} | ||
| <div className="flex items-center gap-1 truncate"> | ||
| <span className="truncate font-nexon text-[14px] font-normal text-grayscale-500 sm:text-[16px]"> | ||
| {userName} | ||
| {nickname} | ||
| </span> | ||
| <span className="text-grayscale-500">|</span> | ||
| <span className="whitespace-nowrap font-nexon text-[14px] font-normal text-grayscale-500 sm:text-[16px]"> | ||
| {date} | ||
| {formatLocalDate(updatedAt)} | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
@@ -116,7 +117,7 @@ const CardBoard: React.FC<CardBoardProps> = ({ | |
| width={22} | ||
| height={22} | ||
| /> | ||
| <span className="font-nexon text-[14px] font-normal text-grayscale-500 sm:text-[16px]">{comments}</span> | ||
| <span className="font-nexon text-[14px] font-normal text-grayscale-500 sm:text-[16px]">{commentCount}</span> | ||
| </div> | ||
| {/* 좋아요 */} | ||
| <div className="flex items-center gap-1"> | ||
|
|
@@ -136,7 +137,9 @@ const CardBoard: React.FC<CardBoardProps> = ({ | |
| className="cursor-pointer" | ||
| onClick={handleLikeClick} | ||
| /> | ||
| <span className="font-nexon text-[14px] font-normal text-grayscale-500 sm:text-[16px]">{likeCount}</span> | ||
| <span className="font-nexon text-[14px] font-normal text-grayscale-500 sm:text-[16px]"> | ||
|
||
| {likeDisplayCount} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
댓글 본문에 줄넘김 허용을 위해서 className에 whitespace-pre-wrap 추가하면 좋겠습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네~ 추가할께요.