1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 18:35:09 +01:00

Convert WhitelabelFetcher to WhitelabelSource

This commit is contained in:
Tim Daubenschütz 2015-11-03 10:07:44 +01:00
parent 6a0c4b4272
commit 35e9bedf04
4 changed files with 32 additions and 39 deletions

View File

@ -1,29 +1,16 @@
'use strict'; 'use strict';
import { altWhitelabel } from '../alt'; import { altWhitelabel } from '../alt';
import WhitelabelFetcher from '../fetchers/whitelabel_fetcher';
class WhitelabelActions { class WhitelabelActions {
constructor() { constructor() {
this.generateActions( this.generateActions(
'updateWhitelabel' 'fetchWhitelabel',
'successFetchWhitelabel',
'whitelabelFailed'
); );
} }
fetchWhitelabel() {
WhitelabelFetcher.fetch()
.then((res) => {
if(res && res.whitelabel) {
this.actions.updateWhitelabel(res.whitelabel);
} else {
this.actions.updateWhitelabel({});
}
})
.catch((err) => {
console.logGlobal(err);
});
}
} }
export default altWhitelabel.createActions(WhitelabelActions); export default altWhitelabel.createActions(WhitelabelActions);

View File

@ -1,17 +0,0 @@
'use strict';
import requests from '../utils/requests';
import { getSubdomain } from '../utils/general_utils';
let WhitelabelFetcher = {
/**
* Fetch the custom whitelabel data from the API.
*/
fetch() {
return requests.get('whitelabel_settings', {'subdomain': getSubdomain()});
}
};
export default WhitelabelFetcher;

View File

@ -9,15 +9,17 @@ import UserSource from '../sources/user_source';
class UserStore { class UserStore {
constructor() { constructor() {
this.currentUser = {}; this.currentUser = {};
this.invalidateCache = false; this.userMeta = {
this.errorMessage = null; invalidateCache: false,
err: null
};
this.bindActions(UserActions); this.bindActions(UserActions);
this.registerAsync(UserSource); this.registerAsync(UserSource);
} }
onFetchCurrentUser(invalidateCache) { onFetchCurrentUser(invalidateCache) {
this.invalidateCache = invalidateCache; this.userMeta.invalidateCache = invalidateCache;
if(!this.getInstance().isLoading()) { if(!this.getInstance().isLoading()) {
this.getInstance().lookupCurrentUser(); this.getInstance().lookupCurrentUser();
@ -25,7 +27,7 @@ class UserStore {
} }
onSuccessFetchCurrentUser({users: [user]}) { onSuccessFetchCurrentUser({users: [user]}) {
this.invalidateCache = false; this.userMeta.invalidateCache = false;
this.currentUser = user; this.currentUser = user;
} }
@ -39,7 +41,7 @@ class UserStore {
onCurrentUserFailed(err) { onCurrentUserFailed(err) {
console.logGlobal(err); console.logGlobal(err);
this.errorMessage = err; this.userMeta.err = err;
} }
} }

View File

@ -2,17 +2,38 @@
import { altWhitelabel } from '../alt'; import { altWhitelabel } from '../alt';
import WhitelabelActions from '../actions/whitelabel_actions'; import WhitelabelActions from '../actions/whitelabel_actions';
import WhitelabelSource from '../sources/whitelabel_source';
class WhitelabelStore { class WhitelabelStore {
constructor() { constructor() {
this.whitelabel = {}; this.whitelabel = {};
this.whitelabelMeta = {
invalidateCache: false,
err: null
};
this.bindActions(WhitelabelActions); this.bindActions(WhitelabelActions);
this.registerAsync(WhitelabelSource);
} }
onUpdateWhitelabel(whitelabel) { onFetchWhitelabel(invalidateCache) {
this.whitelabelMeta.invalidateCache = invalidateCache;
if(!this.getInstance().isLoading()) {
this.getInstance().lookupWhitelabel();
}
}
onSuccessFetchWhitelabel(whitelabel) {
this.whitelabelMeta.invalidateCache = false;
this.whitelabel = whitelabel; this.whitelabel = whitelabel;
} }
onWhitelabelFailed(err) {
console.logGlobal(err);
this.whitelabelMeta.err = err;
}
} }
export default altWhitelabel.createStore(WhitelabelStore, 'WhitelabelStore'); export default altWhitelabel.createStore(WhitelabelStore, 'WhitelabelStore');