-
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 branch 'epic/FE-13--main-page' into feat/FE-17
- Loading branch information
Showing
10 changed files
with
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { EpigramType } from '@/schema/todayepigram'; | ||
import httpClient from './index'; | ||
|
||
const getTodayEpigram = async (): Promise<EpigramType> => { | ||
const response = await httpClient.get('/epigrams/today'); | ||
return response.data; | ||
}; | ||
|
||
export default getTodayEpigram; |
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,15 @@ | ||
import React from 'react'; | ||
import useGetTodayEpigram from '@/hooks/useGetTodayEpigram'; | ||
import EpigramCard from '@/components/Card/EpigramCard'; | ||
|
||
function TodayEpigram() { | ||
const { data: epigram, error, isLoading } = useGetTodayEpigram(); | ||
|
||
if (isLoading) return <p>로딩 중...</p>; | ||
if (error) return <p>{error.message}</p>; | ||
if (!epigram) return <p>오늘의 에피그램이 없습니다.</p>; | ||
|
||
return <EpigramCard content={epigram.content} author={epigram.author} tags={epigram.tags} />; | ||
} | ||
|
||
export default TodayEpigram; |
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,11 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import getTodayEpigram from '@/apis/getTodayEpigram'; | ||
import { EpigramType } from '@/schema/todayepigram'; | ||
|
||
const useGetTodayEpigram = () => | ||
useQuery<EpigramType, Error>({ | ||
queryKey: ['epigram'], | ||
queryFn: getTodayEpigram, | ||
}); | ||
|
||
export default useGetTodayEpigram; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as z from 'zod'; | ||
|
||
const TagSchema = z.object({ | ||
name: z.string(), | ||
id: z.number(), | ||
}); | ||
|
||
export const EpigramSchema = z.object({ | ||
likeCount: z.number(), | ||
tags: z.array(TagSchema), | ||
writerId: z.number(), | ||
referenceUrl: z.string().url(), | ||
referenceTitle: z.string(), | ||
author: z.string(), | ||
content: z.string(), | ||
id: z.number(), | ||
isLiked: z.boolean(), | ||
}); | ||
|
||
export type TagType = z.infer<typeof TagSchema>; | ||
export type EpigramType = z.infer<typeof EpigramSchema>; |
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'; | ||
} |