Skip to content

Commit 0b47e49

Browse files
authored
feat: 오고 있는 편지 조회 기능 구현 (mock api) (#36)
* style: 홈 페이지 eslint 오류 해결 * remove: 사용하지 않는 파일 삭제 * feat: 오고 있는 편지 조회 mock api 연결 * feat: 오고 있는 편지 클릭 시 편지 상세 페이지로 이동 * feat: 편지 목록 높이 자동 조정 및 스크롤 기능 추가 * fix: 랜덤 응원 메시지 모달 위로 뜨는 오류 해결 * fix: 오고 있는 편지 클릭 시 편지 미리보기로 이동하는 라우팅 오류 해결 * feat: 오고 있는 편지 목록에서 시간이 다 된 항목을 자동으로 삭제하는 기능 추가 * refactor: 오고 있는 편지 파일 구조 수정 * style: 오고 있는 편지 함수 선언을 화살표 함수로 변환 * feat: 새로 도착한 편지 개수 계산 구현
1 parent 645c527 commit 0b47e49

16 files changed

+157
-50
lines changed

src/apis/incomingLetters.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { client } from '@/apis/client';
2+
3+
export const fetchIncomingLettersApi = async (token: string) => {
4+
try {
5+
const { data } = await client.get('/api/letters?status=delivery', {
6+
headers: {
7+
Authorization: `Bearer ${token}`,
8+
},
9+
});
10+
console.log('불러온 데이터', data);
11+
return data;
12+
} catch (error) {
13+
console.error('❌오고 있는 편지 목록을 불러오던 중 에러 발생', error);
14+
throw error;
15+
}
16+
};

src/pages/Home/components/FloatingLetters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useEffect, useRef } from 'react';
21
import gsap from 'gsap';
2+
import { useEffect, useRef } from 'react';
3+
34
import letter1 from '@/assets/images/letter-1.png';
45
import letter2 from '@/assets/images/letter-2.png';
56
import letter3 from '@/assets/images/letter-3.png';

src/pages/Home/components/GoToLetterBoard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Link } from 'react-router';
2+
23
import goToLetterBoard from '@/assets/images/go-to-letter-board.png';
34

45
const GoToLetterBoard = () => {

src/pages/Home/components/GoToLetterBox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Link } from 'react-router';
2+
23
import goToLetterBoxNewLetters from '@/assets/images/go-to-letter-box-new-letters.png';
34
import goToLetterBox from '@/assets/images/go-to-letter-box.png';
45

56
const GoToLetterBox = () => {
67
//TODO : hasNewLetters 전역으로 상태 관리하기
7-
let hasNewLetters = true;
8+
const hasNewLetters = true;
89
return (
910
<div className="absolute bottom-10 left-5 z-9 flex w-fit">
1011
<div className="text-left">

src/pages/Home/components/GoToRandomLetter.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Link } from 'react-router';
2+
23
import goToRandomLetter from '@/assets/images/go-to-random-letter.png';
34

45
const GoToRandomLetter = () => {

src/pages/Home/components/HomeBackgroundLeft.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import BackgroundImageWrapper from '@/components/BackgroundImageWrapper';
21
import homeLeftMountain from '@/assets/images/home-left-mountain.png';
2+
import BackgroundImageWrapper from '@/components/BackgroundImageWrapper';
33

44
const HomeBackgroundLeft = () => {
55
return (

src/pages/Home/components/HomeBackgroundRightBottom.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import BackgroundImageWrapper from '@/components/BackgroundImageWrapper';
21
import homeRightMountainBottom from '@/assets/images/home-right-mountain-bottom.png';
2+
import BackgroundImageWrapper from '@/components/BackgroundImageWrapper';
3+
34
const HomeBackgroundRightBottom = () => {
45
return (
56
<BackgroundImageWrapper

src/pages/Home/components/HomeBackgroundRightTop.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import BackgroundImageWrapper from '@/components/BackgroundImageWrapper';
21
import homeRightMountainTop from '@/assets/images/home-right-mountain-top.png';
2+
import BackgroundImageWrapper from '@/components/BackgroundImageWrapper';
33
const HomeBackgroundRightTop = () => {
44
return (
55
<BackgroundImageWrapper

src/pages/Home/components/HomeLeft.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import RandomCheer from './RandomCheer';
2-
import GoToWrite from './GoToWrite';
31
import GoToRandomLetter from './GoToRandomLetter';
2+
import GoToWrite from './GoToWrite';
3+
import RandomCheer from './RandomCheer';
44

55
const HomeLeft = () => {
66
return (

src/pages/Home/components/HomeRight.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1+
import { useEffect } from 'react';
2+
3+
import { useIncomingLettersStore } from '@/stores/incomingLettersStore';
4+
15
import FloatingLetters from './FloatingLetters';
26
import GoToLetterBoard from './GoToLetterBoard';
37
import GoToLetterBox from './GoToLetterBox';
48
import NewLetterModal from './NewLetterModal';
59

610
const HomeRight = () => {
7-
//TODO : hasNewLetters 전역으로 상태 관리할지
8-
let hasNewLetters = true;
11+
const { arrivedCount, fetchIncomingLetters } = useIncomingLettersStore();
12+
useEffect(() => {
13+
fetchIncomingLetters();
14+
}, []);
915

1016
return (
1117
<div className="flex h-screen w-full max-w-150 min-w-[300px] flex-shrink-0 grow snap-start flex-col items-center overflow-x-hidden pt-5">
12-
{hasNewLetters && <FloatingLetters />}
18+
{arrivedCount !== 0 && <FloatingLetters />}
1319
<GoToLetterBox />
1420
<GoToLetterBoard />
15-
{hasNewLetters && <NewLetterModal />}
21+
{arrivedCount !== 0 && <NewLetterModal />}
1622
</div>
1723
);
1824
};

0 commit comments

Comments
 (0)