File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments