Skip to content

Commit 7d0bd85

Browse files
author
Manuela Paula Ritter
committed
add delete task to reducer and new mock effects
1 parent 5d0b308 commit 7d0bd85

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/app/matrix/matrix.effects.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@ import { Observable, of } from 'rxjs';
55
import { catchError, map, mergeMap } from 'rxjs/operators';
66
import { Color } from '../shared/color.interfaces';
77
import {
8+
ADD_TOPIC,
9+
AddTopic,
10+
AddTopicFailed,
11+
AddTopicSuccess,
12+
DELETE_TASK,
13+
DeleteTask,
14+
DeleteTaskFailed,
15+
DeleteTaskSuccess,
816
GET_MATRIX_DATA,
917
GetMatrixData,
1018
GetMatrixDataFailed,
1119
GetMatrixDataSuccess,
1220
UPDATE_TASK,
21+
UPDATE_TOPIC,
1322
UpdateTask,
1423
UpdateTaskFailed,
1524
UpdateTaskSuccess,
25+
UpdateTopic,
26+
UpdateTopicFailed,
27+
UpdateTopicSuccess,
1628
} from './matrix.actions';
1729
import { MatrixData, Task, Topic } from './matrix.interfaces';
1830

@@ -62,4 +74,61 @@ export class MatrixEffects {
6274
),
6375
),
6476
);
77+
78+
@Effect()
79+
deleteTask$: Observable<Action> = this.actions$.pipe(
80+
ofType<DeleteTask>(DELETE_TASK),
81+
mergeMap((action) =>
82+
of(action.taskId).pipe(
83+
map(
84+
(taskId: number) =>
85+
new DeleteTaskSuccess(
86+
new Task(
87+
taskId,
88+
'deleted',
89+
1,
90+
1,
91+
1,
92+
1,
93+
21,
94+
'',
95+
false,
96+
true,
97+
undefined,
98+
undefined,
99+
new Date(),
100+
),
101+
),
102+
),
103+
catchError((message) => of(new DeleteTaskFailed(message))),
104+
),
105+
),
106+
);
107+
108+
@Effect()
109+
addTopic$: Observable<Action> = this.actions$.pipe(
110+
ofType<AddTopic>(ADD_TOPIC),
111+
mergeMap((action) =>
112+
of(Math.floor(Math.random() * (100 - 4) - 4)).pipe(
113+
map(
114+
(id: number) =>
115+
new AddTopicSuccess(
116+
new Topic(id, 'New Topic', Color.green, true, false),
117+
),
118+
),
119+
catchError((message) => of(new AddTopicFailed(message))),
120+
),
121+
),
122+
);
123+
124+
@Effect()
125+
updateTopic$: Observable<Action> = this.actions$.pipe(
126+
ofType<UpdateTopic>(UPDATE_TOPIC),
127+
mergeMap((action) =>
128+
of(action.topic).pipe(
129+
map((topic: Topic) => new UpdateTopicSuccess(topic)),
130+
catchError((message) => of(new UpdateTopicFailed(message))),
131+
),
132+
),
133+
);
65134
}

src/app/matrix/matrix.reducers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {
44
ADD_TOPIC,
55
ADD_TOPIC_FAILED,
66
ADD_TOPIC_SUCCESS,
7+
DELETE_TASK,
8+
DELETE_TASK_FAILED,
9+
DELETE_TASK_SUCCESS,
710
GET_MATRIX_DATA,
811
GET_MATRIX_DATA_FAILED,
912
GET_MATRIX_DATA_SUCCESS,
@@ -35,6 +38,7 @@ export function matrixReducer(state = initialState, action: Action) {
3538
case UPDATE_TASK:
3639
case UPDATE_TOPIC:
3740
case ADD_TOPIC:
41+
case DELETE_TASK:
3842
draft.isLoading = true;
3943
draft.errorMessage = undefined;
4044
return;
@@ -43,6 +47,7 @@ export function matrixReducer(state = initialState, action: Action) {
4347
case UPDATE_TASK_FAILED:
4448
case UPDATE_TOPIC_FAILED:
4549
case ADD_TOPIC_FAILED:
50+
case DELETE_TASK_FAILED:
4651
draft.isLoading = false;
4752
draft.errorMessage = matrixAction.message;
4853
return;
@@ -53,6 +58,7 @@ export function matrixReducer(state = initialState, action: Action) {
5358
setUnloading(draft);
5459
return;
5560
case UPDATE_TASK_SUCCESS:
61+
case DELETE_TASK_SUCCESS:
5662
const taskIndex = draft.tasks.findIndex(
5763
(task) => task.id === matrixAction.task.id,
5864
);

0 commit comments

Comments
 (0)