dispatch/client/js/state/app.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

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 = {
2020-05-03 07:05:16 +00:00
connected: false,
2017-06-06 23:03:35 +00:00
wrapWidth: 0,
charWidth: 0,
windowWidth: 0,
2018-04-25 03:36:27 +00:00
connectDefaults: {
name: '',
host: '',
port: '',
2018-04-25 03:36:27 +00:00
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') {
Object.assign(state, key);
2018-11-22 11:00:18 +00:00
} else {
state[key] = value;
}
2017-06-06 23:03:35 +00:00
},
[actions.socket.CONNECTED](state, { connected }) {
state.connected = connected;
},
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;
2020-06-24 23:50:10 +00:00
},
[actions.INIT](state, { app }) {
Object.assign(state, app);
2017-06-06 23:03:35 +00:00
}
});
export function appSet(key, value) {
return {
type: actions.APP_SET,
key,
value
};
}
export function setCharWidth(width) {
return appSet('charWidth', width);
}