mirror of https://github.com/embarklabs/embark.git
store theme in localstorage
This commit is contained in:
parent
be0129fea9
commit
c833f9b3bf
|
@ -30,6 +30,14 @@ export const changeTheme = {
|
||||||
failure: (error) => action(CHANGE_THEME[FAILURE], {error})
|
failure: (error) => action(CHANGE_THEME[FAILURE], {error})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const FETCH_THEME = createRequestTypes('FETCH_THEME');
|
||||||
|
export const fetchTheme = {
|
||||||
|
request: () => action(FETCH_THEME[REQUEST]),
|
||||||
|
success: (theme) => action(FETCH_THEME[SUCCESS], {theme}),
|
||||||
|
failure: () => action(FETCH_THEME[FAILURE])
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export const FETCH_CREDENTIALS = createRequestTypes('FETCH_CREDENTIALS');
|
export const FETCH_CREDENTIALS = createRequestTypes('FETCH_CREDENTIALS');
|
||||||
export const fetchCredentials = {
|
export const fetchCredentials = {
|
||||||
request: () => action(FETCH_CREDENTIALS[REQUEST]),
|
request: () => action(FETCH_CREDENTIALS[REQUEST]),
|
||||||
|
@ -104,11 +112,15 @@ export const COMMANDS = createRequestTypes('COMMANDS');
|
||||||
export const commands = {
|
export const commands = {
|
||||||
post: (command) => action(COMMANDS[REQUEST], {command}),
|
post: (command) => action(COMMANDS[REQUEST], {command}),
|
||||||
success: (command, payload) => {
|
success: (command, payload) => {
|
||||||
return action(COMMANDS[SUCCESS], {processLogs: [{
|
return action(COMMANDS[SUCCESS], {
|
||||||
timestamp: new Date().getTime(),
|
processLogs: [
|
||||||
name: EMBARK_PROCESS_NAME,
|
{
|
||||||
msg: `console> ${payload.command}<br>${ansiToHtml(command.result)}`
|
timestamp: new Date().getTime(),
|
||||||
}]})
|
name: EMBARK_PROCESS_NAME,
|
||||||
|
msg: `console> ${payload.command}<br>${ansiToHtml(command.result)}`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
},
|
},
|
||||||
failure: (error) => action(COMMANDS[FAILURE], {error})
|
failure: (error) => action(COMMANDS[FAILURE], {error})
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
processes as processesAction,
|
processes as processesAction,
|
||||||
versions as versionsAction,
|
versions as versionsAction,
|
||||||
plugins as pluginsAction,
|
plugins as pluginsAction,
|
||||||
changeTheme
|
changeTheme, fetchTheme
|
||||||
} from '../actions';
|
} from '../actions';
|
||||||
|
|
||||||
import { getCredentials, getAuthenticationError, getVersions, getTheme } from '../reducers/selectors';
|
import { getCredentials, getAuthenticationError, getVersions, getTheme } from '../reducers/selectors';
|
||||||
|
@ -39,6 +39,7 @@ class AppContainer extends Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.fetchCredentials();
|
this.props.fetchCredentials();
|
||||||
|
this.props.fetchTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
requireAuthentication() {
|
requireAuthentication() {
|
||||||
|
@ -113,6 +114,7 @@ export default withRouter(connect(
|
||||||
fetchProcesses: processesAction.request,
|
fetchProcesses: processesAction.request,
|
||||||
fetchVersions: versionsAction.request,
|
fetchVersions: versionsAction.request,
|
||||||
fetchPlugins: pluginsAction.request,
|
fetchPlugins: pluginsAction.request,
|
||||||
changeTheme: changeTheme.request
|
changeTheme: changeTheme.request,
|
||||||
|
fetchTheme: fetchTheme.request
|
||||||
},
|
},
|
||||||
)(AppContainer));
|
)(AppContainer));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {combineReducers} from 'redux';
|
import {combineReducers} from 'redux';
|
||||||
import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE,
|
import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE,
|
||||||
FETCH_CREDENTIALS, UPDATE_BASE_ETHER, CHANGE_THEME} from "../actions";
|
FETCH_CREDENTIALS, UPDATE_BASE_ETHER, CHANGE_THEME, FETCH_THEME} from "../actions";
|
||||||
import {EMBARK_PROCESS_NAME} from '../constants';
|
import {EMBARK_PROCESS_NAME} from '../constants';
|
||||||
|
|
||||||
const BN_FACTOR = 10000;
|
const BN_FACTOR = 10000;
|
||||||
|
@ -86,7 +86,7 @@ const filtrer = {
|
||||||
},
|
},
|
||||||
processLogs: function(processLog, index, self) {
|
processLogs: function(processLog, index, self) {
|
||||||
if (processLog.id !== undefined) {
|
if (processLog.id !== undefined) {
|
||||||
return index === self.findIndex((p) => p.id === processLog.id) && index <= MAX_ELEMENTS
|
return index === self.findIndex((p) => p.id === processLog.id) && index <= MAX_ELEMENTS;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -224,7 +224,7 @@ function baseEther(state = '1', action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function theme(state='dark', action) {
|
function theme(state='dark', action) {
|
||||||
if (action.type === CHANGE_THEME[REQUEST]) {
|
if (action.type === CHANGE_THEME[REQUEST] || action.type === FETCH_THEME[SUCCESS]) {
|
||||||
return action.theme;
|
return action.theme;
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
|
|
@ -50,6 +50,8 @@ export const deleteCurrentFile = doRequest.bind(null, null, storage.deleteCurren
|
||||||
export const fetchCredentials = doRequest.bind(null, actions.fetchCredentials, storage.fetchCredentials);
|
export const fetchCredentials = doRequest.bind(null, actions.fetchCredentials, storage.fetchCredentials);
|
||||||
export const saveCredentials = doRequest.bind(null, actions.saveCredentials, storage.saveCredentials);
|
export const saveCredentials = doRequest.bind(null, actions.saveCredentials, storage.saveCredentials);
|
||||||
export const logout = doRequest.bind(null, actions.logout, storage.logout);
|
export const logout = doRequest.bind(null, actions.logout, storage.logout);
|
||||||
|
export const changeTheme = doRequest.bind(null, actions.changeTheme, storage.changeTheme);
|
||||||
|
export const fetchTheme = doRequest.bind(null, actions.fetchTheme, storage.fetchTheme);
|
||||||
|
|
||||||
|
|
||||||
export function *watchFetchTransaction() {
|
export function *watchFetchTransaction() {
|
||||||
|
@ -185,6 +187,14 @@ export function *watchAuthenticate() {
|
||||||
yield takeEvery(actions.AUTHENTICATE[actions.REQUEST], authenticate);
|
yield takeEvery(actions.AUTHENTICATE[actions.REQUEST], authenticate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function *watchChangeTheme() {
|
||||||
|
yield takeEvery(actions.CHANGE_THEME[actions.REQUEST], changeTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function *watchFetchTheme() {
|
||||||
|
yield takeEvery(actions.FETCH_THEME[actions.REQUEST], fetchTheme);
|
||||||
|
}
|
||||||
|
|
||||||
export function *watchAuthenticateSuccess() {
|
export function *watchAuthenticateSuccess() {
|
||||||
yield takeEvery(actions.AUTHENTICATE[actions.SUCCESS], saveCredentials);
|
yield takeEvery(actions.AUTHENTICATE[actions.SUCCESS], saveCredentials);
|
||||||
}
|
}
|
||||||
|
@ -341,6 +351,8 @@ export default function *root() {
|
||||||
fork(watchAuthenticate),
|
fork(watchAuthenticate),
|
||||||
fork(watchAuthenticateSuccess),
|
fork(watchAuthenticateSuccess),
|
||||||
fork(watchLogout),
|
fork(watchLogout),
|
||||||
|
fork(watchFetchTheme),
|
||||||
|
fork(watchChangeTheme),
|
||||||
fork(watchListenGasOracle)
|
fork(watchListenGasOracle)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export function deleteCurrentFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveCredentials({token, host}) {
|
export function saveCredentials({token, host}) {
|
||||||
const credentials = {token, host}
|
const credentials = {token, host};
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
localStorage.setItem('credentials', JSON.stringify(credentials));
|
localStorage.setItem('credentials', JSON.stringify(credentials));
|
||||||
resolve({response: {data: credentials}});
|
resolve({response: {data: credentials}});
|
||||||
|
@ -39,3 +39,16 @@ export function logout() {
|
||||||
resolve({response: true});
|
resolve({response: true});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function changeTheme({theme}) {
|
||||||
|
return new Promise(function(resolve) {
|
||||||
|
localStorage.setItem('theme', theme);
|
||||||
|
resolve({response: {data: theme}});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fetchTheme() {
|
||||||
|
return new Promise(function(resolve) {
|
||||||
|
resolve({response: {data: localStorage.getItem('theme')}});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue