This commit is contained in:
QkoSad
2023-08-08 16:02:54 +03:00
commit 0a7a469d56
315 changed files with 426907 additions and 0 deletions
@@ -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;