Skip to content

Commit c3b499b

Browse files
committed
updated story editor
1 parent 4b33adf commit c3b499b

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@editorjs/paragraph": "^2.8.0",
1818
"@editorjs/table": "^2.0.2",
1919
"@react-icons/all-files": "^4.1.0",
20+
"md5": "^2.3.0",
2021
"next": "12.0.10",
2122
"node-fetch": "^3.2.0",
2223
"react": "17.0.2",

src/components/Layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebarContentLeft?: ReactNode
99

1010
export default function Layout ({sidebarContentLeft, children, sidebarContentRight}: LayoutProps) {
1111
return (
12-
<div className="mx-auto bg-gray-100">
12+
<div className="mx-auto bg-gray-100 min-h-screen">
1313
<Navbar />
1414
<div className="grid grid-cols-9 gap-10 mt-10 px-20 pt-10">
1515
{sidebarContentLeft && (

src/components/editor/StoryEditor.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ const DEFAULT_INITIAL_DATA = () => {
1818
]
1919
}
2020
}
21+
22+
const getAbstract = (content) => {
23+
let abstract = ''
24+
for(let i =0; i< content.blocks.length; i++){
25+
if (content.blocks[i].type == "header" || content.blocks[i].type =="paragraph") {
26+
abstract += content.blocks[i].data.text
27+
}
28+
if (abstract.length >= 200) break;
29+
}
30+
return abstract;
31+
}
2132

2233
const EDITTOR_HOLDER_ID = 'editorjs';
2334

2435
export default function Editor () {
25-
const [postTitle, setPostTitle] = useState('Enter Title')
36+
const [postTitle, setPostTitle] = useState('Your Title Goes Here')
2637
const ejInstance = useRef();
2738
const [editorData, setEditorData] = React.useState(DEFAULT_INITIAL_DATA);
2839

@@ -65,11 +76,15 @@ export default function Editor () {
6576
`
6677
);
6778
const handleStorySubmit = () => {
68-
console.log(postTitle)
69-
console.log(editorData)
7079
commitMutation({
7180
variables: {
72-
input: {title: postTitle, contentJson: JSON.stringify(editorData), abstractContent: '', urlSuffix: '', thumbnail: ''},
81+
input: {
82+
title: postTitle,
83+
contentJson: JSON.stringify(editorData),
84+
abstractContent: getAbstract(editorData),
85+
urlSuffix: postTitle.toLowerCase().replace(" ", "-").substring(0, 32),
86+
thumbnail: ''
87+
},
7388
},
7489
})
7590
}

src/pages/story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Editor = dynamic(() => import('../components/editor/StoryEditor'))
55
export default function Story () {
66
return (
77
<div>
8-
<Layout sidebarContentRight={<div>Promoted</div>}>
8+
<Layout sidebarContentRight={<div>Promoted</div>} sidebarContentLeft={<div/>}>
99
<Editor />
1010
</Layout>
1111
</div>

yarn.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,11 @@ chalk@^4.0.0, chalk@^4.1.2:
634634
ansi-styles "^4.1.0"
635635
supports-color "^7.1.0"
636636

637+
638+
version "0.0.2"
639+
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
640+
integrity sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==
641+
637642
chokidar@^3.5.3:
638643
version "3.5.3"
639644
resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz"
@@ -741,6 +746,11 @@ cross-spawn@^7.0.2:
741746
shebang-command "^2.0.0"
742747
which "^2.0.1"
743748

749+
750+
version "0.0.2"
751+
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
752+
integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==
753+
744754
cssesc@^3.0.0:
745755
version "3.0.0"
746756
resolved "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz"
@@ -1444,6 +1454,11 @@ is-boolean-object@^1.1.0:
14441454
call-bind "^1.0.2"
14451455
has-tostringtag "^1.0.0"
14461456

1457+
is-buffer@~1.1.6:
1458+
version "1.1.6"
1459+
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
1460+
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
1461+
14471462
is-callable@^1.1.4, is-callable@^1.2.4:
14481463
version "1.2.4"
14491464
resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz"
@@ -1669,6 +1684,15 @@ lru-cache@^6.0.0:
16691684
dependencies:
16701685
yallist "^4.0.0"
16711686

1687+
md5@^2.3.0:
1688+
version "2.3.0"
1689+
resolved "https://registry.yarnpkg.com/md5/-/md5-2.3.0.tgz#c3da9a6aae3a30b46b7b0c349b87b110dc3bda4f"
1690+
integrity sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==
1691+
dependencies:
1692+
charenc "0.0.2"
1693+
crypt "0.0.2"
1694+
is-buffer "~1.1.6"
1695+
16721696
merge2@^1.3.0, merge2@^1.4.1:
16731697
version "1.4.1"
16741698
resolved "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz"

0 commit comments

Comments
 (0)