Skip to content

Commit 2deec76

Browse files
committed
Create store
1 parent 3483421 commit 2deec76

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

storybook-react/src/lib/store.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { createSlice, configureStore } from "@reduxjs/toolkit";
2+
3+
const defaultTasks = [
4+
{ id: "1", title: "Something", state: "TASK_INBOX" },
5+
{ id: "2", title: "Something more", state: "TASK_INBOX" },
6+
{ id: "3", title: "Something else", state: "TASK_INBOX" },
7+
{ id: "4", title: "Something again", state: "TASK_INBOX" },
8+
];
9+
10+
const TaskBoxData = {
11+
tasks: defaultTasks,
12+
status: `title`,
13+
error: null,
14+
};
15+
16+
const TasksSlice = createSlice({
17+
name: `taskbox`,
18+
initialState: TaskBoxData,
19+
reducers: {
20+
updateTaskState: (state, action) => {
21+
const { id, newTaskState } = action.payload;
22+
const task = state.tasks.findIndex((task) => task.id === id);
23+
if (task >= 0) {
24+
state.tasks[task].state = newTaskState;
25+
}
26+
},
27+
},
28+
});
29+
30+
const { updateTaskState } = TasksSlice.actions;
31+
32+
const store = configureStore({
33+
reducer: {
34+
taskbox: TasksSlice.reducer,
35+
},
36+
});
37+
38+
export { updateTaskState };
39+
export default store;

0 commit comments

Comments
 (0)