Skip to content

Commit

Permalink
feat : 키워드 편지 상세 조회 답장 리스트 api 연동 (#315)
Browse files Browse the repository at this point in the history
* chore : daycounter 로직 수정

* refactor : 폴더 및 로직 수정

* feat : 컨테이너 및 상세 개발

* story : 스토리 삭제

* feat : 라우팅 설정

* feat : api 호출 로직 작성

* chore : 폴더 경로 수정

* chore : UseNearbyLettersDetailProps  타입 변경

* story : 바뀐 유틸에 맞게 스토리 수정

* chore: simple layout 수정

* style : 전역 스타일 수정

* chore : ; 제거 및 안 쓰는 import 제거

* chore : url 수정

* chore : url 수정으로 인한 변경

* feat : 키워드 편지 상세 조회 삭제 기능 api 연동

* feat : id props 삭제 및 api  연동

* chore : 스토리북 수정

* chore : 키워드 편지 상세 조회 답장 리스트 타입 지정

* feat : 키워드 편지 상세 조회 답장 리스트 api 연동

* feat : 키워드 편지 상세 조회 답장 리스트 데이터 바인딩

---------

Co-authored-by: 남정욱 <[email protected]>
  • Loading branch information
mmjjaa and HelloWook authored Dec 7, 2024
1 parent 93ad24a commit 2b15111
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Margin } from '@/components/Common/Margin/Margin';
import { KeywordList } from '../../Keyword/KeywordList';
import { DeleteButton } from '../../Delete/DeleteButton';
import clsx from 'clsx';
import { useGetKeywordReplyList } from '@/hooks/useGetKeywordReplyList';
import { ReplyList } from '../../ReplyList/ReplyList';

type KeywordLetterDetailProps = {
letterData: {
Expand All @@ -19,8 +21,27 @@ type KeywordLetterDetailProps = {
export const KeywordLetterDetail = ({
letterData
}: KeywordLetterDetailProps) => {
const { letterId, title, content, keywords, createdAt, font } = letterData;

const {
data: keywordReplyListData,
isLoading: isKeywordReplyListDataLoading,
error: keywordReplyListDataError
} = useGetKeywordReplyList({
letterId: letterId || 0,
page: 1,
size: 1,
sort: 'createdAt'
});

if (isKeywordReplyListDataLoading) {
return <div>로딩 중...</div>;
}

if (keywordReplyListDataError instanceof Error) {
return <div>오류...: {keywordReplyListDataError.message}</div>;
}

const { title, content, keywords, createdAt, font } = letterData;

return (
<div className={clsx(font ? font : 'font-sans')}>
Expand All @@ -44,6 +65,14 @@ export const KeywordLetterDetail = ({
<KeywordList keywords={keywords} />
<Margin bottom={30} />
</div>

{keywordReplyListData?.content ? (
<div className="mt-16 mx-auto">
<ReplyList
keywordReplyListData={keywordReplyListData.content}
/>
</div>
) : null}
</div>
);
};
Expand Down
42 changes: 20 additions & 22 deletions src/components/LetterDetailPage/ReplyList/ReplyList.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import { NavLink } from 'react-router-dom';
import { KeywordReplyListResponseType } from '@/types/letter';
import { formatDate } from '@/util/formatDate';
import { NavLink, useLocation } from 'react-router-dom';

type ReplyListProps = {
replies: {
id: number;
title: string;
date: string;
}[];
keywordReplyListData: KeywordReplyListResponseType['content'];
};

export const ReplyList = ({ replies }: ReplyListProps) => {
export const ReplyList = ({ keywordReplyListData }: ReplyListProps) => {
const location = useLocation();
const basePath = location.pathname.split('/')[2];

return (
<NavLink
to="/letter/reply/:id"
className="bg-gray-300 rounded-2xl w-auto"
>
{replies.map((reply, index) => (
<div
key={reply.id}
<div className="bg-gray-300 rounded-2xl w-auto">
{keywordReplyListData.map((reply, index) => (
<NavLink
key={reply.replyLetterId}
to={`/letter/${basePath}/reply/${reply.replyLetterId}`}
className={`flex items-center cursor-pointer h-1 p-6 ${
index < replies.length - 1
index < keywordReplyListData.length - 1
? 'border-b border-l-neutral-300'
: ''
}`}
>
<div
className={`flex items-center justify-between w-full hover:opacity-70 `}
>
<div className="flex items-center justify-between w-full hover:opacity-70">
<span className="font-bold w-44 truncate mr-4">
Re: {reply.title}
{reply.title}
</span>
<span className="text-sm truncate flex-1 text-gray-600">
{reply.date}
{formatDate(reply.createdAt)}
</span>
<div className="text-2xl">{'>'}</div>
</div>
</div>
</NavLink>
))}
</NavLink>
</div>
);
};
31 changes: 31 additions & 0 deletions src/hooks/useGetKeywordReplyList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useQuery } from '@tanstack/react-query';
import { getKeywordReplyList } from '@/service/keyword/getKeywordReplyList';
import { KeywordReplyListResponseType } from '@/types/letter';

type KeywordReplyListRequestProps = {
letterId: number;
page: number;
size: number;
sort: string;
};

export const useGetKeywordReplyList = ({
letterId,
page,
size,
sort
}: KeywordReplyListRequestProps) => {
return useQuery<KeywordReplyListResponseType, Error>({
queryKey: ['getKeywordReplyLists', letterId, page, size, sort],
queryFn: async () => {
const response = await getKeywordReplyList({
letterId,
page,
size,
sort
});
return response.result;
},
enabled: !!letterId
});
};
1 change: 0 additions & 1 deletion src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export const router = createBrowserRouter([
element: <MapLetterDetailPage />
},
{

path: '/letter/map/:dataType/:letterId',
element: <MapLetterArchieveDetailContainerPage />
},
Expand Down
28 changes: 28 additions & 0 deletions src/service/keyword/getKeywordReplyList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defaultApi } from '@/service/api';
import { ApiResponseType } from '@/types/apiResponse';
import { KeywordReplyListResponseType } from '@/types/letter';

type KeywordReplyListRequestProps = {
letterId: number;
page: number;
size: number;
sort: string;
};

type KeywordReplyListResponse = ApiResponseType<KeywordReplyListResponseType>;

export async function getKeywordReplyList({
letterId,
page,
size,
sort
}: KeywordReplyListRequestProps): Promise<KeywordReplyListResponse> {
const api = defaultApi();
const response = await api.get<KeywordReplyListResponse>(
`/letters/replies/${letterId}`,
{
params: { page, size, sort }
}
);
return response.data;
}
20 changes: 20 additions & 0 deletions src/types/letter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,23 @@ export type GetArchivedMapLetterResponseType = {
message: string;
result: getArchivedMapLetterResultType;
};


export type KeywordReply = {
replyLetterId: number;
title: string;
label: string;
createdAt: string;
};

export type KeywordReplyListResponseType = {
content: KeywordReply[];
page: number;
size: number;
totalElements: number;
totalPages: number;
};
export type KeywordReplyListProps = {
keywordReplyListData: KeywordReplyListResponseType[];
};

0 comments on commit 2b15111

Please sign in to comment.