Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/apis/unreadLetters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import client from './client';

export interface UnreadLetters {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface엔 export가 없어도 될 거 같습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

만약 다른 컴포넌트에서도 타입이 사용되는거라면 d.ts 파일에 들어가면 좋을거 같습니당

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그렇네요 그렇게 수정하겠습니다!

data: number;
message: string;
timestamp: string;
}

export const getUnreadLettersCount = async (): Promise<UnreadLetters> => {
try {
const response = await client.get('/api/letters/unread/count');
console.log('📩 안 읽은 편지 개수 데이터', response);
return response.data;
} catch (error) {
console.error('❌안 읽은 편지 개수를 받아오던 중 에러가 발생했습니다', error);
throw new Error('안 읽은 편지 개수 조회 실패');
}
};
19 changes: 14 additions & 5 deletions src/pages/Home/components/HomeRight.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { useEffect } from 'react';
import { useEffect, useState } from 'react';

import { useIncomingLettersStore } from '@/stores/incomingLettersStore';
import { getUnreadLettersCount } from '@/apis/unreadLetters';

import FloatingLetters from './FloatingLetters';
import GoToLetterBoard from './GoToLetterBoard';
import GoToLetterBox from './GoToLetterBox';
import NewLetterModal from './NewLetterModal';

const HomeRight = () => {
const { arrivedCount, fetchIncomingLetters } = useIncomingLettersStore();
const [arrivedCount, setArrivedCount] = useState<number>(0);

useEffect(() => {
fetchIncomingLetters();
}, [fetchIncomingLetters]);
const fetchUnreadCount = async () => {
try {
const result = await getUnreadLettersCount();
setArrivedCount(result.data);
} catch (error) {
console.error('❌ 안 읽은 편지 개수를 불러오는 데 실패했습니다:', error);
}
};
fetchUnreadCount();
}, []);

return (
<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">
Expand Down
19 changes: 16 additions & 3 deletions src/pages/Home/components/NewLetterModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { useIncomingLettersStore } from '@/stores/incomingLettersStore';
import { useEffect, useState } from 'react';

import { getUnreadLettersCount } from '@/apis/unreadLetters';

//TODO: 내 편지함 상세 조회에서 해당 편지를 조회하면 arrivedCount가 1 감소하도록
const NewLetterModal = () => {
const arrivedCount = useIncomingLettersStore((state) => state.arrivedCount);
const [arrivedCount, setArrivedCount] = useState<number>(0);

useEffect(() => {
const fetchUnreadCount = async () => {
try {
const result = await getUnreadLettersCount();
setArrivedCount(result.data);
} catch (error) {
console.error('❌ 안 읽은 편지 개수를 불러오는 데 실패했습니다:', error);
}
};
fetchUnreadCount();
}, []);

return (
<p className="text-gray-60 body-b absolute top-30 mb-10 w-fit animate-pulse rounded-full bg-white px-6 py-4">
Expand Down