File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1
1
import EditorJS , { LogLevels , OutputData } from '@editorjs/editorjs'
2
+ import { Http2ServerRequest } from 'http2'
2
3
import React , { useEffect , useRef , useState } from 'react'
3
4
import { graphql , useMutation } from 'react-relay'
4
5
import Button from '../Button'
@@ -36,11 +37,18 @@ const getAbstract = (content: OutputData) => {
36
37
37
38
const EDITTOR_HOLDER_ID = 'editorjs'
38
39
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' )
41
47
const ejInstance = useRef < EditorJS | null > ( )
42
- const [ editorData , setEditorData ] = React . useState ( DEFAULT_INITIAL_DATA )
43
48
49
+ const [ editorData , setEditorData ] = React . useState (
50
+ ( body && JSON . parse ( decodeURI ( body ) ) ) || DEFAULT_INITIAL_DATA
51
+ )
44
52
useEffect ( ( ) => {
45
53
if ( ! ejInstance . current ) {
46
54
initEditor ( )
Original file line number Diff line number Diff line change 1
1
import dynamic from 'next/dynamic'
2
+ import { useRouter } from 'next/router'
2
3
import Layout from '../components/Layout'
3
4
4
5
const Editor = dynamic ( ( ) => import ( '../components/story/StoryEditor' ) , {
5
6
ssr : false ,
6
7
} )
7
8
export default function Story ( ) {
9
+ const router = useRouter ( )
10
+ const { title, body } = router . query
8
11
return (
9
12
< div >
10
13
< Layout
11
14
sidebarContentRight = { < div > Promoted</ div > }
12
15
sidebarContentLeft = { < div > Reactions</ div > }
13
16
>
14
- < Editor />
17
+ < Editor title = { title as string } body = { body as string } />
15
18
</ Layout >
16
19
</ div >
17
20
)
You can’t perform that action at this time.
0 commit comments