Skip to content

Commit 1c459b0

Browse files
committed
64
1 parent 7d06175 commit 1c459b0

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

db.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@
8484
"createdAt": 1647211568779,
8585
"id": 15
8686
},
87-
{
88-
"title": "",
89-
"body": "",
90-
"publish": false,
91-
"createdAt": 1653628899948,
92-
"id": 16
93-
},
9487
{
9588
"title": "tetet",
9689
"body": "body",

src/components/BlogList.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import LoadingSpinner from '../components/LoadingSpinner';
66
import Pagination from './Pagination';
77
import { useLocation } from 'react-router-dom';
88
import propTypes from 'prop-types';
9+
import Toast from '../components/Toast';
910

1011
const BlogList = ({ isAdmin }) => {
1112
const history = useHistory();
@@ -102,6 +103,12 @@ const BlogList = ({ isAdmin }) => {
102103

103104
return (
104105
<div>
106+
<Toast
107+
toasts={[
108+
{ text: 'error'},
109+
{ text: 'success', type: 'success'},
110+
]}
111+
/>
105112
<input
106113
type="text"
107114
placeholder="Search.."

src/components/Toast.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import propTypes from "prop-types";
2+
3+
const Toast = ({ toasts }) => {
4+
return (
5+
<div className="position-fixed bottom-0 end-0 p-2">
6+
{toasts.map(toast => {
7+
return (
8+
<div className={`alert alert-${toast.type || 'success'} m-0 py-2 mt-2`}>
9+
{toast.text}
10+
</div>
11+
);
12+
})}
13+
</div>
14+
);
15+
}
16+
17+
Toast.propTypes = {
18+
toasts: propTypes.arrayOf(propTypes.shape({
19+
text: propTypes.string,
20+
type: propTypes.string
21+
})).isRequired
22+
}
23+
24+
Toast.defaultProps = {
25+
toasts: []
26+
}
27+
28+
export default Toast;

0 commit comments

Comments
 (0)