@@ -20,29 +20,39 @@ const LASTFETCHTIMEOUT = 60000;
20
20
// - showMore: Flag to show/hide button to fetch all audiences
21
21
22
22
// xhr map, key value pair of xhrKey, xhr reference
23
- let xhrMap = { } ;
23
+ // let xhrMap = {};
24
24
25
25
function PushAudiencesStore ( state , action ) {
26
26
action . app . setParseKeys ( ) ;
27
- let urlPrefix = `/apps/${ action . app . slug } /dashboard_ajax/push_audiences` ;
28
- let legacyUrlPrefix = `/apps/${ action . app . slug } /push_audiences` ;
29
27
switch ( action . type ) {
30
28
case ActionTypes . FETCH :
31
29
if ( state && new Date ( ) - state . get ( 'lastFetch' ) < LASTFETCHTIMEOUT ) { //check for stale store
32
30
if ( state . get ( 'audiences' ) && state . get ( 'audiences' ) . size >= ( action . min || 0 ) ) { //check for valid audience size
33
31
return Parse . Promise . as ( state ) ;
34
32
}
35
33
}
36
- let { xhr, promise} = abortableGet ( action . limit ? urlPrefix + `?audience_limit=${ action . limit } ` : urlPrefix , action . xhrKey !== null ) ;
37
- xhrMap [ action . xhrKey ] = xhr ;
38
- return promise . then ( ( { audiences, showMore } ) => {
39
- return Map ( { lastFetch : new Date ( ) , audiences : List ( audiences ) , showMore : showMore } ) ;
34
+ let promise = action . app . apiRequest (
35
+ 'GET' ,
36
+ action . limit ? `push_audiences?audience_limit=${ action . limit } ` : 'push_audiences' ,
37
+ { } ,
38
+ { useMasterKey : true }
39
+ ) ;
40
+
41
+ //xhrMap[action.xhrKey] = xhr;
42
+ //
43
+ return promise . then ( ( { results, showMore } ) => {
44
+ return Map ( { lastFetch : new Date ( ) , audiences : List ( results ) , showMore : showMore } ) ;
40
45
} ) ;
41
46
case ActionTypes . CREATE :
42
- return post ( legacyUrlPrefix , {
47
+ return action . app . apiRequest (
48
+ 'POST' ,
49
+ 'push_audiences' ,
50
+ {
43
51
query : action . query ,
44
52
name : action . name ,
45
- } ) . then ( ( { new_audience } ) => {
53
+ } ,
54
+ { useMasterKey : true }
55
+ ) . then ( ( { new_audience } ) => {
46
56
return state . update ( 'audiences' , ( audiences ) => {
47
57
return audiences . unshift ( {
48
58
createdAt : new Date ( ) ,
@@ -54,7 +64,12 @@ function PushAudiencesStore(state, action) {
54
64
} ) ;
55
65
} ) ;
56
66
case ActionTypes . DESTROY :
57
- return del ( legacyUrlPrefix + `/${ action . objectId } ` ) . then ( ( ) => {
67
+ return action . app . apiRequest (
68
+ 'DELETE' ,
69
+ `push_audiences/${ action . objectId } ` ,
70
+ { } ,
71
+ { useMasterKey : true }
72
+ ) . then ( ( ) => {
58
73
return state . update ( 'audiences' , ( audiences ) => {
59
74
let index = audiences . findIndex ( function ( audience ) {
60
75
return audience . objectId === action . objectId ;
@@ -63,10 +78,12 @@ function PushAudiencesStore(state, action) {
63
78
} ) ;
64
79
} ) ;
65
80
case ActionTypes . ABORT_FETCH :
66
- let xhrKey = action . xhrKey ;
81
+
82
+ /*let xhrKey = action.xhrKey;
67
83
if (xhrMap[xhrKey]) {
68
84
xhrMap[xhrKey].abort();
69
- }
85
+ }*/
86
+
70
87
return Parse . Promise . as ( state ) ;
71
88
}
72
89
}
0 commit comments