Skip to content

Commit c477d88

Browse files
author
Roshan Jossy
committed
add query params for title and body in editor
1 parent 6ab848c commit c477d88

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/components/story/StoryEditor.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import EditorJS, { LogLevels, OutputData } from '@editorjs/editorjs'
2+
import { Http2ServerRequest } from 'http2'
23
import React, { useEffect, useRef, useState } from 'react'
34
import { graphql, useMutation } from 'react-relay'
45
import Button from '../Button'
@@ -36,11 +37,18 @@ const getAbstract = (content: OutputData) => {
3637

3738
const EDITTOR_HOLDER_ID = 'editorjs'
3839

39-
export default function Editor() {
40-
const [postTitle, setPostTitle] = useState('Your Title Goes Here')
40+
type EditorProps = {
41+
title?: string
42+
body?: string
43+
}
44+
45+
export default function Editor({ title, body }: EditorProps) {
46+
const [postTitle, setPostTitle] = useState(title || 'Your Title Goes Here')
4147
const ejInstance = useRef<EditorJS | null>()
42-
const [editorData, setEditorData] = React.useState(DEFAULT_INITIAL_DATA)
4348

49+
const [editorData, setEditorData] = React.useState(
50+
(body && JSON.parse(decodeURI(body))) || DEFAULT_INITIAL_DATA
51+
)
4452
useEffect(() => {
4553
if (!ejInstance.current) {
4654
initEditor()

src/pages/story.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import dynamic from 'next/dynamic'
2+
import { useRouter } from 'next/router'
23
import Layout from '../components/Layout'
34

45
const Editor = dynamic(() => import('../components/story/StoryEditor'), {
56
ssr: false,
67
})
78
export default function Story() {
9+
const router = useRouter()
10+
const { title, body } = router.query
811
return (
912
<div>
1013
<Layout
1114
sidebarContentRight={<div>Promoted</div>}
1215
sidebarContentLeft={<div>Reactions</div>}
1316
>
14-
<Editor />
17+
<Editor title={title as string} body={body as string} />
1518
</Layout>
1619
</div>
1720
)

0 commit comments

Comments
 (0)