Skip to content

Commit

Permalink
feat : 지도 편지 상세 조회 답장 리스트 api 연동 (#319)
Browse files Browse the repository at this point in the history
* chore :  타입명 수정

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

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

* chore : 지도 편지 상세 조회 답장 리스트 타입 수정

* fix : 빌드 에러 수정

* fix :  letterId 빌드 에러 수정

* chore : 스토리북 삭제
  • Loading branch information
mmjjaa authored Dec 8, 2024
1 parent 06ba208 commit 791ddda
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { formatDate } from '@/util/formatDate';
import clsx from 'clsx';
import { DeleteButton } from '../../Delete/DeleteButton';
import { TextArea } from '@/components/Common/TextArea/TextArea';
import { useGetMapReplyList } from '@/hooks/useGetMapReplyList';
import { ReplyList } from '../../ReplyList/ReplyList';

type MapLetterDetailProps = {
letterData: {
Expand All @@ -21,10 +23,31 @@ type MapLetterDetailProps = {
};

export const MapLetterArchieveDetail = ({
letterData
letterData,
letterId
}: MapLetterDetailProps) => {
const { title, content, createdAt, font, description, profileImg } =
letterData;

const {
data: mapReplyListData,
isLoading: isMapReplyListDataLoading,
error: mapReplyListDataError
} = useGetMapReplyList({
letterId: Number(letterId) || 0,
page: 1,
size: 9
});

console.log(mapReplyListData);
if (isMapReplyListDataLoading) {
return <div>로딩 중...</div>;
}

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

return (
<div className={clsx(font ? font : 'font-sans')}>
<Margin top={20} />
Expand Down Expand Up @@ -58,6 +81,15 @@ export const MapLetterArchieveDetail = ({
</div>
<Margin bottom={30} />
</div>

{mapReplyListData?.content ? (
<div className="mt-16 mx-auto">
<ReplyList
title={title}
keywordReplyListData={mapReplyListData.content}
/>
</div>
) : null}
</div>
);
};
9 changes: 5 additions & 4 deletions src/components/LetterDetailPage/ReplyList/ReplyList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { KeywordReplyListResponseType } from '@/types/letter';
import { ReplyListResponseType } from '@/types/letter';
import { formatDate } from '@/util/formatDate';
import { NavLink, useLocation } from 'react-router-dom';

type ReplyListProps = {
keywordReplyListData: KeywordReplyListResponseType['content'];
title?: string;
keywordReplyListData: ReplyListResponseType['content'];
};

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

Expand All @@ -24,7 +25,7 @@ export const ReplyList = ({ keywordReplyListData }: ReplyListProps) => {
>
<div className="flex items-center justify-between w-full hover:opacity-70">
<span className="font-bold w-44 truncate mr-4">
{reply.title}
RE: {title}
</span>
<span className="text-sm truncate flex-1 text-gray-600">
{formatDate(reply.createdAt)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DayCounter } from '@/components/Common/DayCounter/DayCounter';
import { NavLink } from 'react-router-dom';

type LetterInfoContainerProps = {
Expand Down Expand Up @@ -31,7 +30,11 @@ export const LetterInfoContainer = ({
<div className="flex flex-col h-20">
<div className="gap-2 flex-center">
<p className="text-sm text-gray-600">작성일: {date}</p>
<DayCounter width="40px" createdAt={String(daysLeft)} />
<div className="p-1 bg-gray-100 flex-center rounded-xl">
<p className="text-sm font-bold text-gray-500 text-nowrap">
D-{daysLeft}
</p>
</div>
</div>

<h3 className="text-lg font-semibold">{title}</h3>
Expand Down
19 changes: 0 additions & 19 deletions src/components/MapPage/Maplibre/Maplibre.stories.tsx

This file was deleted.

157 changes: 0 additions & 157 deletions src/components/MapPage/Maplibre/Maplibre.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/hooks/useGetKeywordReplyList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { getKeywordReplyList } from '@/service/keyword/getKeywordReplyList';
import { KeywordReplyListResponseType } from '@/types/letter';
import { ReplyListResponseType } from '@/types/letter';

type KeywordReplyListRequestProps = {
letterId: number;
Expand All @@ -15,7 +15,7 @@ export const useGetKeywordReplyList = ({
size,
sort
}: KeywordReplyListRequestProps) => {
return useQuery<KeywordReplyListResponseType, Error>({
return useQuery<ReplyListResponseType, Error>({
queryKey: ['getKeywordReplyLists', letterId, page, size, sort],
queryFn: async () => {
const response = await getKeywordReplyList({
Expand Down
28 changes: 28 additions & 0 deletions src/hooks/useGetMapReplyList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useQuery } from '@tanstack/react-query';
import { getMapReplyList } from '@/service/MapLetter/getMapReplyList';
import { ReplyListResponseType } from '@/types/letter';

type MapReplyListRequestProps = {
letterId: number;
page?: number;
size?: number;
};

export const useGetMapReplyList = ({
letterId,
page,
size
}: MapReplyListRequestProps) => {
return useQuery<ReplyListResponseType, Error>({
queryKey: ['getMapReplyList', letterId, page, size],
queryFn: async () => {
const response = await getMapReplyList({
letterId,
page,
size
});
return response.result || { content: [] };
},
enabled: !!letterId
});
};
26 changes: 26 additions & 0 deletions src/service/MapLetter/getMapReplyList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { defaultApi } from '@/service/api';
import { ApiResponseType } from '@/types/apiResponse';
import { ReplyListResponseType } from '@/types/letter';

type MapReplyListRequestProps = {
letterId: number;
page?: number;
size?: number;
};

type MapReplyListResponse = ApiResponseType<ReplyListResponseType>;

export async function getMapReplyList({
letterId,
page,
size
}: MapReplyListRequestProps): Promise<MapReplyListResponse> {
const api = defaultApi();
const response = await api.get<MapReplyListResponse>(
`/map/${letterId}/reply`,
{
params: { page, size }
}
);
return response.data;
}
1 change: 0 additions & 1 deletion src/service/detail/getKeywordLetterDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ export async function getKeywordLetterDetail({
const response = await api.get<KeywordLetterDetailResponse>(
`/letters/detail/${letterId}`
);

return response.data;
}
4 changes: 2 additions & 2 deletions src/service/keyword/getKeywordReplyList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defaultApi } from '@/service/api';
import { ApiResponseType } from '@/types/apiResponse';
import { KeywordReplyListResponseType } from '@/types/letter';
import { ReplyListResponseType } from '@/types/letter';

type KeywordReplyListRequestProps = {
letterId: number;
Expand All @@ -9,7 +9,7 @@ type KeywordReplyListRequestProps = {
sort: string;
};

type KeywordReplyListResponse = ApiResponseType<KeywordReplyListResponseType>;
type KeywordReplyListResponse = ApiResponseType<ReplyListResponseType>;

export async function getKeywordReplyList({
letterId,
Expand Down
Loading

0 comments on commit 791ddda

Please sign in to comment.