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) => {
<>
|
- {files.map((file) => getFileInfo(file))}
+
+ {originFiles.map((file) => getFileInfoOrigin(file))}
+ {files.map((file) => getFileInfo(file))}
+
@@ -151,7 +186,7 @@ const FilesUploadForm = (props) => {
(isDragActive
? 'bg-blue-300 bg-opacity-50'
: 'bg-slate-100 bg-opacity-50') +
- (files.length === 0
+ (files.length === 0 && originFiles.length === 0
? ' h-full rounded-lg'
: ' h-[192px] rounded-b-lg ') +
' flex items-center justify-center '
@@ -193,7 +228,7 @@ const FilesUploadForm = (props) => {
/>
파일 추가
- {files.length !== 0 ? (
+ {files.length !== 0 || originFiles.length !== 0 ? ( //첨부된 파일이 있을 경우
{/*console.log(files.length)*/}
@@ -203,7 +238,10 @@ const FilesUploadForm = (props) => {
삭제 |
- {files.map((file) => getFileInfo(file))}
+
+ {originFiles?.map((file) => getFileInfoOrigin(file))}
+ {files?.map((file) => getFileInfo(file))}
+
) : (
''
diff --git a/src/page/Board/Components/Gallary.jsx b/src/page/Board/Components/Gallary.jsx
index 380a7347..a2ebb3f9 100644
--- a/src/page/Board/Components/Gallary.jsx
+++ b/src/page/Board/Components/Gallary.jsx
@@ -21,114 +21,122 @@ 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)}
+
+
+
+
+
+
+
+ {board.visitCount}
+
+
+
+
+
+ );
+ };
useEffect(() => {}, []);
return (
<>
{notices.length != 0 ? (
-
+
- {notices.map((board, index) => (
-
-
{
- if (
- board.isSecret &&
- board.writerId != state.member?.memberInfo?.id
- )
- linkHandler(e, board);
- }}
- >
-
-
- {/*console.log(board.thumbnailPath)*/}
- {board.isSecret ? (
-
- ) : (
-
- )}
-
- {isNewPost(board.registerTime) ? (
-
- N
-
- ) : (
- ''
- )}
-
-
-
-
- {board.title}
-
-
-
- {board.files && board.files.length != 0 ? (
-
- ) : (
- ''
- )}
-
-
- {board.commentCount}
-
-
-
-
-
- {board.writer}
-
-
- {getDiffTimeWithFormat(board.registerTime)}
-
-
-
-
-
-
-
- {board.visitCount}
-
-
-
-
-
- ))}
+ {notices.map((board, index) => card(board, index, true))}
-
+
{
)}
{/*=====================================================================*/}
- {boards?.map((board, index) => (
-
-
{
- 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)}
-
-
-
-
-
-
-
- {board.visitCount}
-
-
-
-
-
- ))}
+ {boards?.map((board, index) => card(board, index, false))}
>
);
diff --git a/src/page/Board/Components/Table.jsx b/src/page/Board/Components/Table.jsx
index f55c7929..e04c2361 100644
--- a/src/page/Board/Components/Table.jsx
+++ b/src/page/Board/Components/Table.jsx
@@ -28,6 +28,100 @@ const Table = ({
if (id == currentId) return 'text-mainYellow rounded-lg';
return;
};
+ const row = (board, index, isN) => {
+ //isN은 공지글인지 일반 글인지 여부(true=>공지글, false=>일반 글)
+ return (
+
+ {/*console.log(board)*/}
+
+ {isN ? '공지' : MAX_POSTS * (currentPage - 1) + index + 1}
+ |
+
+ {
+ if (
+ board.isSecret &&
+ board.writerId != state.member?.memberInfo?.id
+ )
+ linkHandler(e, board);
+ }}
+ >
+
+
+ {board.isSecret ? (
+
+ ) : (
+ ''
+ )}
+
+ {board.title}
+
+
+
+ {board.thumbnail ? (
+
+ ) : (
+ ''
+ )}
+ {board.files ? (
+
+ ) : (
+ ''
+ )}
+ {board.commentCount != 0 ? (
+
+ {'(' + board.commentCount + ')'}
+
+ ) : (
+ ''
+ )}
+ {isNewPost(board.registerTime) ? (
+
+ N
+
+ ) : (
+ ''
+ )}
+
+
+
+ 글쓴이 : {board.writer} | 작성일시 :
+ {getDateWithFormat(board.registerTime)} |{' '}
+
+ 조회수 : {board.visitCount}
+
+
+
+ |
+
+
+ {board.writer}
+ |
+
+ {/*getDateWithFormat(board.registerTime)
+ */}
+ {getDiffTimeWithFormat(board.registerTime)}
+ |
+
+ {board.visitCount}
+ |
+
+ );
+ };
return (
@@ -51,170 +145,10 @@ const Table = ({
- {notices?.map((board, index) => (
-
-
- 공지
- |
-
- {
- if (
- board.isSecret &&
- board.writerId != state.member?.memberInfo?.id
- )
- linkHandler(e, board);
- }}
- >
-
-
-
- {board.title}
-
-
-
-
- {board.thumbnail ? (
-
- ) : (
- ''
- )}
- {board.files && board.files.length != 0 ? (
-
- ) : (
- ''
- )}
- {board.commentCount != 0 ? (
-
- {'(' + board.commentCount + ')'}
-
- ) : (
- ''
- )}
- {isNewPost(board.registerTime) ? (
-
- N
-
- ) : (
- ''
- )}
-
-
-
- 글쓴이 : {board.writer} | 작성일시 :
- {getDateWithFormat(board.registerTime)} |{' '}
-
- 조회수 : {board.visitCount}
-
-
-
- |
-
- {board.writer}
- |
-
- {/*getDateWithFormat(board.registerTime)
- */}
- {getDiffTimeWithFormat(board.registerTime)}
- |
-
- {board.visitCount}
- |
-
- ))}
- {/*=============================================================================================*/}
- {boards?.map((board, index) => (
-
- {/*console.log(board)*/}
-
- {MAX_POSTS * (currentPage - 1) + index + 1}
- |
-
- {
- if (
- board.isSecret &&
- board.writerId != state.member?.memberInfo?.id
- )
- linkHandler(e, board);
- }}
- >
-
-
- {board.isSecret ? (
-
- ) : (
- ''
- )}
-
- {board.title}
-
-
-
- {board.thumbnail ? (
-
- ) : (
- ''
- )}
- {board.files && board.files.length != 0 ? (
-
- ) : (
- ''
- )}
- {board.commentCount != 0 ? (
-
- {'(' + board.commentCount + ')'}
-
- ) : (
- ''
- )}
- {isNewPost(board.registerTime) ? (
-
- N
-
- ) : (
- ''
- )}
-
-
-
- 글쓴이 : {board.writer} | 작성일시 :
- {getDateWithFormat(board.registerTime)} |{' '}
-
- 조회수 : {board.visitCount}
-
-
-
- |
+ {notices?.map((board, index) => row(board, index, true))}
+ {boards?.map((board, index) => row(board, index, false))}
-
- {board.writer}
- |
-
- {/*getDateWithFormat(board.registerTime)
- */}
- {getDiffTimeWithFormat(board.registerTime)}
- |
-
- {board.visitCount}
- |
-
- ))}
);
diff --git a/src/page/Board/Components/TextEditer.jsx b/src/page/Board/Components/TextEditer.jsx
index 0b139016..4ce1af50 100644
--- a/src/page/Board/Components/TextEditer.jsx
+++ b/src/page/Board/Components/TextEditer.jsx
@@ -33,6 +33,8 @@ const TextEditer = (props) => {
const [thumbnailBase64, setThumbnailBase64] = useState(null); // 파일 base64
const [thumbnail, setThumbnail] = useState(null);
const [files, setFiles] = useState([]);
+ const [originFiles, setOriginFiles] = useState([]);
+ const [deleteFileIdList, setDeleteFileIdList] = useState([]); //삭제할 파일 목록
const checkAllowCommentHandler = ({ target }) => {
setAllowComment(target.checked);
@@ -65,6 +67,7 @@ const TextEditer = (props) => {
setIsNotice(!!board.isNotice);
setIsSecret(!!board.isSecret);
setUploadAble(true);
+ setOriginFiles(board.files);
}
}, []);
@@ -117,6 +120,17 @@ const TextEditer = (props) => {
};
const uploadModifyhandler = (isTemp) => {
setUploadAble(false);
+ console.log(deleteFileIdList);
+ postAPI
+ .deleteFiles({
+ fileIdList: deleteFileIdList,
+ token: token,
+ })
+ .then((res) => {
+ console.log(res);
+ });
+
+
postAPI
.modify({
boardId: board.id,
@@ -231,9 +245,13 @@ const TextEditer = (props) => {
diff --git a/src/page/Study/Components/Modals/ModifyModal.jsx b/src/page/Study/Components/Modals/ModifyModal.jsx
index 3a5194fe..448bef28 100644
--- a/src/page/Study/Components/Modals/ModifyModal.jsx
+++ b/src/page/Study/Components/Modals/ModifyModal.jsx
@@ -24,7 +24,7 @@ const ModifyModal = ({
스터디 수정하기
-