Skip to content

Commit 6d0a9fe

Browse files
JcarlosjuniorRafael Santos
authored andcommitted
changing placeholder url to actual url
1 parent ed79f53 commit 6d0a9fe

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/lib/stores/PushAudiencesStore.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,39 @@ const LASTFETCHTIMEOUT = 60000;
2020
// - showMore: Flag to show/hide button to fetch all audiences
2121

2222
// xhr map, key value pair of xhrKey, xhr reference
23-
let xhrMap = {};
23+
//let xhrMap = {};
2424

2525
function PushAudiencesStore(state, action) {
2626
action.app.setParseKeys();
27-
let urlPrefix = `/apps/${action.app.slug}/dashboard_ajax/push_audiences`;
28-
let legacyUrlPrefix = `/apps/${action.app.slug}/push_audiences`;
2927
switch (action.type) {
3028
case ActionTypes.FETCH:
3129
if (state && new Date() - state.get('lastFetch') < LASTFETCHTIMEOUT) { //check for stale store
3230
if (state.get('audiences') && state.get('audiences').size >= (action.min || 0)) { //check for valid audience size
3331
return Parse.Promise.as(state);
3432
}
3533
}
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});
4045
});
4146
case ActionTypes.CREATE:
42-
return post(legacyUrlPrefix, {
47+
return action.app.apiRequest(
48+
'POST',
49+
'push_audiences',
50+
{
4351
query: action.query,
4452
name: action.name,
45-
}).then(({ new_audience }) => {
53+
},
54+
{ useMasterKey: true }
55+
).then(({ new_audience }) => {
4656
return state.update('audiences',(audiences) => {
4757
return audiences.unshift({
4858
createdAt: new Date(),
@@ -54,7 +64,12 @@ function PushAudiencesStore(state, action) {
5464
});
5565
});
5666
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(() => {
5873
return state.update('audiences',(audiences) => {
5974
let index = audiences.findIndex(function(audience) {
6075
return audience.objectId === action.objectId;
@@ -63,10 +78,12 @@ function PushAudiencesStore(state, action) {
6378
});
6479
});
6580
case ActionTypes.ABORT_FETCH:
66-
let xhrKey = action.xhrKey;
81+
82+
/*let xhrKey = action.xhrKey;
6783
if (xhrMap[xhrKey]) {
6884
xhrMap[xhrKey].abort();
69-
}
85+
}*/
86+
7087
return Parse.Promise.as(state);
7188
}
7289
}

0 commit comments

Comments
 (0)