Skip to content

Commit 242f8e9

Browse files
authored
Refactoring editor (#80)
* update editor styles * 게시글 생성, 수정, 삭제, 취소 시 버튼 클릭 안되도록 수정
1 parent 837835a commit 242f8e9

File tree

5 files changed

+108
-59
lines changed

5 files changed

+108
-59
lines changed

src/app/posts/[index]/edit/page.module.scss

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@
5858
}
5959
}
6060

61+
h1,
62+
h2,
63+
h3,
64+
h4 {
65+
border: none !important;
66+
}
67+
6168
h2 {
6269
font-size: var(--h5) !important;
6370
}
6471

65-
h3,
66-
h4 {
72+
h3 {
6773
font-size: var(--h6) !important;
6874
}
6975

70-
* {
71-
border: none !important;
76+
h4 {
77+
font-size: var(--p) !important;
7278
}
7379

7480
ul {

src/app/posts/create/page.module.scss

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@
5858
}
5959
}
6060

61+
h1,
62+
h2,
63+
h3,
64+
h4 {
65+
border: none !important;
66+
}
67+
6168
h2 {
6269
font-size: var(--h5) !important;
6370
}
6471

65-
h3,
66-
h4 {
72+
h3 {
6773
font-size: var(--h6) !important;
6874
}
6975

70-
* {
71-
border: none !important;
76+
h4 {
77+
font-size: var(--p) !important;
7278
}
7379

7480
ul {

src/components/common/header/PostsHeader/index.tsx

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"use client";
22

3+
import { useState } from "react";
34
import Link from "next/link";
5+
import { usePathname } from "next/navigation";
6+
47
import styles from "./styles.module.scss";
8+
59
import { DefaultLogo } from "@/components/common/logo";
6-
import { usePathname } from "next/navigation";
710
import { useAppDispatch, useAppSelector } from "@/hooks/reduxHook";
811
import { setResetPost } from "@/store/modules/post";
912
import { deletePost, postPost, putPost } from "@/app/api/posts";
@@ -12,6 +15,7 @@ const PostsHeader = () => {
1215
const dispatch = useAppDispatch();
1316
const user = useAppSelector((state) => state.user);
1417
const { title, markdownValue } = useAppSelector((state) => state.post);
18+
const [loading, setLoading] = useState(false);
1519

1620
const pathname = usePathname();
1721
const isAdmin = user.userType === "admin";
@@ -20,15 +24,29 @@ const PostsHeader = () => {
2024
const isEdit = pathname.endsWith("/edit");
2125
const index = Number(pathname.split("/")[2]);
2226

23-
const handleSave = async () => {
24-
if (isEdit) await putPost({ index, title, markdownValue });
25-
if (isCreate) await postPost({ title, markdownValue });
26-
dispatch(setResetPost());
27-
};
28-
29-
const handleDelete = async () => {
30-
await deletePost(index);
31-
dispatch(setResetPost());
27+
const handleButton = async (
28+
type: "create" | "edit" | "delete" | "cancel"
29+
) => {
30+
try {
31+
setLoading(true);
32+
switch (type) {
33+
case "create":
34+
await postPost({ title, markdownValue });
35+
break;
36+
case "edit":
37+
await putPost({ index, title, markdownValue });
38+
break;
39+
case "delete":
40+
await deletePost(index);
41+
break;
42+
case "delete":
43+
default:
44+
break;
45+
}
46+
dispatch(setResetPost());
47+
} finally {
48+
setLoading(false);
49+
}
3250
};
3351

3452
return (
@@ -39,45 +57,52 @@ const PostsHeader = () => {
3957
{!isPosts && <Link href="/posts">POST</Link>}
4058
</nav>
4159

42-
{isAdmin && (
60+
{isAdmin && !isPosts && (
4361
<div className={styles.button_container}>
44-
{isPosts ? null : (
62+
{isEdit || isCreate ? (
63+
<>
64+
<button
65+
type="button"
66+
className={`card-shadow ${styles.submit_button} ${
67+
loading && styles.loading
68+
}`}
69+
onClick={() =>
70+
isEdit ? handleButton("edit") : handleButton("create")
71+
}
72+
disabled={loading}
73+
>
74+
{isEdit ? "save" : "create"}
75+
</button>
76+
<Link
77+
href={isEdit ? `/posts/${index}` : "/posts"}
78+
className={`button-card-shadow ${styles.edit_button} ${
79+
loading && styles.loading
80+
}`}
81+
onClick={() => handleButton("cancel")}
82+
>
83+
cancel
84+
</Link>
85+
</>
86+
) : (
4587
<>
46-
{!isEdit && !isCreate && (
47-
<>
48-
<Link
49-
href={`/posts/${index}/edit`}
50-
className={`button-card-shadow ${styles.edit_button}`}
51-
>
52-
edit
53-
</Link>
54-
<button
55-
type="button"
56-
className={`button-card-shadow ${styles.delete_button}`}
57-
onClick={handleDelete}
58-
>
59-
delete
60-
</button>
61-
</>
62-
)}
63-
{(isEdit || isCreate) && (
64-
<>
65-
<button
66-
type="button"
67-
className={`card-shadow ${styles.submit_button}`}
68-
onClick={handleSave}
69-
>
70-
save
71-
</button>
72-
<Link
73-
href={isEdit ? `/posts/${index}` : "/posts"}
74-
className={`button-card-shadow ${styles.edit_button}`}
75-
onClick={() => dispatch(setResetPost())}
76-
>
77-
cancel
78-
</Link>
79-
</>
80-
)}
88+
<Link
89+
href={`/posts/${index}/edit`}
90+
className={`button-card-shadow ${styles.edit_button} ${
91+
loading && styles.loading
92+
}`}
93+
>
94+
edit
95+
</Link>
96+
<button
97+
type="button"
98+
className={`button-card-shadow ${styles.delete_button} ${
99+
loading && styles.loading
100+
}`}
101+
onClick={() => handleButton("delete")}
102+
disabled={loading}
103+
>
104+
delete
105+
</button>
81106
</>
82107
)}
83108
</div>

src/components/common/header/PostsHeader/styles.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,9 @@
127127
animation: submit-glow 4s infinite linear;
128128
}
129129
}
130+
131+
.loading {
132+
cursor: not-allowed;
133+
opacity: 0.5;
134+
pointer-events: none;
135+
}

src/components/posts/[id]/PostContent/styles.module.scss

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@
2020
}
2121
}
2222

23+
h1,
24+
h2,
25+
h3,
26+
h4 {
27+
border: none !important;
28+
}
29+
2330
h2 {
2431
font-size: var(--h5) !important;
2532
}
2633

27-
h3,
28-
h4 {
34+
h3 {
2935
font-size: var(--h6) !important;
3036
}
3137

32-
* {
33-
border: none !important;
38+
h4 {
39+
font-size: var(--p) !important;
3440
}
3541

3642
ul {

0 commit comments

Comments
 (0)