Create News
We can easily create a new page to submit news. We use CKEditor as our rich text editor.
#
1. Install and Configure CKEditorInstall the CKEditor with the following command.
Because CKEditor does not come with types we use a little trick to make it work in our project.
Create a typings.d.ts
file in the src folder and copy the following code in it.
note
You have to install the exact version of the ckeditor for these typings to work.
#
2. Create Composer componentCreate a new component called Composer
and route /submit
to it. To create a new post we use useAddPost
hook.
note
We use mutateAsync
because we want to redirect the user to the homepage after the post is created.
Use the spaces
query to find the id of the "General" space and
use the postTypes
query to find the id of the "Discussion" post type.
Then we can use these ids to create a "Discussion" post in "General" space.
Put them all together with some styling and the component should look similar to this.