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) => { <>