diff --git a/src/apis/getTodayEpigram.ts b/src/apis/getTodayEpigram.ts new file mode 100644 index 00000000..17eb6aa0 --- /dev/null +++ b/src/apis/getTodayEpigram.ts @@ -0,0 +1,9 @@ +import type { EpigramType } from '@/schema/todayepigram'; +import httpClient from './index'; + +const getTodayEpigram = async (): Promise => { + const response = await httpClient.get('/epigrams/today'); + return response.data; +}; + +export default getTodayEpigram; diff --git a/src/components/Card/EpigramCard.tsx b/src/components/Card/EpigramCard.tsx index 6fb71f86..48d5ae56 100644 --- a/src/components/Card/EpigramCard.tsx +++ b/src/components/Card/EpigramCard.tsx @@ -1,9 +1,18 @@ import React from 'react'; -// figma 상으로는 sm ~ 3xl 사이즈로 구현되어 있는데, tailwind 환경을 반영해 -// base ~ 2xl 으로 정의했습니다. +interface Tag { + name: string; + id: number; +} + +interface EpigramCardProps { + content: string; + author: string; + tags: Tag[]; +} + const sizeStyles = { - base: 'w-[286px] max-h-[132px]', + xs: 'w-[286px] max-h-[132px]', sm: 'sm:w-[312px] sm:max-h-[152px]', md: 'md:w-[384px] md:max-h-[180px]', lg: 'lg:w-[540px] lg:max-h-[160px]', @@ -12,7 +21,7 @@ const sizeStyles = { }; const textSizeStyles = { - base: 'text-xs', + xs: 'text-xs', sm: 'sm:text-sm', md: 'md:text-base', lg: 'lg:text-xl', @@ -20,38 +29,36 @@ const textSizeStyles = { '2xl': '2xl:text-2xl', }; -function EpigramCard() { +function EpigramCard({ content, author, tags }: EpigramCardProps) { return ( -
+
{/* eslint-disable-next-line */}
{/* 줄무늬를 만들려면 비어있는 div가 필요합니다. */}
- 오랫동안 꿈을 그리는 사람은 마침내 그 꿈을 닮아 간다. + {content}
- - 앙드레 말로 - + - {author} -
-
- #나아가야할때 -
-
- #꿈을이루고싶을때 -
+ {tags.map((tag) => ( +
+ #{tag.name} +
+ ))}
); diff --git a/src/components/main/TodayEpigram.tsx b/src/components/main/TodayEpigram.tsx new file mode 100644 index 00000000..f9b49b0b --- /dev/null +++ b/src/components/main/TodayEpigram.tsx @@ -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

로딩 중...

; + if (error) return

{error.message}

; + if (!epigram) return

오늘의 에피그램이 없습니다.

; + + return ; +} + +export default TodayEpigram; diff --git a/src/hooks/useGetTodayEpigram.ts b/src/hooks/useGetTodayEpigram.ts new file mode 100644 index 00000000..e40c5aac --- /dev/null +++ b/src/hooks/useGetTodayEpigram.ts @@ -0,0 +1,11 @@ +import { useQuery } from '@tanstack/react-query'; +import getTodayEpigram from '@/apis/getTodayEpigram'; +import { EpigramType } from '@/schema/todayepigram'; + +const useGetTodayEpigram = () => + useQuery({ + queryKey: ['epigram'], + queryFn: getTodayEpigram, + }); + +export default useGetTodayEpigram; diff --git a/src/schema/todayepigram.ts b/src/schema/todayepigram.ts new file mode 100644 index 00000000..2e8fbb0b --- /dev/null +++ b/src/schema/todayepigram.ts @@ -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; +export type EpigramType = z.infer;