@@ -4,6 +4,12 @@ import * as ActionTypes from '../../../constants';
4
4
import { startLoader , stopLoader } from '../reducers/loading' ;
5
5
import { setToastText , showToast } from './toast' ;
6
6
7
+ import {
8
+ setCollections ,
9
+ delCollection ,
10
+ updateCollection
11
+ } from '../reducers/collections' ;
12
+
7
13
const TOAST_DISPLAY_TIME_MS = 1500 ;
8
14
9
15
export function getCollections ( username ) {
@@ -18,10 +24,7 @@ export function getCollections(username) {
18
24
return apiClient
19
25
. get ( url )
20
26
. then ( ( response ) => {
21
- dispatch ( {
22
- type : ActionTypes . SET_COLLECTIONS ,
23
- collections : response . data
24
- } ) ;
27
+ dispatch ( setCollections ( response . data ) ) ;
25
28
dispatch ( stopLoader ( ) ) ;
26
29
} )
27
30
. catch ( ( error ) => {
@@ -72,10 +75,7 @@ export function addToCollection(collectionId, projectId) {
72
75
return apiClient
73
76
. post ( url )
74
77
. then ( ( response ) => {
75
- dispatch ( {
76
- type : ActionTypes . ADD_TO_COLLECTION ,
77
- payload : response . data
78
- } ) ;
78
+ dispatch ( updateCollection ( response . data ) ) ;
79
79
dispatch ( stopLoader ( ) ) ;
80
80
81
81
const collectionName = response . data . name ;
@@ -102,10 +102,7 @@ export function removeFromCollection(collectionId, projectId) {
102
102
return apiClient
103
103
. delete ( url )
104
104
. then ( ( response ) => {
105
- dispatch ( {
106
- type : ActionTypes . REMOVE_FROM_COLLECTION ,
107
- payload : response . data
108
- } ) ;
105
+ dispatch ( updateCollection ( response . data ) ) ;
109
106
dispatch ( stopLoader ( ) ) ;
110
107
111
108
const collectionName = response . data . name ;
@@ -131,10 +128,7 @@ export function editCollection(collectionId, { name, description }) {
131
128
return apiClient
132
129
. patch ( url , { name, description } )
133
130
. then ( ( response ) => {
134
- dispatch ( {
135
- type : ActionTypes . EDIT_COLLECTION ,
136
- payload : response . data
137
- } ) ;
131
+ dispatch ( updateCollection ( response . data ) ) ;
138
132
return response . data ;
139
133
} )
140
134
. catch ( ( error ) => {
@@ -152,11 +146,7 @@ export function deleteCollection(collectionId) {
152
146
return apiClient
153
147
. delete ( url )
154
148
. then ( ( response ) => {
155
- dispatch ( {
156
- type : ActionTypes . DELETE_COLLECTION ,
157
- payload : response . data ,
158
- collectionId
159
- } ) ;
149
+ dispatch ( deleteCollection ( response . data , collectionId ) ) ;
160
150
return response . data ;
161
151
} )
162
152
. catch ( ( error ) => {
0 commit comments