Skip to content

Commit bbe5a21

Browse files
created blog actions
1 parent c2e63ee commit bbe5a21

File tree

5 files changed

+122
-2
lines changed

5 files changed

+122
-2
lines changed

client/actions/blog.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fetch from "isomorphic-fetch";
2+
import {API} from "../config.js";
3+
import cookie from "js-cookie";
4+
5+
export const createBlog = (blog,token) => {
6+
return fetch(`${API}/api/blog`, {
7+
method: 'POST',
8+
headers: {
9+
Accept: 'application/json',
10+
Authorization:`Bearer ${token}`
11+
12+
},
13+
body: blog
14+
})
15+
.then(response => {
16+
return response.json();
17+
})
18+
.catch(error => console.log(error));
19+
};
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
const NewBlog = ()=>{
1+
import Link from "next/link";
2+
import React,{useState,useEffect} from "react";
3+
import Router from "next/router";
4+
import dynamic from "next/dynamic"; // react quill runs on client side so dynamic is used to turn off ssr for react quill(to dynamically load the component)
5+
import {withRouter} from "next/router"; // to get access to the router props from the components
6+
// importing actions
7+
import {getCookie,isAuthenticated} from "../../actions/authentication";
8+
import {getCategories} from "../../actions/category";
9+
import {getTagLists} from "../../actions/tag";
10+
import {createBlog} from "../../actions/blog";
11+
12+
// dynamically importing react quill
13+
const ReactQuill = dynamic(() => import("react-quill"),{ssr:false});
14+
15+
16+
const NewBlog = ({router})=>{
217
return (
318
<div>
419
Create Blog Form
20+
{JSON.stringify(router)}
521
</div>
622
)
723
};
824

9-
export default NewBlog;
25+
export default withRouter(NewBlog);

client/package-lock.json

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"nprogress": "^0.2.0",
2121
"react": "^17.0.1",
2222
"react-dom": "^17.0.1",
23+
"react-quill": "^1.3.5",
2324
"reactstrap": "^8.8.1"
2425
}
2526
}

client/pages/_document.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class MyDocument extends Document {
1515
integrity="sha512-42kB9yDlYiCEfx2xVwq0q7hT4uf26FUgSIZBK8uiaEnTdShXjwr8Ip1V4xGJMg3mHkUt9nNuTDxunHF0/EgxLQ=="
1616
crossorigin="anonymous" />
1717
<link rel="stylesheet" href="/static/styles/styles.css"/>
18+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/react-quill/0.4.1/quill.snow.css" integrity="sha512-z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==" crossorigin="anonymous" />
1819

1920
</Head>
2021
<body>

0 commit comments

Comments
 (0)