dispatch/client/js/state/app.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-11-22 11:00:18 +00:00
import assign from 'lodash/assign';
import createReducer from 'utils/createReducer';
2017-06-06 23:03:35 +00:00
import * as actions from './actions';
export const getApp = state => state.app;
export const getConnected = state => state.app.connected;
export const getWrapWidth = state => state.app.wrapWidth;
export const getCharWidth = state => state.app.charWidth;
export const getWindowWidth = state => state.app.windowWidth;
export const getConnectDefaults = state => state.app.connectDefaults;
2018-04-25 03:36:27 +00:00
const initialState = {
2017-06-06 23:03:35 +00:00
connected: true,
wrapWidth: 0,
charWidth: 0,
windowWidth: 0,
2018-04-25 03:36:27 +00:00
connectDefaults: {
name: '',
address: '',
channels: [],
ssl: false,
password: false,
readonly: false,
showDetails: false
},
2018-11-06 10:13:32 +00:00
hexIP: false,
newVersionAvailable: false,
installable: null
2018-04-25 03:36:27 +00:00
};
2017-06-06 23:03:35 +00:00
2018-04-25 03:36:27 +00:00
export default createReducer(initialState, {
[actions.APP_SET](state, { key, value }) {
2018-11-22 11:00:18 +00:00
if (typeof key === 'object') {
assign(state, key);
} else {
state[key] = value;
}
2017-06-06 23:03:35 +00:00
},
[actions.UPDATE_MESSAGE_HEIGHT](state, action) {
2018-04-25 03:36:27 +00:00
state.wrapWidth = action.wrapWidth;
state.charWidth = action.charWidth;
state.windowWidth = action.windowWidth;
2017-06-06 23:03:35 +00:00
}
});
export function appSet(key, value) {
return {
type: actions.APP_SET,
key,
value
};
}
export function setConnected(connected) {
return appSet('connected', connected);
}
export function setCharWidth(width) {
return appSet('charWidth', width);
}
export function setConnectDefaults(defaults) {
2018-04-25 03:36:27 +00:00
return appSet('connectDefaults', defaults);
2017-06-06 23:03:35 +00:00
}