From 6b81c57c0602a1a321fbca748d27fb58ee7030ac Mon Sep 17 00:00:00 2001 From: amaran-th Date: Wed, 1 Jun 2022 04:41:43 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=EA=B2=8C=EC=8B=9C=EA=B8=80=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=88=98=EC=A0=95=20=EA=B4=80=EB=A0=A8=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #100 --- src/API/v1/comment.js | 3 +- src/API/v1/post.js | 24 ++++-- src/page/Board/Components/FilesUploadForm.jsx | 78 ++++++++++++++----- src/page/Board/Components/TextEditer.jsx | 21 ++++- 4 files changed, 96 insertions(+), 30 deletions(-) diff --git a/src/API/v1/comment.js b/src/API/v1/comment.js index 6bdf6662..998d4fda 100644 --- a/src/API/v1/comment.js +++ b/src/API/v1/comment.js @@ -2,11 +2,10 @@ import axios from 'axios'; const API_URL = process.env.REACT_APP_API_URL; -async function create({ boardId, content, ipAddress, parentId, token }) { +async function create({ boardId, content, parentId, token }) { const url = API_URL + '/v1/comment/' + boardId; const data = { content, - ipAddress, parentId, }; const options = { diff --git a/src/API/v1/post.js b/src/API/v1/post.js index d9795ba6..81cc06ed 100644 --- a/src/API/v1/post.js +++ b/src/API/v1/post.js @@ -6,7 +6,6 @@ async function create({ title, content, categoryId, - ipAddress, allowComment, isNotice, isSecret, @@ -20,7 +19,6 @@ async function create({ formData.append('title', title); formData.append('content', content); formData.append('categoryId', categoryId); - formData.append('ipAddress', ipAddress); formData.append('allowComment', allowComment); formData.append('isNotice', isNotice); formData.append('isSecret', isSecret); @@ -129,7 +127,6 @@ async function modify({ title, content, categoryId, - ipAddress, allowComment, isNotice, isSecret, @@ -143,7 +140,6 @@ async function modify({ formData.append('title', title); formData.append('content', content); formData.append('categoryId', categoryId); - formData.append('ipAddress', ipAddress); formData.append('allowComment', allowComment); formData.append('isNotice', isNotice); formData.append('isSecret', isSecret); @@ -167,10 +163,25 @@ async function modify({ ); return response.data; } catch (error) { - return error.response.data; + return error.response?.data; + } +} +async function deleteFiles({ fileIdList, token }) { + const options = { + method: 'DELETE', + url: API_URL + '/v1/post/files', + params: { fileIdList: fileIdList.join(',') }, + headers: { + Authorization: `${token}`, + }, + }; + try { + const response = await axios(options); + return response.data; + } catch (error) { + return error.response?.data; } } - async function remove({ boardId, token }) { const options = { method: 'DELETE', @@ -259,6 +270,7 @@ export default { getNoticeList, downloadFile, modify, + deleteFiles, remove, search, like, diff --git a/src/page/Board/Components/FilesUploadForm.jsx b/src/page/Board/Components/FilesUploadForm.jsx index 545834b2..ec90e271 100644 --- a/src/page/Board/Components/FilesUploadForm.jsx +++ b/src/page/Board/Components/FilesUploadForm.jsx @@ -7,7 +7,6 @@ import { formatFileSize } from '../BoardUtil'; const getFileIcon = (filename) => { const extension = filename?.split('.')[1]; - try { return ( { } }; -const FilesUploadForm = (props) => { - const [files, setFiles] = useState([]); - +const FilesUploadForm = ({ + files, + setFiles, + modifyFlag, + deleteFileIdList, + setDeleteFileIdList, + originFiles, + setOriginFile, +}) => { + const deleteOriginClickHandler = (id) => { + setOriginFile(originFiles.filter((file) => file.id !== id)); + setDeleteFileIdList([...deleteFileIdList, id]); //지울 파일 리스트에 아이디 추가 + }; + const getFileInfoOrigin = (file) => { + //기존에 첨부되어 있던 파일의 상세 정보 display + return ( + + + {getFileIcon(file.fileName)} + {file.fileName} + + {formatFileSize(file.fileSize)} + + + + + ); + }; const deleteClickHandler = (fileName) => { - props.setFiles(files.filter((file) => file.name !== fileName)); setFiles(files.filter((file) => file.name !== fileName)); }; - const getFileInfo = (file) => { + //새로 첨부한 파일의 상세 정보 display return ( @@ -52,21 +78,26 @@ const FilesUploadForm = (props) => { }; useEffect(() => { - console.log(files); - }, [files]); + console.log('origin:', originFiles); + console.log('new:', files); + }, [files, originFiles]); useEffect(() => { - if (props.modifyFlag) { - console.log(props.board.files); - //setFiles(props.board.files); + if (modifyFlag) { + //console.log('origin:', props.board.files); + //props.setOriginFiles(props.board.files); } }, []); const onDrop = useCallback( (acceptedFiles) => { - var temp = [...files]; + var temp = [...originFiles, ...files]; + console.log(originFiles); + console.log(temp); var realAddFiles = []; //최종적으로 추가될 파일 var notAddFiles = []; //중복된 파일 acceptedFiles.forEach((newFile) => { - const isRepeat = temp.filter((file) => file.name == newFile.name); + const isRepeat = temp.filter( + (file) => file.name == newFile.name || file.fileName == newFile.name + ); if (isRepeat.length != 0) { //console.log('중복'); notAddFiles = [...notAddFiles, newFile]; @@ -106,7 +137,6 @@ const FilesUploadForm = (props) => { ') 기존 파일을 삭제하고 새로 업로드 해주십시오.' ); } - props.setFiles([...files, ...realAddFiles]); setFiles([...files, ...realAddFiles]); }, [files] @@ -121,13 +151,15 @@ const FilesUploadForm = (props) => { <> From 2f6805b7cb4ffda25c9f3ce5c30eca845b8cc7fb Mon Sep 17 00:00:00 2001 From: amaran-th Date: Wed, 1 Jun 2022 06:16:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 게시글목록의 행 및 카드를 함수화함 #108 --- src/page/Board/Components/Gallary.jsx | 268 ++++++++++---------------- src/page/Board/Components/Table.jsx | 260 +++++++++---------------- 2 files changed, 193 insertions(+), 335 deletions(-) diff --git a/src/page/Board/Components/Gallary.jsx b/src/page/Board/Components/Gallary.jsx index 380a7347..52b407a7 100644 --- a/src/page/Board/Components/Gallary.jsx +++ b/src/page/Board/Components/Gallary.jsx @@ -21,111 +21,119 @@ import { const Gallary = ({ notices, boards, linkHandler, state }) => { const { categoryId } = useParams(); const [thumbnails, setThumbnails] = []; + const card = (board, index, isN) => { + return ( +
+ { + if ( + board.isSecret && + board.writerId != state.member?.memberInfo?.id + ) + linkHandler(e, board); + }} + > +
+
+ {board.isSecret ? ( +
+
+ +
+ 비밀글입니다. +
+
+ ) : ( + 썸네일 이미지 + )} +
+ {isNewPost(board.registerTime) ? ( + + N + + ) : ( + '' + )} +
+
+

+ {board.title} +

+
+ {board.files && board.files.length != 0 ? ( + + ) : ( + '' + )} + + + + {board.commentCount} + +
+
+

+ + {board.writer} + + + {getDiffTimeWithFormat(board.registerTime)} + +

+
+
+ +
+ +
+ ); + }; useEffect(() => {}, []); return ( <> {notices.length != 0 ? ( -
+