Skip to content

Commit b4b035b

Browse files
committed
feat: update style for edtior.js
1 parent 7d24daa commit b4b035b

File tree

4 files changed

+66
-22
lines changed

4 files changed

+66
-22
lines changed

apps/web/@/molecules/editor-js/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const Editor: React.FC<EditorJSProps> = ({ onChange, data }) => {
2323
list: List,
2424
},
2525
data: data,
26+
placeholder: "Write your post here...",
2627
onChange: async () => {
2728
const content = await editorRef.current?.save()
2829
onChange(content)

apps/web/@/molecules/input-title/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const InputTitle: React.FunctionComponent<InputTitleProps> = ({
2525
placeholder={placeholder}
2626
onChange={onChange}
2727
onBlur={onBlur}
28-
className="h-16 w-full rounded-md border border-none bg-transparent px-3 py-2 text-4xl font-bold focus-visible:ring-ring focus-visible:ring-offset-2 focus:focus-visible:outline-none"
28+
className="h-16 w-full scroll-m-20 rounded-md border border-none bg-transparent px-3 py-2 text-4xl font-extrabold tracking-tight focus-visible:ring-ring focus-visible:ring-offset-2 focus:focus-visible:outline-none lg:text-5xl"
2929
/>
3030
</div>
3131
)

apps/web/@/molecules/post-form/index.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"use client"
22

33
import React, { useState } from "react"
4+
import dynamic from "next/dynamic"
45
import Link from "next/link"
5-
import { useParams } from "next/navigation"
6+
import { useParams, useRouter } from "next/navigation"
67

78
import { zodResolver } from "@hookform/resolvers/zod"
89
import { createPost, Prisma, updatePost } from "database"
@@ -11,20 +12,21 @@ import { useTranslations } from "next-intl"
1112
import { Controller, useForm } from "react-hook-form"
1213
import AsyncCreatableSelect from "react-select/async-creatable"
1314
import { toast } from "react-toastify"
14-
import { Button, buttonVariants, cn, Label, LoadingButton } from "ui"
15+
import { buttonVariants, cn, Label, LoadingButton } from "ui"
1516
import z from "zod"
1617

1718
import APP_ROUTES from "@/constants/routes"
1819
import InputTitle from "@/molecules/input-title"
1920
import { TPostItem } from "@/types/posts"
2021

21-
import Editor from "../editor-js"
22+
const Editor = dynamic(() => import("../editor-js"), { ssr: false })
2223

2324
const PostForm = ({ post: postData }: { post?: TPostItem }) => {
2425
const { title = "", content = "", tagOnPost = [] } = postData || {}
2526
const t = useTranslations()
2627
const session = useSession()
2728
const [pending, setPending] = useState(false)
29+
const router = useRouter()
2830

2931
const userId = session?.data?.user?.id
3032

@@ -68,24 +70,27 @@ const PostForm = ({ post: postData }: { post?: TPostItem }) => {
6870
})
6971

7072
const handleSubmitPost = async (data) => {
73+
let newPostId = postId as string
7174
try {
7275
setPending(true)
7376
if (postId) {
7477
await updatePost(postId as string, data, userId)
7578
toast.success(t("common.post_created"))
7679
} else {
77-
await createPost(data, userId)
80+
const post = await createPost(data, userId)
81+
newPostId = post.data.id
7882
toast.success(t("common.post_updated"))
7983
}
8084
} catch (error) {
8185
toast.error(error.message)
8286
} finally {
87+
router.push(APP_ROUTES.POST.replace(":postId", newPostId))
8388
setPending(false)
8489
}
8590
}
8691

8792
const promiseOptions = async (inputValue: string) => {
88-
const rawData = await fetch("/api/protected/tags?search=" + inputValue)
93+
const rawData = await fetch(`/api/protected/tags?search=${inputValue}`)
8994
const tags = await rawData.json()
9095

9196
return tags.map((tag) => ({
@@ -117,26 +122,27 @@ const PostForm = ({ post: postData }: { post?: TPostItem }) => {
117122
)}
118123
</div>
119124
</div> */}
120-
{JSON.stringify(errors)}
121125
<form
122126
className="mb-4 w-full"
123127
onSubmit={handleSubmit(handleSubmitPost)}
124128
>
125129
<div className="grid grid-cols-4 gap-8">
126130
<div className="col-span-3 mb-4 w-full rounded-md">
127131
<div className="w-full">
128-
<Controller
129-
name="title"
130-
control={control}
131-
render={({ field }) => (
132-
<InputTitle
133-
placeholder={t("common.untitled")}
134-
{...field}
135-
/>
136-
)}
137-
/>
132+
<div className="px-[58px]">
133+
<Controller
134+
name="title"
135+
control={control}
136+
render={({ field }) => (
137+
<InputTitle
138+
placeholder={t("common.untitled")}
139+
{...field}
140+
/>
141+
)}
142+
/>
143+
</div>
138144

139-
<div className="mt-3 rounded">
145+
<div className="mt-3">
140146
<Controller
141147
name="content"
142148
control={control}

apps/web/app/[lang]/globals.css

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@
7171
@apply border-border;
7272
}
7373
body {
74-
@apply bg-background text-foreground min-h-screen font-sans antialiased;
74+
@apply min-h-screen bg-background font-sans text-foreground antialiased;
7575
}
7676

77-
h1, h2, h3, h4, h5, h6 {
78-
@apply font-bold mb-4;
77+
h1,
78+
h2,
79+
h3,
80+
h4,
81+
h5,
82+
h6 {
83+
@apply mb-4 font-bold;
7984
}
8085

8186
p {
@@ -90,7 +95,7 @@
9095
font-size: 0.9rem;
9196
padding: 0.25em;
9297
}
93-
98+
9499
pre {
95100
background: #0f111a;
96101
border-radius: 0.5rem;
@@ -158,3 +163,35 @@
158163
}
159164
}
160165
}
166+
167+
/* editorjs */
168+
.ce-block__content,
169+
.ce-toolbar__content {
170+
max-width: unset;
171+
margin-left: 70px;
172+
margin-right: 70px;
173+
}
174+
175+
h1.ce-header {
176+
@apply scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl;
177+
}
178+
179+
h2.ce-header {
180+
@apply scroll-m-20 text-3xl font-semibold tracking-tight first:mt-0;
181+
}
182+
183+
h3.ce-header {
184+
@apply scroll-m-20 text-2xl font-semibold tracking-tight;
185+
}
186+
187+
h4.ce-header {
188+
@apply scroll-m-20 text-xl font-semibold tracking-tight;
189+
}
190+
191+
h5.ce-header {
192+
@apply scroll-m-20 text-lg font-semibold tracking-tight;
193+
}
194+
195+
h6.ce-header {
196+
@apply scroll-m-20 text-base font-semibold tracking-tight;
197+
}

0 commit comments

Comments
 (0)