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

Feature/게시글 수정하기 버튼 활성화 안 됨 #880 #889

Merged
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
6 changes: 4 additions & 2 deletions src/api/postApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ const useGetEachPostQuery = (

const useGetPostFilesQuery = (postId: number, fileOpen: boolean, password?: string) => {
const queryClient = useQueryClient();

const fetcher = () => axios.get(`/posts/${postId}/files`).then(({ data }) => data);
const fetcher = () =>
axios.get(`/posts/${postId}/files`).then(({ data }) => {
return data;
});

return useQuery<FileInfo[]>(['files', postId], fetcher, {
enabled: fileOpen,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/board/BoardView/BoardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const BoardView = () => {
{postInfo && (
<>
<div className="space-y-2">
<BannerSection postId={postId} post={postInfo} />
<BannerSection postId={postId} post={postInfo} password={password} />
<PostSection postId={postId} post={postInfo} password={password} />
</div>
<AdjacentPostNavSection previousPost={postInfo.previousPost} nextPost={postInfo.nextPost} />
Expand Down
5 changes: 3 additions & 2 deletions src/pages/board/BoardView/Section/BannerSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import ActionModal from '@components/Modal/ActionModal';
interface BannerSectionProps {
postId: number;
post: PostInfo;
password?: string;
}

const BannerSection = ({ postId, post }: BannerSectionProps) => {
const BannerSection = ({ postId, post, password }: BannerSectionProps) => {
const [warningDeleteModalopen, setWarningDeleteModalopen] = useState(false);

const { mutate: deletePost } = useDeletePostMutation();
const navigate = useNavigate();
const { checkIsMyId } = useCheckAuth();

const handleEditPostClick = () => {
navigate(`/board/write/${post.categoryName}`, { state: { postId, post } });
navigate(`/board/write/${post.categoryName}`, { state: { postId, post, password } });
};

const handleDeletePostClick = () => {
Expand Down
10 changes: 7 additions & 3 deletions src/pages/board/BoardView/Section/PostSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useReducer, useState } from 'react';
import React, { useEffect, useReducer, useState } from 'react';
import { Button, Typography } from '@mui/material';
import { VscArrowDown, VscArrowUp, VscFolder, VscFolderOpened } from 'react-icons/vsc';
import { PostInfo } from '@api/dto';
Expand All @@ -21,15 +21,14 @@ interface PostSectionProps {
}

const PostSection = ({ postId, post, password }: PostSectionProps) => {
const [fileOpen, toggleFileOpen] = useReducer((prev) => !prev, false);
const [fileOpen, toggleFileOpen] = useReducer((prev) => !prev, true);
const [warningModalOpen, setWarningModalOpen] = useState(false);
const hasWarningModal = post.categoryName === '시험게시판' && post.isRead === false && !fileOpen;

const { data: files } = useGetPostFilesQuery(postId, fileOpen, password);
const { mutate: controlLikes } = useControlPostLikesMutation();
const { mutate: controlDislikes } = useControlPostDislikesMutation();
const { mutate: downloadFile } = useDownloadFileMutation();

const handleFileOpenButtonClick = () => {
if (hasWarningModal) {
setWarningModalOpen(true);
Expand All @@ -56,6 +55,11 @@ const PostSection = ({ postId, post, password }: PostSectionProps) => {
controlDislikes(postId);
};

useEffect(() => {
handleFileOpenButtonClick();
// toggleFileOpen();
}, []);

return (
<div className="min-h-[500px] bg-middleBlack px-6 pb-8 pt-3 sm:px-14 sm:py-10">
<StandardViewer className="mb-4 min-h-[380px]" content={post.content} />
Expand Down
16 changes: 11 additions & 5 deletions src/pages/board/BoardWrite/BoardWrite.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useRef, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { useQueryClient } from 'react-query';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { Stack, Typography } from '@mui/material';
import { Editor } from '@toast-ui/react-editor';
Expand All @@ -11,6 +10,7 @@
useDeleteFilesMutation,
useEditPostMutation,
useEditPostThumbnailMutation,
useGetPostFilesQuery,
useUploadPostMutation,
} from '@api/postApi';
import { COMMON } from '@constants/helperText';
Expand All @@ -33,6 +33,7 @@
state: {
postId: number;
post: PostInfo;
password: string;
} | null;
} = useLocation();

Expand Down Expand Up @@ -67,7 +68,14 @@
getValues,
formState: { isValid },
} = useForm({ mode: 'onBlur' });
const queryClient = useQueryClient();

if (editMode) {
const { data: filesInfo } = useGetPostFilesQuery(editMode?.postId, true, editMode?.password);
useEffect(() => {
if (!filesInfo) return;
setExistingFiles(filesInfo as any);

Check warning on line 76 in src/pages/board/BoardWrite/BoardWrite.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type
}, [filesInfo]);
}

const handleEditorBlur = () => {
const content = editorRef.current?.getInstance().getMarkdown();
Expand Down Expand Up @@ -148,8 +156,6 @@
isTemp: editMode.post.isTemp,
allowComment: editMode.post.allowComment,
});
const serverFiles: (File & { fileId: number })[] | undefined = queryClient.getQueryData(['files', editMode.postId]);
if (serverFiles) setExistingFiles(serverFiles);
}, []);

return (
Expand Down Expand Up @@ -197,7 +203,7 @@
height="470px"
initialValue={editMode?.post.content}
forwardedRef={editorRef as React.MutableRefObject<Editor>}
onBlur={handleEditorBlur}
onChange={handleEditorBlur}
/>
<Typography variant="small" className="text-subRed">
{!hasContent && contentErrMsg}
Expand Down
Loading