|
| 1 | +import { useEffect, useState } from 'react'; |
| 2 | + |
| 3 | +import { getMailbox } from '@/apis/mailBox'; |
1 | 4 | import DoorImg from '@/assets/images/door.png'; |
| 5 | +import ClosedWindowImg from '@/assets/images/window-disabled.png'; |
2 | 6 | import PageTitle from '@/components/PageTitle'; |
3 | 7 | import { chunkBox } from '@/utils/chunkBox'; |
4 | 8 |
|
5 | 9 | import LetterBoxItem from './components/LetterBoxItem'; |
6 | 10 |
|
7 | | -const DUMMY_COUNT = 200; |
8 | | - |
| 11 | +interface LetterBoxData { |
| 12 | + letterMatchingId: number; |
| 13 | + oppositeZipCode: string; |
| 14 | + active: boolean; |
| 15 | + oppositeRead: boolean; |
| 16 | + // totalLetters: number; |
| 17 | +} |
9 | 18 | const LetterBoxPage = () => { |
| 19 | + const [letterBox, setLetterBox] = useState<LetterBoxData[]>([]); |
| 20 | + |
| 21 | + const fetchMailLists = async () => { |
| 22 | + try { |
| 23 | + const response = await getMailbox(); |
| 24 | + if (!response) throw new Error(); |
| 25 | + const data: LetterBoxData[] = response.data; |
| 26 | + // 정렬? |
| 27 | + setLetterBox(data); |
| 28 | + } catch (error) { |
| 29 | + console.error(error); |
| 30 | + } |
| 31 | + }; |
| 32 | + useEffect(() => { |
| 33 | + fetchMailLists(); |
| 34 | + }, []); |
| 35 | + |
10 | 36 | return ( |
11 | 37 | <main className="flex grow flex-col items-center px-5 pt-20"> |
12 | 38 | <PageTitle>내 편지함</PageTitle> |
13 | 39 | <div className="w-full max-w-94"> |
14 | 40 | <p className="body-sb mt-16 mb-[7px] place-self-start text-gray-50"> |
15 | | - 나와 연락한 사람들 {DUMMY_COUNT} |
| 41 | + 나와 연락한 사람들 {letterBox?.length} |
16 | 42 | </p> |
17 | 43 | <section className="letter-box-bg flex grow flex-col items-center px-4 pt-5"> |
18 | 44 | <div className="flex w-full flex-col gap-5"> |
19 | | - {chunkBox( |
20 | | - Array.from({ length: 12 }).map((_, index) => ( |
21 | | - <LetterBoxItem |
22 | | - key={index} |
23 | | - zipCode="12E12" |
24 | | - letterCount={90} |
25 | | - isChecked={index % 2 === 0} |
26 | | - /> |
27 | | - )), |
28 | | - ).map((row, index) => ( |
29 | | - <div key={index} className="flex justify-between"> |
30 | | - {row} |
31 | | - </div> |
32 | | - ))} |
| 45 | + {letterBox.length > 0 ? ( |
| 46 | + chunkBox( |
| 47 | + letterBox.map((data: LetterBoxData, index) => ( |
| 48 | + <LetterBoxItem |
| 49 | + boxId={data.letterMatchingId} |
| 50 | + key={index} |
| 51 | + zipCode={data.oppositeZipCode} |
| 52 | + letterCount={90} |
| 53 | + isChecked={data.oppositeRead} |
| 54 | + isClosed={data.active} |
| 55 | + /> |
| 56 | + )), |
| 57 | + ).map((row, index) => |
| 58 | + row.length === 3 ? ( |
| 59 | + <div key={index} className="flex justify-between"> |
| 60 | + {row} |
| 61 | + </div> |
| 62 | + ) : ( |
| 63 | + <div key={index} className="flex justify-between"> |
| 64 | + {row} |
| 65 | + <img src={ClosedWindowImg} alt="닫힌 문 이미지" className="h-28 w-23" /> |
| 66 | + {row.length === 1 && ( |
| 67 | + <img src={ClosedWindowImg} alt="닫힌 문 이미지" className="h-28 w-23" /> |
| 68 | + )} |
| 69 | + </div> |
| 70 | + ), |
| 71 | + ) |
| 72 | + ) : ( |
| 73 | + <p className="body-m text-gray-60 text-center">아직 주고 받은 편지가 없어요</p> |
| 74 | + )} |
33 | 75 | <div className="flex justify-between"> |
34 | | - <LetterBoxItem zipCode="12E12" letterCount={90} isClosed /> |
| 76 | + <img src={ClosedWindowImg} alt="닫힌 문 이미지" className="h-28 w-23" /> |
35 | 77 | <img src={DoorImg} alt="출입문 이미지" /> |
36 | | - <LetterBoxItem zipCode="12E12" letterCount={90} isClosed /> |
| 78 | + <img src={ClosedWindowImg} alt="닫힌 문 이미지" className="h-28 w-23" /> |
37 | 79 | </div> |
38 | 80 | </div> |
39 | 81 | </section> |
|
0 commit comments