-
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 #61 from epigram5-9/feat/FE-15
FE-15 ✨ 오늘의 에피그램 조회 기능 구현
- Loading branch information
Showing
5 changed files
with
83 additions
and
20 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,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,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 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,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>; |