1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 00:28:00 +02: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';
import { altWhitelabel } from '../alt';
import WhitelabelFetcher from '../fetchers/whitelabel_fetcher';
class WhitelabelActions {
constructor() {
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);

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 {
constructor() {
this.currentUser = {};
this.invalidateCache = false;
this.errorMessage = null;
this.userMeta = {
invalidateCache: false,
err: null
};
this.bindActions(UserActions);
this.registerAsync(UserSource);
}
onFetchCurrentUser(invalidateCache) {
this.invalidateCache = invalidateCache;
this.userMeta.invalidateCache = invalidateCache;
if(!this.getInstance().isLoading()) {
this.getInstance().lookupCurrentUser();
@ -25,7 +27,7 @@ class UserStore {
}
onSuccessFetchCurrentUser({users: [user]}) {
this.invalidateCache = false;
this.userMeta.invalidateCache = false;
this.currentUser = user;
}
@ -39,7 +41,7 @@ class UserStore {
onCurrentUserFailed(err) {
console.logGlobal(err);
this.errorMessage = err;
this.userMeta.err = err;
}
}

View File

@ -2,17 +2,38 @@
import { altWhitelabel } from '../alt';
import WhitelabelActions from '../actions/whitelabel_actions';
import WhitelabelSource from '../sources/whitelabel_source';
class WhitelabelStore {
constructor() {
this.whitelabel = {};
this.whitelabelMeta = {
invalidateCache: false,
err: null
};
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;
}
onWhitelabelFailed(err) {
console.logGlobal(err);
this.whitelabelMeta.err = err;
}
}
export default altWhitelabel.createStore(WhitelabelStore, 'WhitelabelStore');