Skip to content

Commit b2db936

Browse files
committed
Enabling audiences UI
1 parent 89a4d12 commit b2db936

File tree

2 files changed

+25
-32
lines changed

2 files changed

+25
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* _Contributing to this repo? Add info about your change here to be included in next release_
66
* Feature: When editing Object or Array fields the data is displayed in a prettier format and the textarea is resizable
77
* Fix: Display bug on safari when table has empty cells ('')
8+
* Feature: UI for managing push audiences, thanks to [Davi Macedo](https://github.com/davimacedo)
89

910
### 1.0.28
1011
* Feature: Add ability to search Object columns (#727), thanks to [Samuli Siivinen](https://github.com/ssamuli)

src/lib/stores/PushAudiencesStore.js

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8-
import { abortableGet, post, del } from 'lib/AJAX';
98
import keyMirror from 'lib/keyMirror';
109
import Parse from 'parse';
1110
import { List, Map } from 'immutable';
@@ -20,53 +19,46 @@ const LASTFETCHTIMEOUT = 60000;
2019
// - showMore: Flag to show/hide button to fetch all audiences
2120

2221
// xhr map, key value pair of xhrKey, xhr reference
23-
let xhrMap = {};
2422

2523
function PushAudiencesStore(state, action) {
2624
action.app.setParseKeys();
27-
let urlPrefix = `/apps/${action.app.slug}/dashboard_ajax/push_audiences`;
28-
let legacyUrlPrefix = `/apps/${action.app.slug}/push_audiences`;
2925
switch (action.type) {
3026
case ActionTypes.FETCH:
3127
if (state && new Date() - state.get('lastFetch') < LASTFETCHTIMEOUT) { //check for stale store
3228
if (state.get('audiences') && state.get('audiences').size >= (action.min || 0)) { //check for valid audience size
3329
return Parse.Promise.as(state);
3430
}
3531
}
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});
32+
const path = action.limit ? `push_audiences?audience_limit=${action.limit}` : 'push_audiences';
33+
const promise = Parse._request('GET', path, {}, { useMasterKey: true });
34+
35+
return promise.then(({ results, showMore }) => {
36+
return Map({ lastFetch: new Date(), audiences: List(results), showMore: showMore});
4037
});
4138
case ActionTypes.CREATE:
42-
return post(legacyUrlPrefix, {
43-
query: action.query,
44-
name: action.name,
45-
}).then(({ new_audience }) => {
46-
return state.update('audiences',(audiences) => {
47-
return audiences.unshift({
48-
createdAt: new Date(),
49-
name: action.name,
50-
objectId: new_audience ? new_audience.objectId || -1 : -1,
51-
count: 0,
52-
query: JSON.parse(action.query),
39+
return Parse._request('POST', 'push_audiences', { query: action.query, name: action.name, }, { useMasterKey: true })
40+
.then(({ new_audience }) => {
41+
return state.update('audiences',(audiences) => {
42+
return audiences.unshift({
43+
createdAt: new Date(),
44+
name: action.name,
45+
objectId: new_audience ? new_audience.objectId || -1 : -1,
46+
count: 0,
47+
query: JSON.parse(action.query),
48+
});
49+
});
5350
});
54-
});
55-
});
5651
case ActionTypes.DESTROY:
57-
return del(legacyUrlPrefix + `/${action.objectId}`).then(() => {
58-
return state.update('audiences',(audiences) => {
59-
let index = audiences.findIndex(function(audience) {
60-
return audience.objectId === action.objectId;
52+
return Parse._request('DELETE', `push_audiences/${action.objectId}`, {}, { useMasterKey: true })
53+
.then(() => {
54+
return state.update('audiences',(audiences) => {
55+
let index = audiences.findIndex(function(audience) {
56+
return audience.objectId === action.objectId;
57+
});
58+
return audiences.delete(index);
59+
});
6160
});
62-
return audiences.delete(index);
63-
});
64-
});
6561
case ActionTypes.ABORT_FETCH:
66-
let xhrKey = action.xhrKey;
67-
if (xhrMap[xhrKey]) {
68-
xhrMap[xhrKey].abort();
69-
}
7062
return Parse.Promise.as(state);
7163
}
7264
}

0 commit comments

Comments
 (0)