renamed
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = [];
|
||||
const blogReducer = createSlice({
|
||||
name: "blogs",
|
||||
initialState,
|
||||
reducers: {
|
||||
setAllBlogs: (state, action) => action.payload,
|
||||
createBlog: (state, action) => {
|
||||
state.push(action.payload);
|
||||
},
|
||||
removeBlog: (state, action) =>
|
||||
state.filter((el) => el.id !== action.payload.id),
|
||||
likeBlog: (state, action) => {
|
||||
const blog = state.find((el) => el.id === action.payload.id);
|
||||
const newblog = { ...blog, likes: blog.likes + 1 };
|
||||
state[state.indexOf(blog)] = newblog;
|
||||
},
|
||||
addComment: (state, action) => {
|
||||
const blog = state.find((el) => el.id === action.payload.id);
|
||||
console.log(action.payload);
|
||||
const newblog = {
|
||||
...blog,
|
||||
comments: [...blog.comments, action.payload.comment],
|
||||
};
|
||||
state[state.indexOf(blog)] = newblog;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default blogReducer.reducer;
|
||||
export const { addComment, setAllBlogs, createBlog, removeBlog, likeBlog } =
|
||||
blogReducer.actions;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = [];
|
||||
const NotificationReducer = createSlice({
|
||||
name: "notification",
|
||||
initialState,
|
||||
reducers: {
|
||||
createNotification: (state, action) => {
|
||||
state.push(action.payload);
|
||||
},
|
||||
removeNotification: (state, action) => {
|
||||
state.pop()
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default NotificationReducer.reducer;
|
||||
export const { removeNotification, createNotification } = NotificationReducer.actions;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = [];
|
||||
const userReducer = createSlice({
|
||||
name: "users",
|
||||
initialState,
|
||||
reducers: {
|
||||
createUser: (state, action) => {},
|
||||
setAllUsers: (state, action) => action.payload,
|
||||
},
|
||||
});
|
||||
|
||||
export default userReducer.reducer;
|
||||
export const { createUser ,setAllUsers} = userReducer.actions;
|
||||
Reference in New Issue
Block a user