Skip to content

Commit a5d7a74

Browse files
committed
69
1 parent 9062c80 commit a5d7a74

File tree

4 files changed

+76
-13
lines changed

4 files changed

+76
-13
lines changed

db.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,62 @@
10001000
"publish": false,
10011001
"createdAt": 1657255275073,
10021002
"id": 143
1003+
},
1004+
{
1005+
"title": "tt",
1006+
"body": "tt",
1007+
"publish": false,
1008+
"createdAt": 1657774109980,
1009+
"id": 144
1010+
},
1011+
{
1012+
"title": "af",
1013+
"body": "fg",
1014+
"publish": false,
1015+
"createdAt": 1657774124639,
1016+
"id": 145
1017+
},
1018+
{
1019+
"title": "a",
1020+
"body": "a",
1021+
"publish": false,
1022+
"createdAt": 1657774343111,
1023+
"id": 146
1024+
},
1025+
{
1026+
"title": "a",
1027+
"body": "a",
1028+
"publish": false,
1029+
"createdAt": 1657774405686,
1030+
"id": 147
1031+
},
1032+
{
1033+
"title": "b",
1034+
"body": "b",
1035+
"publish": false,
1036+
"createdAt": 1657774415721,
1037+
"id": 148
1038+
},
1039+
{
1040+
"title": "b",
1041+
"body": "b",
1042+
"publish": false,
1043+
"createdAt": 1657774497818,
1044+
"id": 149
1045+
},
1046+
{
1047+
"title": "a",
1048+
"body": "a",
1049+
"publish": false,
1050+
"createdAt": 1657775679723,
1051+
"id": 150
1052+
},
1053+
{
1054+
"title": "b",
1055+
"body": "b",
1056+
"publish": false,
1057+
"createdAt": 1657775748192,
1058+
"id": 151
10031059
}
10041060
]
10051061
}

src/App.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,30 @@ import {
55
} from 'react-router-dom';
66
import NavBar from './components/NavBar';
77
import routes from './routes';
8+
import Toast from './components/Toast';
9+
import useToast from './hooks/toast';
810

911
function App() {
12+
const [toasts, addToast, deleteToast] = useToast();
1013
return (
1114
<Router>
1215
<NavBar />
13-
16+
<Toast
17+
toasts={toasts}
18+
deleteToast={deleteToast}
19+
/>
1420
<div className="container mt-3">
1521
<Switch>
1622
{routes.map((route) => {
17-
return <Route key={route.path} exact path={route.path} component={route.component} />;
23+
const Component = route.component;
24+
return <Route
25+
key={route.path}
26+
exact
27+
path={route.path}
28+
// component={route.component}
29+
>
30+
<Component addToast={addToast} />
31+
</Route>;
1832
})}
1933
</Switch>
2034
</div>

src/components/BlogForm.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import { useEffect, useState } from 'react';
22
import axios from 'axios';
33
import { useHistory, useParams } from 'react-router';
44
import propTypes from 'prop-types';
5-
import Toast from '../components/Toast';
6-
import useToast from '../hooks/toast';
75

8-
const BlogForm = ({ editing }) => {
9-
const [toasts, addToast, deleteToast] = useToast();
6+
const BlogForm = ({ editing, addToast }) => {
107
const history = useHistory();
118
const { id } = useParams();
129

@@ -86,7 +83,7 @@ const BlogForm = ({ editing }) => {
8683
type: 'success',
8784
text: 'Successfully created!'
8885
});
89-
// history.push('/admin');
86+
history.push('/admin');
9087
})
9188
}
9289
}
@@ -98,10 +95,6 @@ const BlogForm = ({ editing }) => {
9895

9996
return (
10097
<div>
101-
<Toast
102-
toasts={toasts}
103-
deleteToast={deleteToast}
104-
/>
10598
<h1>{editing ? 'Edit' : 'Create'} a blog post</h1>
10699
<div className="mb-3">
107100
<label className="form-label">Title</label>

src/pages/CreatePage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import BlogForm from "../components/BlogForm";
22

3-
const CreatePage = () => {
3+
const CreatePage = ({ addToast }) => {
44
return (
55
<div>
6-
<BlogForm />
6+
<BlogForm addToast={addToast} />
77
</div>
88
);
99
};

0 commit comments

Comments
 (0)