Skip to content

Commit 99406be

Browse files
committed
Feat: 게시물 변수명 변경#65
1 parent 10a303a commit 99406be

File tree

10 files changed

+172
-25
lines changed

10 files changed

+172
-25
lines changed

components/pages/main/Feed/BoardsList/BoardModal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function BoardModal({
3232
</FlexBox>
3333
{board ? (
3434
<ModalBoardCard
35-
userId={board.userName}
35+
userId={board.writer}
3636
imgs={[
3737
// TODO: 이미지 연결
3838
'/Feed/desktop/tempPostPic/tempPostPic1.svg',

components/pages/main/Feed/BoardsList/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ export default function BoardsList({
2929
className="w-full"
3030
>
3131
<FeedBoardCard
32-
userId={board.userName}
32+
userId={board.writer}
3333
content={board.title}
3434
// TODO: 이미지 연결
3535
imgs={[]}
3636
setShowModal={setShowModal}
37-
comments={board.comments}
37+
comments={board.replyListDto}
38+
commentsCount={board.replyCount}
3839
/>
3940
</div>
4041
))}

components/pages/main/Feed/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function Feed() {
2525
showModal={showModal}
2626
setShowModal={setShowModal}
2727
board={selectedBoard}
28-
comments={selectedBoard?.comments}
28+
comments={selectedBoard?.replyListDto}
2929
/>
3030
</FlexBox>
3131
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable jsx-a11y/no-static-element-interactions */
2+
/* eslint-disable jsx-a11y/click-events-have-key-events */
3+
4+
import { Dispatch, SetStateAction } from 'react';
5+
import useGetBoardListInfiniteData from '@/hooks/queries/useGetBoardListInfiniteData';
6+
import { BoardList } from '@/types/types';
7+
import MyBoardCard from '@/components/ui/BoardCard/MyBoardCard';
8+
import FlexBox from '../../../../ui/FlexBox';
9+
10+
export default function MyBoardsList({
11+
setSelectedBoard,
12+
setShowModal,
13+
}: {
14+
setSelectedBoard: Dispatch<SetStateAction<BoardList | null>>;
15+
setShowModal: Dispatch<SetStateAction<boolean>>;
16+
}) {
17+
const { Observer, data: boards } = useGetBoardListInfiniteData({
18+
infiniteQueryKey: ['boards'],
19+
});
20+
21+
return (
22+
<FlexBox direction="column" className="gap-10">
23+
{boards?.pages?.map((board) => (
24+
<div
25+
key={board.id}
26+
onClick={() => {
27+
setSelectedBoard(board);
28+
}}
29+
className="w-full"
30+
>
31+
<MyBoardCard
32+
userName={board.writer}
33+
content={board.content}
34+
// TODO: 이미지 연결
35+
imgs={[]}
36+
// setShowModal={setShowModal}
37+
// comments={board.replyListDto}
38+
commentsCount={board.replyCount}
39+
/>
40+
</div>
41+
))}
42+
<Observer>
43+
<div>로딩스피너...</div>
44+
</Observer>
45+
</FlexBox>
46+
);
47+
}

components/ui/BoardCard/BoardCardPackage/CommentWrapper.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export function BoardCardCommentWrapper({
6666
}
6767

6868
export function MyPageBoardCardCommentWrapper({
69-
commentsNum,
69+
commentsCount,
7070
}: {
71-
commentsNum: number;
71+
commentsCount: number;
7272
}) {
7373
return (
7474
<FlexBox
@@ -81,7 +81,7 @@ export function MyPageBoardCardCommentWrapper({
8181
<FlexBox className="gap-5">
8282
<FlexBox className="gap-2 body3 text-grey-500">
8383
<div>댓글</div>
84-
<div>{commentsNum}</div>
84+
<div>{commentsCount}</div>
8585
</FlexBox>
8686
<FlexBox className="gap-2 body3 text-grey-500">
8787
<div>좋아요</div>

components/ui/BoardCard/FeedBoardCard.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface FeedBoardCardProps {
99
imgs: string[];
1010
setShowModal: Dispatch<SetStateAction<boolean>>;
1111
comments: Comment[] | undefined;
12+
commentsCount: number;
1213
}
1314

1415
export default function FeedBoardCard({
@@ -17,8 +18,8 @@ export default function FeedBoardCard({
1718
imgs,
1819
setShowModal,
1920
comments,
21+
commentsCount,
2022
}: FeedBoardCardProps) {
21-
const commentsCount = comments ? comments.length : 0;
2223
return (
2324
<FlexBox
2425
direction="column"
@@ -41,7 +42,7 @@ export default function FeedBoardCard({
4142
{comments?.map((comment) => (
4243
<BoardCard.Comments
4344
key={comment.id}
44-
userName={comment.userName}
45+
userName={comment.nickname}
4546
content={comment.content}
4647
onClickModal={() => setShowModal(true)}
4748
/>

components/ui/BoardCard/MyBoardCard.tsx

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import { BoardCard } from '@/components/ui/BoardCard/BoardCardPackage';
2+
// import { Dispatch, SetStateAction } from 'react';
23

3-
export default function MyBoardCard() {
4+
interface MyBoardCardProps {
5+
userName: string;
6+
content: string;
7+
imgs: string[];
8+
// setShowModal: Dispatch<SetStateAction<boolean>>;
9+
// comments: Comment[] | undefined;
10+
commentsCount: number;
11+
}
12+
13+
export default function MyBoardCard({
14+
userName,
15+
content,
16+
imgs,
17+
// setShowModal,
18+
// comments,
19+
commentsCount,
20+
}: MyBoardCardProps) {
421
return (
522
<BoardCard>
6-
<BoardCard.Header userId="id" />
7-
<BoardCard.Content
8-
type="myPage"
9-
content="천재고양이 구름이를 소개합니다. 누구 고양이길래 이렇게 귀엽고"
10-
imgs={['/Feed/desktop/tempPostPic/tempPostPic1.svg']}
11-
>
12-
<BoardCard.MyPageBoardCardCommentWrapper commentsNum={13} />
23+
<BoardCard.Header userId={userName} />
24+
<BoardCard.Content type="myPage" content={content} imgs={imgs}>
25+
<BoardCard.MyPageBoardCardCommentWrapper
26+
commentsCount={commentsCount}
27+
/>
1328
</BoardCard.Content>
1429
</BoardCard>
1530
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
import { useInView } from 'react-intersection-observer';
5+
import { useInfiniteQuery } from '@tanstack/react-query';
6+
import getMyBoardList from '@/service/myPage';
7+
8+
interface InfiniteScrollProps {
9+
infiniteQueryKey: string[];
10+
pageParameter?: number;
11+
pageSize?: number;
12+
inViewThreshold?: number;
13+
}
14+
15+
export default function useGetMyBoardListInfiniteData({
16+
infiniteQueryKey,
17+
pageParameter = 1,
18+
pageSize = 5,
19+
inViewThreshold = 1,
20+
}: InfiniteScrollProps) {
21+
const { data, fetchNextPage, isLoading, hasNextPage, isFetchingNextPage } =
22+
useInfiniteQuery({
23+
queryKey: infiniteQueryKey,
24+
queryFn: ({ pageParam = pageParameter }) =>
25+
getMyBoardList({ pageParam, pageSize }),
26+
getNextPageParam: (lastPage, allPages) =>
27+
allPages.length < 20 ? allPages.length + 1 : undefined,
28+
select: (d) => ({
29+
pages: d.pages.flatMap((page) => page),
30+
pageParams: d.pageParams,
31+
}),
32+
});
33+
34+
// 무한 스크롤 화면 가장 아래 부분 탐지하는 observer
35+
function Observer({ children }: { children: React.ReactNode }) {
36+
const { ref, inView } = useInView({ threshold: inViewThreshold });
37+
38+
useEffect(() => {
39+
if (inView && hasNextPage) {
40+
fetchNextPage();
41+
}
42+
}, [inView]);
43+
44+
if (!hasNextPage || !data) return null;
45+
return (
46+
<div ref={ref}>{isLoading || isFetchingNextPage ? children : null}</div>
47+
);
48+
}
49+
50+
return {
51+
Observer,
52+
data,
53+
};
54+
}

service/myPage.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { AuthError } from '@/lib/error';
2+
import { MyBoardList } from '@/types/types';
3+
4+
interface TempPostListApiProps {
5+
pageParam: number;
6+
pageSize: number;
7+
}
8+
9+
export default async function getMyBoardList({
10+
pageParam,
11+
pageSize,
12+
}: TempPostListApiProps): Promise<MyBoardList[]> {
13+
try {
14+
const url = `/endpoint/api/board/myPage?pageNumber=${pageParam}&pageSize=${pageSize}`;
15+
const response = await fetch(url);
16+
if (!response.ok) {
17+
throw new Error(`서버오류:${response.status}`);
18+
}
19+
return await response.json();
20+
} catch (error) {
21+
if (error instanceof AuthError) {
22+
window.location.replace('/auth/login');
23+
alert(error.message);
24+
}
25+
throw error;
26+
}
27+
}

types/types.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@ export interface BoardList {
1515
id: number;
1616
title: string;
1717
content: string;
18-
userName: string;
19-
comments: Comment[];
20-
image: string[];
21-
likeNum: number;
22-
commentNum: number;
23-
created: string;
24-
modified: string;
18+
writer: string;
19+
replyListDto: Comment[];
20+
fileNames: string[];
21+
likedCount: number;
22+
replyCount: number;
23+
createdDate: string;
24+
modifiedDate: string;
2525
}
2626

2727
export interface Comment {
2828
id: number;
2929
content: string;
30-
userName: string;
30+
nickname: string;
3131
children: string[];
3232
}
3333

34+
export interface MyBoardList extends BoardList {}
35+
3436
export interface LocationInfoType {
3537
predictions: string[];
3638
location: {

0 commit comments

Comments
 (0)