Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/#187: 채널 보드 드래그앤 드랍 안되는 문제 해결 #189

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions __mocks__/handlers/boardHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ const boardsInfo: BoardsInfo = {
myMatchId: 0,
channelBoardLoadDtoList: [
{
boardId: 'aaa',
boardId: 111,
boardTitle: '공지사항',
boardIndex: 0,
},
{
boardId: 'bbb',
boardId: 222,
boardTitle: '게임 룰',
boardIndex: 1,
},
{
boardId: 'ccc',
boardId: 333,
boardTitle: '커뮤니티',
boardIndex: 2,
},
Expand All @@ -68,17 +68,17 @@ const boardsInfo: BoardsInfo = {
myMatchId: 1,
channelBoardLoadDtoList: [
{
boardId: 'bbb',
boardId: 222,
boardTitle: '리그 공지사항',
boardIndex: 0,
},
{
boardId: 'ccc',
boardId: 333,
boardTitle: '참여자 규칙',
boardIndex: 1,
},
{
boardId: 'ddd',
boardId: 444,
boardTitle: '참여하기',
boardIndex: 2,
},
Expand All @@ -89,17 +89,17 @@ const boardsInfo: BoardsInfo = {
myMatchId: 2,
channelBoardLoadDtoList: [
{
boardId: 'eee',
boardId: 333,
boardTitle: '리그 공지사항',
boardIndex: 0,
},
{
boardId: 'fff',
boardId: 444,
boardTitle: '참여자 규칙',
boardIndex: 1,
},
{
boardId: 'ggg',
boardId: 555,
boardTitle: '참여하기',
boardIndex: 2,
},
Expand Down
2 changes: 1 addition & 1 deletion src/@types/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface BoardInfo {
}

export interface Channels {
boardId: string;
boardId: number;
boardTitle: string;
boardIndex: number;
}
38 changes: 26 additions & 12 deletions src/components/Sidebar/BoardBar/BoardBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ const BoardBody = ({ channelLink }: Props) => {
if (boards === undefined) return;
const res = await postData(channelLink);
const newBoard: Channels = {
boardId: res.boardId.toString(),
boardId: res.boardId,
boardTitle: res.boardTitle,
boardIndex: res.boardIndex,
};
setBoards((prevBoards) => [...prevBoards, newBoard]);
selectBoardId(newBoard.boardId);
handleBoard(channelLink, newBoard.boardId, res.boardTitle);
selectBoardId(newBoard.boardId.toString());
handleBoard(channelLink, newBoard.boardId.toString(), res.boardTitle);
};

const postCustomBoard = async (customedBoards: Channels[]) => {
const res = await authAPI({
method: 'post',
url: `/api/channel/${channelLink}/order`,
data: {
channelBoardLoadDtoList: boards,
channelBoardLoadDtoList: customedBoards,
},
});

Expand All @@ -116,8 +116,9 @@ const BoardBody = ({ channelLink }: Props) => {
const newBoards = [...boards];
const [removed] = newBoards.splice(source.index, 1);
newBoards.splice(destination.index, 0, removed);
console.log(newBoards);
for (let i = 0; i < newBoards.length; i++) {
newBoards[i].boardIndex = i;
newBoards[i].boardIndex = i + 1;
}
postCustomBoard(newBoards);
};
Expand All @@ -135,11 +136,17 @@ const BoardBody = ({ channelLink }: Props) => {

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

useEffect(() => {
if (!boards.length || !data?.channelBoardLoadDtoList) return;
if (JSON.stringify(boards) === JSON.stringify(data.channelBoardLoadDtoList)) return;
setBoards(data.channelBoardLoadDtoList);
}, [data?.channelBoardLoadDtoList]);

useEffect(() => {
setBoards((prevBoards) => {
return prevBoards.map((board) => {
Expand Down Expand Up @@ -182,7 +189,7 @@ const BoardBody = ({ channelLink }: Props) => {
</div>
)}
<div>
<Title>보드 목록</Title>
<Title>대회 관리</Title>
{channelPermission === 0 && (
<Wrapper
isSelected={selected === 'admin'}
Expand All @@ -203,10 +210,15 @@ const BoardBody = ({ channelLink }: Props) => {
대진표
<Icon kind='lock' color='#637083' size='1.5rem' />
</Wrapper>
<Title>공지사항</Title>
{boards &&
boards.map((board, index) =>
channelPermission === 0 ? (
<Draggable key={board.boardId} draggableId={board.boardId} index={index}>
<Draggable
key={board.boardId}
draggableId={board.boardId.toString()}
index={index}
>
{(provided) => (
<Wrapper
ref={provided.innerRef}
Expand All @@ -215,7 +227,7 @@ const BoardBody = ({ channelLink }: Props) => {
data-id={board.boardId}
data-board-title={board.boardTitle}
onClick={onClickBoard}
isSelected={board.boardId === selected}
isSelected={board.boardId.toString() === selected}
>
{board.boardTitle}
<Icon kind='lock' color='#637083' size='1.5rem' />
Expand Down Expand Up @@ -264,11 +276,13 @@ const Wrapper = styled.li<{ isSelected: boolean }>`
align-items: center;
cursor: pointer;
&:hover {
background-color: #39587e;
background: linear-gradient(90deg, rgba(211, 250, 255, 0.3) 0%, rgba(211, 250, 255, 0) 128.25%);
}
color: white;

${({ isSelected }) => isSelected && `background-color: #39587E`};
${({ isSelected }) =>
isSelected &&
`background: linear-gradient(90deg, rgba(211, 250, 255, 0.30) 0%, rgba(211, 250, 255, 0.00) 128.25%)`};
`;

const CurrentRound = styled.div`
Expand Down
Loading