Skip to content

Commit

Permalink
feat 메일 크게보기 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seung365 committed Aug 8, 2024
1 parent 7da42e1 commit a1830be
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/pages/MyPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import {
Divider,
Button,
Spinner,
IconButton,
} from '@chakra-ui/react';
import { ChevronDownIcon, ChevronUpIcon } from '@chakra-ui/icons';
import { useGetMail } from '@/api/hooks/Mail/useGetMail';
import { useEffect, useState } from 'react';

export const MyPage = () => {
const { authInfo } = useAuth();
const [isJob, setIsJob] = useState('univ');
const [page, setPage] = useState(0);
const [expandedMails, setExpandedMails] = useState<{ [key: string]: boolean }>({});

const { mailData, mailLoading, mailError, refetch } = useGetMail(page, 5, isJob);

Expand All @@ -44,6 +47,13 @@ export const MyPage = () => {
setPage(0);
};

const toggleMailContent = (mailId: string) => {
setExpandedMails((prev) => ({
...prev,
[mailId]: !prev[mailId],
}));
};

return (
<Wrapper>
<LogoWrapper>
Expand Down Expand Up @@ -81,18 +91,30 @@ export const MyPage = () => {
) : mailError ? (
<Text>메일을 불러오는 중 오류가 발생했습니다.</Text>
) : mailData && mailData.content && mailData.content.length > 0 ? (
mailData.content.map((email, index) => (
<Box key={`${isJob}-${email.createDate}-${index}`} w="100%">
<HStack justify="space-between" mb={2}>
<Text fontWeight="bold">{email.subject}</Text>
<Text fontSize="sm" color="gray.500">
{email.createDate}
</Text>
</HStack>
<Text noOfLines={2}>{email.body}</Text>
<Divider mt={2} />
</Box>
))
mailData.content.map((email, index) => {
const mailId = `${isJob}-${email.createDate}-${index}`;
const isExpanded = expandedMails[mailId];
return (
<Box key={mailId} w="100%">
<HStack justify="space-between" mb={2}>
<Text fontWeight="bold">{email.subject}</Text>
<HStack>
<Text fontSize="sm" color="gray.500">
{email.createDate}
</Text>
<IconButton
aria-label={isExpanded ? 'Collapse' : 'Expand'}
icon={isExpanded ? <ChevronUpIcon /> : <ChevronDownIcon />}
size="sm"
onClick={() => toggleMailContent(mailId)}
/>
</HStack>
</HStack>
<Text noOfLines={isExpanded ? undefined : 2}>{email.body}</Text>
<Divider mt={2} />
</Box>
);
})
) : (
<Text>메일이 없습니다!</Text>
)}
Expand Down

0 comments on commit a1830be

Please sign in to comment.