Skip to content

Commit

Permalink
Merge pull request #95 from Na-o-man/feat/#87
Browse files Browse the repository at this point in the history
feat:안건 목록 조회 url 수정
  • Loading branch information
eomseona authored Aug 22, 2024
2 parents 2bf41ba + 55c7da7 commit 7595e6b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/components/Vote/VoteList/VoteList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import * as S from './Styles';
import VoteContainer from '../VoteContainer/VoteContainer';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useLocation } from 'react-router-dom';
import { useRecoilState, useRecoilValue } from 'recoil';
import { agendasList } from 'recoil/states/vote';
import axios from 'axios';
Expand All @@ -13,6 +13,7 @@ const token = getCookie('access-token');

const VoteList: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();
const groupId = useRecoilValue(shareGroupId);
const [agendas, setAgendas] = useRecoilState(agendasList);
const [currentPage, setCurrentPage] = useState(0);
Expand All @@ -39,9 +40,19 @@ const VoteList: React.FC = () => {
},
});
const { agendaDetailInfoList, totalPages } = response.data.data;
console.log('Fetched Agendas:', agendaDetailInfoList);
setAgendas((prevAgendas) => [...prevAgendas, ...agendaDetailInfoList]); // 기존 데이터에 추가

if (agendaDetailInfoList.length === 0) {
// 안건이 없는 경우 /vote 페이지로 이동
navigate('/vote', { replace: true });
return;
}

// 안건이 있는 경우 상태 업데이트 및 /vote/list로 이동
setAgendas((prevAgendas) => [...prevAgendas, ...agendaDetailInfoList]);
setTotalPages(totalPages);
if (location.pathname !== '/vote/list') {
navigate('/vote/list', { replace: true });
}
} catch (error: any) {
setError(error.message || 'Error fetching data');
} finally {
Expand All @@ -50,8 +61,11 @@ const VoteList: React.FC = () => {
};

useEffect(() => {
fetchAgendas(currentPage);
}, [groupId, currentPage]);
// 새로운 그룹을 선택할 때마다 기존 안건 목록 초기화 및 첫 페이지 호출
setAgendas([]);
setCurrentPage(0);
fetchAgendas(0);
}, [groupId]);

const handleScroll = () => {
if (
Expand Down

0 comments on commit 7595e6b

Please sign in to comment.