Skip to content

Commit

Permalink
refactor(QYOG-94): 상세, 글생성 게시판 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
jsj1510 committed Mar 17, 2024
1 parent 5c4f1e0 commit 6802b32
Show file tree
Hide file tree
Showing 26 changed files with 239 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import { Converter } from "@/utils";

interface PostData {
id: number;
type: string;
}

interface TableData {
data:
| Swagger.Api.FreePostFindAllAndCount.ResponseBody
| Swagger.Api.NoticePostFindAllAndCount.ResponseBody;
type: string;
handleClickPostDetail: (el: PostData) => void;
handleClickPostDetail: ({ id, type }: PostData) => void;
}

export default function Table({
Expand Down Expand Up @@ -79,7 +80,7 @@ export default function Table({
return (
<S.Tr
key={post.id}
onClick={() => handleClickPostDetail(post)}
onClick={() => handleClickPostDetail({ id: post.id, type })}
type={type}
>
<S.Th
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 12 additions & 3 deletions src/components/UI/Quill/Quill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ const modules = {

const formats = [
"header",
"font",
"size",
"bold",
"italic",
"underline",
"strike",
"blockquote",
"list",
"bullet",
"indent",
"link",
"image",
"align",
"color",
"background",
];

interface QuillProps {
Expand Down Expand Up @@ -79,6 +85,7 @@ export default function Quill({
}}
>
<label htmlFor="title">Title</label>

<input
type="text"
value={value.title}
Expand All @@ -87,14 +94,16 @@ export default function Quill({
onChange={handleTitleChange}
required
/>
<Button>{value ? "생성" : "수정"}</Button>

<QuillNoSSRWrapper
modules={modules}
formats={formats}
value={value.description}
onChange={handleContentChange}
theme="snow"
style={{ height: "600px" }}
/>
<Button>{value ? "생성" : "수정"}</Button>
<div dangerouslySetInnerHTML={{ __html: value.description }} />
</form>
);
Expand Down
101 changes: 101 additions & 0 deletions src/containers/Board/DetailBoard/DetailBoard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { useRouter } from "next/router";
import { useQuery, useMutation } from "@tanstack/react-query";
import { useEffect } from "react";

import * as S from "./emotion";
import { freePostsAPI, noticePostsAPI } from "@/apis";
import {
FreePostDetailResponseDto,
NoticePostDetailResponseDto,
} from "@/apis/data-contracts";

export default function DetailBoard() {
const router = useRouter();
const { postId, type } = router.query;

const { data } = useQuery({
queryFn: async () => {
let response;
if (type === "free") {
response = await freePostsAPI.freePostFindOneOrNotFound(Number(postId));
} else {
response = await noticePostsAPI.noticePostFindOneOrNotFound(
Number(postId)
);
}

return response.data;
},

queryKey: ["post", postId, type],
enabled: postId !== undefined,
});

const { mutate } = useMutation({
mutationKey: ["post", postId, type],
mutationFn: async () => {
let response;
if (type === "free") {
response = await freePostsAPI.freePostIncrementHit(Number(postId));
} else {
response = await noticePostsAPI.noticePostIncreaseHit(Number(postId));
}
},
onSuccess() {
console.log(data);
},
onError(error) {
console.log(error);
},
});

useEffect(() => {
if (data) {
mutate();
}
}, [data, mutate]);

const handleClickDelete = () => {
freePostsAPI.freePostRemove(Number(postId)).then(() => {
router.back();
});
};

const handleClickUpdate = async () => {
router.push({
pathname: `/board/free/write/`,
query: {
Id: postId,
},
});
};

return (
<S.Container>
<S.Title>
{
(type === "free"
? (data as FreePostDetailResponseDto)?.freePost
: (data as NoticePostDetailResponseDto)?.noticePost
)?.title
}
</S.Title>
<S.WrapBar>
<S.Btn onClick={handleClickUpdate}>수정</S.Btn>
<S.Btn onClick={handleClickDelete}>삭제</S.Btn>
</S.WrapBar>
<S.WrapDesc>
<S.Desc>
<S.Title>
{
(type === "free"
? (data as FreePostDetailResponseDto)?.freePost
: (data as NoticePostDetailResponseDto)?.noticePost
)?.description
}
</S.Title>
</S.Desc>
</S.WrapDesc>
</S.Container>
);
}
File renamed without changes.
1 change: 1 addition & 0 deletions src/containers/Board/DetailBoard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as DetailBoard } from "./DetailBoard";
64 changes: 0 additions & 64 deletions src/containers/Board/DetailFreeBoard/DetailFreeBoard.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/containers/Board/DetailFreeBoard/index.ts

This file was deleted.

63 changes: 0 additions & 63 deletions src/containers/Board/DetailNoticeBoard/DetailNoticeBoard.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/containers/Board/DetailNoticeBoard/emotion.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/containers/Board/DetailNoticeBoard/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/containers/Board/SearchWriter/SearchWriter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default function SearchWriter({ type }: BoardType) {

function handleClickPostWrite() {
router.push({
pathname: `free/write/`,
pathname: `board/write/`,
query: type,
});
}

Expand Down
Loading

0 comments on commit 6802b32

Please sign in to comment.