-
Notifications
You must be signed in to change notification settings - Fork 2
feat:랜덤 편지 + 편지 상세 1차 기능 구현 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
a621403
21f5479
f39cad4
ff7fe17
e7aa076
6824bf0
0d96316
b763c5f
a29ebfa
033ded0
5998700
5dc58dc
59415aa
35e9227
3128728
3937a0f
99c5ac4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import client from './client'; | ||
|
|
||
| const getRandomLetters = async ( | ||
| setRandomLettersState: React.Dispatch<React.SetStateAction<RandomLetters[]>>, | ||
| category: string | null, | ||
| ) => { | ||
| try { | ||
| const res = await client.get(`/api/random/${category}`); | ||
| if (!res) throw new Error('랜덤 편지 데이터를 가져오는 도중 에러가 발생했습니다.'); | ||
| setRandomLettersState(res.data.data); | ||
| console.log(res); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
|
|
||
| export { getRandomLetters }; |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { useNavigate } from 'react-router'; | ||
|
|
||
| import LetterWrapper from '@/components/LetterWrapper'; | ||
|
|
||
| // import letterPink from '@/assets/images/letter-pink.png'; | ||
|
|
||
| export default function CoolTime({ | ||
| setCoolTime, | ||
| }: { | ||
| setCoolTime: React.Dispatch<React.SetStateAction<boolean>>; | ||
| }) { | ||
| const navigate = useNavigate(); | ||
|
|
||
| const TIME_STAMP = '2025-02-26T22:13:25.262045608'; | ||
|
|
||
| const COMPLETED_DATE = new Date(TIME_STAMP); | ||
|
|
||
| const END_DATE = new Date(COMPLETED_DATE); | ||
| END_DATE.setHours(COMPLETED_DATE.getHours() + 1); | ||
|
|
||
| const NOW_DATE = new Date(); | ||
|
|
||
| const endTime = END_DATE.getTime() - NOW_DATE.getTime(); | ||
|
|
||
| const [endTimes, setEndTimes] = useState({ | ||
| hours: Math.floor((endTime / (1000 * 60 * 60)) % 24), | ||
| minutes: Math.floor((endTime / (1000 * 60)) % 60), | ||
| seconds: Math.floor((endTime / 1000) % 60), | ||
| }); | ||
|
|
||
| const formatNumber = (num: number) => { | ||
| return num.toString().padStart(2, '0'); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (endTimes.hours < 0 || endTimes.minutes < 0 || endTimes.seconds < 0) { | ||
| setEndTimes({ hours: 0, minutes: 0, seconds: 0 }); | ||
| } | ||
| if (endTimes.hours === 0 && endTimes.minutes === 0 && endTimes.seconds === 0) { | ||
| setCoolTime(false); | ||
| return; | ||
| } | ||
| const endTimeFlow = setInterval(() => { | ||
| setEndTimes((currentTime) => { | ||
| if (currentTime.seconds > 0) { | ||
| return { ...currentTime, seconds: currentTime.seconds - 1 }; | ||
| } // | ||
| else { | ||
| if (currentTime.minutes > 0) { | ||
| return { ...currentTime, minutes: currentTime.minutes - 1, seconds: 59 }; | ||
| } // | ||
| else { | ||
| if (currentTime.hours > 0) { | ||
| return { hours: currentTime.hours - 1, minutes: 59, seconds: 59 }; | ||
| } // | ||
| else { | ||
| setCoolTime(false); | ||
| return { ...currentTime }; | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| if (endTimes.hours === 0 && endTimes.minutes === 0 && endTimes.seconds === 0) { | ||
| clearInterval(endTimeFlow); | ||
| } | ||
| }, 1000); | ||
|
|
||
| return () => { | ||
| clearInterval(endTimeFlow); | ||
| }; | ||
| }, [endTimes, setCoolTime]); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lint가 그렇게 하라고 하네요...😅 저도 왜 넣어야하는진 모르겠지만 일단 넣었습니당 ㅎ..
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useEffect에 상태값이 들어가면 무조건 dependency에 넣으라고 하더라구용
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 알겠습니당! |
||
| return ( | ||
| <div className="mt-20 flex flex-col items-center justify-center"> | ||
| <div className="body-m flex flex-col items-center justify-center"> | ||
| <p className="text-gray-60">랜덤 편지 활성화 까지</p> | ||
| <p className="text-gray-80"> | ||
| {formatNumber(endTimes.hours)} : {formatNumber(endTimes.minutes)} :{' '} | ||
| {formatNumber(endTimes.seconds)} | ||
| </p> | ||
| <div className="mt-2 w-75"> | ||
| <LetterWrapper> | ||
| <div className="flex h-50 w-full max-w-[300px] flex-col gap-[35px] p-4"></div> | ||
| </LetterWrapper> | ||
| </div> | ||
| <button | ||
| className="bg-primary-3 body-m mt-12.5 w-full rounded-lg py-2" | ||
| onClick={() => { | ||
| navigate('/'); | ||
| }} | ||
| > | ||
| 홈으로 돌아가기 | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘 쓸게요 😇😇