Skip to content

Commit ca656f8

Browse files
committed
72
1 parent ef6c154 commit ca656f8

File tree

5 files changed

+11
-48
lines changed

5 files changed

+11
-48
lines changed

db.json

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,41 +1001,6 @@
10011001
"createdAt": 1657255275073,
10021002
"id": 143
10031003
},
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-
},
10391004
{
10401005
"title": "b",
10411006
"body": "b",

src/components/BlogList.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { useLocation } from 'react-router-dom';
88
import propTypes from 'prop-types';
99
import Toast from '../components/Toast';
1010
import useToast from '../hooks/toast';
11-
import { useSelector } from 'react-redux';
1211

1312
const BlogList = ({ isAdmin }) => {
1413
const history = useHistory();
@@ -21,10 +20,6 @@ const BlogList = ({ isAdmin }) => {
2120
const [numberOfPosts, setNumberOfPosts] = useState(0);
2221
const [numberOfPages, setNumberOfPages] = useState(0);
2322
const [searchText, setSearchText] = useState('');
24-
const toasts1 = useSelector((state) => {
25-
return state.toast.toasts;
26-
});
27-
console.log('hello', toasts1)
2823

2924
const [toasts, addToast, deleteToast] = useToast();
3025
const limit = 5;

src/components/Card.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import PropTypes from 'prop-types';
2-
import { useSelector } from 'react-redux';
32

43
const Card = ({ title, onClick, children }) => {
5-
const toasts = useSelector((state) => {
6-
return state.toast.toasts;
7-
});
8-
console.log('hello1', toasts);
94
return (
105
<div
116
className="card mb-3 cursor-pointer"

src/hooks/toast.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { useState, useRef } from 'react';
22
import { v4 as uuidv4 } from 'uuid';
3+
import { addToast as add } from '../store/toastSlice';
4+
import { useDispatch } from 'react-redux';
35

46
const useToast = () => {
57
const [, setToastRerender] = useState(false);
68
const toasts = useRef([]);
9+
const dispatch = useDispatch();
710

811
const deleteToast = (id) => {
912
const filteredToasts = toasts.current.filter(toast => {
@@ -21,8 +24,9 @@ const useToast = () => {
2124
id
2225
}
2326

24-
toasts.current = [...toasts.current, toastWithId];
25-
setToastRerender(prev => !prev);
27+
dispatch(add(toastWithId));
28+
// toasts.current = [...toasts.current, toastWithId];
29+
// setToastRerender(prev => !prev);
2630

2731
setTimeout(() => {
2832
deleteToast(id, toasts, setToastRerender);

src/store/toastSlice.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ const toastSlice = createSlice({
88
name: 'toast',
99
initialState,
1010
reducers: {
11-
11+
addToast: (state, action) => {
12+
state.toasts.push(action.payload);
13+
}
1214
}
1315
})
1416

17+
export const { addToast } = toastSlice.actions;
18+
1519
export default toastSlice.reducer;

0 commit comments

Comments
 (0)