Added todo slice
This commit is contained in:
parent
4877008708
commit
0a135dc17c
@ -1,9 +1,10 @@
|
|||||||
import { configureStore } from "@reduxjs/toolkit";
|
import { configureStore } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
import uiStateReducer from "./slices/uiState";
|
import uiStateReducer from "./slices/uiState";
|
||||||
|
import todoReducer from "./slices/todo";
|
||||||
|
|
||||||
const store = configureStore({
|
const store = configureStore({
|
||||||
reducer: { uiState: uiStateReducer },
|
reducer: { uiState: uiStateReducer, todo: todoReducer },
|
||||||
});
|
});
|
||||||
|
|
||||||
export type RootState = ReturnType<typeof store.getState>;
|
export type RootState = ReturnType<typeof store.getState>;
|
||||||
|
30
src/store/slices/todo.ts
Normal file
30
src/store/slices/todo.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
|
import { TaskItemT } from "../../types";
|
||||||
|
|
||||||
|
const initialState: { tasks: TaskItemT[] } = {
|
||||||
|
tasks: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const todoSlice = createSlice({
|
||||||
|
name: "todo",
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
add: (state, { payload }: PayloadAction<TaskItemT>) => {
|
||||||
|
state.tasks.push(payload);
|
||||||
|
},
|
||||||
|
markDone: (
|
||||||
|
state,
|
||||||
|
{ payload }: PayloadAction<{ index: number; value: boolean }>
|
||||||
|
) => {
|
||||||
|
state.tasks[payload.index].done = payload.value;
|
||||||
|
},
|
||||||
|
remove: (state, { payload }: PayloadAction<number>) => {
|
||||||
|
state.tasks.splice(payload);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { add, markDone, remove } = todoSlice.actions;
|
||||||
|
|
||||||
|
export default todoSlice.reducer;
|
Loading…
x
Reference in New Issue
Block a user