Skip to content

Commit

Permalink
♻️ 채팅 리스트 페이지 코드 리팩토링 (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaeng committed Jan 21, 2025
1 parent 4f2ced4 commit 166a24a
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/pages/chatting/ChattingListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ import styled from 'styled-components';
import { useEffect } from 'react';
import { useInView } from 'react-intersection-observer';
import { ROUTE_PATH } from '@src/constants/routePath';
import { useDm } from '@src/hooks/query/useDm';
import { useGetMessageRoomList } from '@src/hooks/query/chat';
import useEncodedNavigation from '@src/hooks/useEncodedNavigate';
import { formatChatListItemTime } from '@src/utils/formatters';
import StatusBadgeListItem from '@src/components/common/StatusBadgeListItem';
import Header from '@src/components/common/Header';

const ChattingListPage = () => {
const navigate = useEncodedNavigation();
const { data, isFetchingNextPage, fetchNextPage, isLoading, hasNextPage } =
useDm();
useGetMessageRoomList();
const { ref, inView } = useInView();
const navigate = useEncodedNavigation();

const handleNavigateChattingRoom = (memberId: number) => {
navigate(ROUTE_PATH.dmChat, memberId);
};

useEffect(() => {
if (inView && !isLoading && hasNextPage) {
fetchNextPage();
}
}, [inView, isLoading, hasNextPage, fetchNextPage]);
if (!inView) return;

if (hasNextPage) fetchNextPage();
}, [inView, hasNextPage]);

return (
<>
<Header text='문자' headerType='hamburger' />
<Layout>
{data?.pages?.map((page) =>
{data?.map((page) =>
page.messageRooms.map((it) => (
<StatusBadgeListItem
key={it.messageRoomId}
Expand All @@ -37,12 +41,12 @@ const ChattingListPage = () => {
: '알 수 없음'
}
message={it.recentMessage}
isRead={false}
onClick={() => navigate(ROUTE_PATH.dmChat, it.memberId)}
isRead
onClick={() => handleNavigateChattingRoom(it.memberId)}
/>
)),
)}
{!isLoading && data?.pages?.length === 0 && (
{!isLoading && data?.length === 0 && (
<Wrapper>
<Span>주고 받은 문자가 없습니다.</Span>
</Wrapper>
Expand All @@ -63,7 +67,7 @@ export default ChattingListPage;
const Layout = styled.div`
display: flex;
flex-direction: column;
gap: 0.625rem;
gap: ${({ theme }) => theme.gap[10]};
height: calc(100% - 4.375rem);
padding: 0.9375rem;
Expand All @@ -76,6 +80,6 @@ const Wrapper = styled.div`
`;
const Span = styled.span`
margin: auto;
${({ theme }) => theme.fonts.body}
color: ${({ theme }) => theme.colors.neutral400};
`;

0 comments on commit 166a24a

Please sign in to comment.