Skip to content

Commit

Permalink
Fix: 채널 보드 조회 안되는 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pp449 committed Oct 8, 2023
1 parent 6dfd893 commit 7f0d387
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/components/Sidebar/BoardBar/BoardBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const postData = async (channelLink: string) => {

const BoardBody = ({ channelLink }: Props) => {
const [selected, setSelected] = useState<string>('');
const [boards, setBoards] = useState<Channels[]>();
const [boards, setBoards] = useState<Channels[]>([]);
const router = useRouter();

const { data, isSuccess } = useQuery(['getBoardLists', channelLink], () =>
Expand Down Expand Up @@ -89,7 +89,7 @@ const BoardBody = ({ channelLink }: Props) => {
boardTitle: res.boardTitle,
boardIndex: res.boardIndex,
};
setBoards([...boards, newBoard]);
setBoards((prevBoards) => [...prevBoards, newBoard]);
selectBoardId(newBoard.boardId);
handleBoard(channelLink, newBoard.boardId, res.boardTitle);
};
Expand Down Expand Up @@ -126,19 +126,19 @@ const BoardBody = ({ channelLink }: Props) => {

useEffect(() => {
const lastVisitBoardId = lastVisitedBoardIdLists[channelLink]?.boardId;
if (isSuccess) setBoards(data.channelBoardLoadDtdList);
if (data) setBoards(data.channelBoardLoadDtdList);

if (lastVisitBoardId) {
selectBoardId(lastVisitBoardId);
return;
}

if (isSuccess) {
if (data) {
const tmpBoards = data.channelBoardLoadDtdList;
selectBoardId(tmpBoards[0].boardId);
handleBoard(channelLink, tmpBoards[0].boardId, tmpBoards[0].boardTitle);
}
}, [channelLink, isSuccess]);
}, [channelLink, data]);

return (
<Container>
Expand Down

0 comments on commit 7f0d387

Please sign in to comment.