-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from epigram5-9/feat/FE-18
FE-18 ✨ 최근 댓글 조회 기능 구현
- Loading branch information
Showing
6 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,13 @@ | ||
import type { GetRecentCommentsResponseType } from '@/schema/recentcomment'; | ||
import httpClient from './index'; | ||
|
||
const getRecentComments = async (): Promise<GetRecentCommentsResponseType> => { | ||
const response = await httpClient.get('/comments', { | ||
params: { | ||
limit: 3, | ||
}, | ||
}); | ||
return response.data; | ||
}; | ||
|
||
export default getRecentComments; |
This file contains 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 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,19 @@ | ||
import React from 'react'; | ||
import useGetRecentComments from '@/hooks/useGetRecentComments'; | ||
import CommentCard from '@/components/Card/CommentCard'; | ||
|
||
function RecentComments() { | ||
const { data, error, isLoading } = useGetRecentComments(); | ||
|
||
if (isLoading) return <p>로딩 중...</p>; | ||
if (error) return <p>{error.message}</p>; | ||
|
||
return ( | ||
<div> | ||
<h1>최신 댓글</h1> | ||
{data?.list.map((comment) => <CommentCard key={comment.id} writer={comment.writer} content={comment.content} createdAt={new Date(comment.createdAt)} status='view' />)} | ||
</div> | ||
); | ||
} | ||
|
||
export default RecentComments; |
This file contains 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,11 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import getRecentComments from '@/apis/getRecentComments'; | ||
import { GetRecentCommentsResponseType } from '@/schema/recentcomment'; | ||
|
||
const useGetRecentComments = () => | ||
useQuery<GetRecentCommentsResponseType, Error>({ | ||
queryKey: ['recentComments', 3], | ||
queryFn: getRecentComments, | ||
}); | ||
|
||
export default useGetRecentComments; |
This file contains 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,27 @@ | ||
import * as z from 'zod'; | ||
|
||
const WriterSchema = z.object({ | ||
image: z.string().url(), | ||
nickname: z.string(), | ||
id: z.number(), | ||
}); | ||
|
||
const CommentSchema = z.object({ | ||
epigramId: z.number(), | ||
writer: WriterSchema, | ||
updatedAt: z.coerce.date(), | ||
createdAt: z.coerce.date(), | ||
isPrivate: z.boolean(), | ||
content: z.string(), | ||
id: z.number(), | ||
}); | ||
|
||
export const GetRecentCommentsResponseSchema = z.object({ | ||
totalCount: z.number(), | ||
nextCursor: z.number(), | ||
list: z.array(CommentSchema), | ||
}); | ||
|
||
export type WriterType = z.infer<typeof WriterSchema>; | ||
export type CommentType = z.infer<typeof CommentSchema>; | ||
export type GetRecentCommentsResponseType = z.infer<typeof GetRecentCommentsResponseSchema>; |
This file contains 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,3 +1,8 @@ | ||
import { WriterType } from '@/schema/recentcomment'; | ||
|
||
export interface CommentCardProps { | ||
status: 'edit' | 'complete'; | ||
writer: WriterType; | ||
content: string; | ||
createdAt: Date; | ||
status?: 'view' | 'edit'; | ||
} |