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

Feat/#198: 채널 보드 삭제 기능 추가 #199

Merged
merged 4 commits into from
Oct 30, 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
3 changes: 0 additions & 3 deletions src/components/Content/ContentModify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ const ContentModify = ({ title, content, onUpdateContent }: ContentModifyProps)
<>
<TitleField placeholder={'제목을 입력해주세요'} defaultValue={title} ref={titleRef} />
<InputField placeholder={'텍스트를 입력해주세요'} defaultValue={content} ref={textRef} />
<ContentButton right='25' backgroundColor='#ff0044'>
삭제하기
</ContentButton>
<ContentButton
right='15'
backgroundColor='grey'
Expand Down
7 changes: 3 additions & 4 deletions src/components/Sidebar/BoardBar/BoardBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ 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 + 1;
}
Expand Down Expand Up @@ -146,13 +145,13 @@ const BoardBody = ({ channelLink }: Props) => {
if (JSON.stringify(boards) === JSON.stringify(data.channelBoardLoadDtoList)) return;
setBoards(data.channelBoardLoadDtoList);
}, [data?.channelBoardLoadDtoList]);

useEffect(() => {
setBoards((prevBoards) => {
return prevBoards.map((board) => {
if (board.boardId === selected) {
if (board.boardId.toString() === selected)
return { ...board, boardTitle: lastVisitedBoardIdLists[channelLink].boardTitle };
}

return board;
});
});
Expand Down
37 changes: 33 additions & 4 deletions src/pages/contents/[channelLink]/[boardId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface Content {
title: string;
content: string;
}
interface ContentButtonProps {
onClick?: () => void;
right?: string;
backgroundColor?: string;
}

const updateData = async (channelLink: string, boardId: string, updatedContent: Content) => {
const res = await authAPI({
Expand All @@ -22,6 +27,7 @@ const updateData = async (channelLink: string, boardId: string, updatedContent:
content: updatedContent.content,
},
});

return res;
};

Expand All @@ -39,7 +45,9 @@ const boardContents = () => {
method: 'get',
url: `/api/channel/${channelLink}/${boardId}`,
});

if (res.status !== 200) return router.push('/');

setContents(res.data);
};

Expand All @@ -49,16 +57,32 @@ const boardContents = () => {
content,
};
if (!channelLink) return;

const res = await updateData(channelLink as string, boardId as string, updatedContent);
if (res.status !== 200) {
alert('요청실패');
return;
}

setContents(updatedContent);
setIsModify(false);
handleBoard(channelLink as string, boardId as string, title);
};

const deleteBoard = async () => {
if (!confirm('공지를 삭제하시겠습니까?')) return;
const res = await authAPI({ method: 'delete', url: `/api/channel/${channelLink}/${boardId}` });

if (res.status !== 200) {
alert('서버 에러가 발생했습니다.');
return;
}

handleBoard(channelLink as string, '', '');

alert('정상적으로 처리되었습니다.');
};

useEffect(() => {
setIsModify(false);
if (!channelLink || !boardId) {
Expand Down Expand Up @@ -90,8 +114,12 @@ const boardContents = () => {
</div>
{channelPermission === 0 && (
<>
<ModifyButton>공지 삭제</ModifyButton>
<ModifyButton onClick={() => setIsModify(true)}>내용 수정</ModifyButton>
<ModifyButton right='15' backgroundColor='#ff0044' onClick={() => deleteBoard()}>
공지 삭제
</ModifyButton>
<ModifyButton backgroundColor='#0067a3' onClick={() => setIsModify(true)}>
내용 수정
</ModifyButton>
</>
)}
</>
Expand All @@ -117,16 +145,17 @@ const Title = styled.div`
border-bottom: 1px solid #d3d3d3;
`;

const ModifyButton = styled.button`
const ModifyButton = styled.button<ContentButtonProps>`
font-size: 2rem;
color: white;
background-color: #0067a3;
position: fixed;
bottom: 3rem;
right: 5rem;
border: none;
padding: 1rem;
border-radius: 1rem;
right: ${(props) => props.right + 'rem'};
background-color: ${(props) => props.backgroundColor};

&:hover {
cursor: pointer;
Expand Down