Rename state/environment to state/app
This commit is contained in:
parent
1beb56abcf
commit
b0b9904bc1
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { createStructuredSelector } from 'reselect';
|
||||
import App from '../components/App';
|
||||
import { getConnected } from '../state/app';
|
||||
import { getChannels } from '../state/channels';
|
||||
import { getPrivateChats } from '../state/privateChats';
|
||||
import { getServers } from '../state/servers';
|
||||
@ -10,7 +11,7 @@ import { push } from '../util/router';
|
||||
|
||||
const mapState = createStructuredSelector({
|
||||
channels: getChannels,
|
||||
connected: state => state.environment.get('connected'),
|
||||
connected: getConnected,
|
||||
privateChats: getPrivateChats,
|
||||
servers: getServers,
|
||||
showTabList: getShowTabList,
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { createStructuredSelector } from 'reselect';
|
||||
import Connect from '../components/pages/Connect';
|
||||
import { getConnectDefaults } from '../state/app';
|
||||
import { join } from '../state/channels';
|
||||
import { getConnectDefaults } from '../state/environment';
|
||||
import { connect as connectServer } from '../state/servers';
|
||||
import { select } from '../state/tab';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import FontFaceObserver from 'fontfaceobserver';
|
||||
import { setCharWidth } from '../state/environment';
|
||||
import { setCharWidth } from '../state/app';
|
||||
import { stringWidth } from '../util';
|
||||
|
||||
export default function fonts({ store }) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Cookie from 'js-cookie';
|
||||
import { socket as socketActions } from '../state/actions';
|
||||
import { getWrapWidth, setEnvironment } from '../state/environment';
|
||||
import { getWrapWidth, setConnectDefaults } from '../state/app';
|
||||
import { addMessages } from '../state/messages';
|
||||
import { select, updateSelection } from '../state/tab';
|
||||
import { find } from '../util';
|
||||
@ -10,7 +10,7 @@ import { replace } from '../util/router';
|
||||
export default function initialState({ store }) {
|
||||
const env = JSON.parse(document.getElementById('env').innerHTML);
|
||||
|
||||
store.dispatch(setEnvironment('connect_defaults', env.defaults));
|
||||
store.dispatch(setConnectDefaults(env.defaults));
|
||||
|
||||
if (env.servers) {
|
||||
store.dispatch({
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { socketAction } from '../state/actions';
|
||||
import { setEnvironment } from '../state/environment';
|
||||
import { setConnected } from '../state/app';
|
||||
import { broadcast, inform, print, addMessage, addMessages } from '../state/messages';
|
||||
import { select } from '../state/tab';
|
||||
import { normalizeChannel } from '../util';
|
||||
@ -106,7 +106,7 @@ export default function handleSocket({ socket, store: { dispatch, getState } })
|
||||
},
|
||||
|
||||
_connected(connected) {
|
||||
dispatch(setEnvironment('connected', connected));
|
||||
dispatch(setConnected(connected));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { when } from '../util/observe';
|
||||
import { measureScrollBarWidth } from '../util';
|
||||
import { getCharWidth } from '../state/environment';
|
||||
import { getCharWidth } from '../state/app';
|
||||
import { updateMessageHeight } from '../state/messages';
|
||||
|
||||
const menuWidth = 200;
|
||||
|
@ -1,11 +1,11 @@
|
||||
export const APP_SET = 'APP_SET';
|
||||
|
||||
export const INVITE = 'INVITE';
|
||||
export const JOIN = 'JOIN';
|
||||
export const KICK = 'KICK';
|
||||
export const PART = 'PART';
|
||||
export const SET_TOPIC = 'SET_TOPIC';
|
||||
|
||||
export const SET_ENVIRONMENT = 'SET_ENVIRONMENT';
|
||||
|
||||
export const INPUT_HISTORY_ADD = 'INPUT_HISTORY_ADD';
|
||||
export const INPUT_HISTORY_DECREMENT = 'INPUT_HISTORY_DECREMENT';
|
||||
export const INPUT_HISTORY_INCREMENT = 'INPUT_HISTORY_INCREMENT';
|
||||
|
59
client/src/js/state/app.js
Normal file
59
client/src/js/state/app.js
Normal file
@ -0,0 +1,59 @@
|
||||
import { Record } from 'immutable';
|
||||
import createReducer from '../util/createReducer';
|
||||
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;
|
||||
|
||||
const ConnectDefaults = Record({
|
||||
name: '',
|
||||
address: '',
|
||||
channels: [],
|
||||
ssl: false,
|
||||
password: false
|
||||
});
|
||||
|
||||
const App = Record({
|
||||
connected: true,
|
||||
wrapWidth: 0,
|
||||
charWidth: 0,
|
||||
windowWidth: 0,
|
||||
connectDefaults: new ConnectDefaults()
|
||||
});
|
||||
|
||||
export default createReducer(new App(), {
|
||||
[actions.APP_SET](state, action) {
|
||||
return state.set(action.key, action.value);
|
||||
},
|
||||
|
||||
[actions.UPDATE_MESSAGE_HEIGHT](state, action) {
|
||||
return state
|
||||
.set('wrapWidth', action.wrapWidth)
|
||||
.set('charWidth', action.charWidth)
|
||||
.set('windowWidth', action.windowWidth);
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
return appSet('connectDefaults', new ConnectDefaults(defaults));
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
import { Map } from 'immutable';
|
||||
import createReducer from '../util/createReducer';
|
||||
import * as actions from './actions';
|
||||
|
||||
export const getEnvironment = state => state.environment;
|
||||
|
||||
export const getWrapWidth = state => state.environment.get('wrapWidth');
|
||||
export const getCharWidth = state => state.environment.get('charWidth');
|
||||
export const getWindowWidth = state => state.environment.get('windowWidth');
|
||||
|
||||
export const getConnectDefaults = state => state.environment.get('connect_defaults');
|
||||
|
||||
const initialState = Map({
|
||||
connected: true
|
||||
});
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[actions.SET_ENVIRONMENT](state, action) {
|
||||
return state.set(action.key, action.value);
|
||||
},
|
||||
|
||||
[actions.UPDATE_MESSAGE_HEIGHT](state, action) {
|
||||
return state
|
||||
.set('wrapWidth', action.wrapWidth)
|
||||
.set('charWidth', action.charWidth)
|
||||
.set('windowWidth', action.windowWidth);
|
||||
}
|
||||
});
|
||||
|
||||
export function setEnvironment(key, value) {
|
||||
return {
|
||||
type: actions.SET_ENVIRONMENT,
|
||||
key,
|
||||
value
|
||||
};
|
||||
}
|
||||
|
||||
export function setWrapWidth(width) {
|
||||
return setEnvironment('wrapWidth', width);
|
||||
}
|
||||
|
||||
export function setCharWidth(width) {
|
||||
return setEnvironment('charWidth', width);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import app from './app';
|
||||
import channels from './channels';
|
||||
import environment from './environment';
|
||||
import input from './input';
|
||||
import messages from './messages';
|
||||
import privateChats from './privateChats';
|
||||
@ -16,8 +16,8 @@ export const getRouter = state => state.router;
|
||||
export default function createReducer(router) {
|
||||
return combineReducers({
|
||||
router,
|
||||
app,
|
||||
channels,
|
||||
environment,
|
||||
input,
|
||||
messages,
|
||||
privateChats,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { List, Map, Record } from 'immutable';
|
||||
import { createSelector } from 'reselect';
|
||||
import createReducer from '../util/createReducer';
|
||||
import { getWrapWidth, getCharWidth, getWindowWidth } from './environment';
|
||||
import { getApp } from './app';
|
||||
import { getSelectedTab } from './tab';
|
||||
import { findBreakpoints, messageHeight, linkify, timestamp } from '../util';
|
||||
import * as actions from './actions';
|
||||
@ -107,9 +107,7 @@ function initMessage(message, tab, state) {
|
||||
message.content = from + message.content.slice(7, -1);
|
||||
}
|
||||
|
||||
const wrapWidth = getWrapWidth(state);
|
||||
const charWidth = getCharWidth(state);
|
||||
const windowWidth = getWindowWidth(state);
|
||||
const { wrapWidth, charWidth, windowWidth } = getApp(state);
|
||||
|
||||
message.length = message.content.length;
|
||||
message.breakpoints = findBreakpoints(message.content);
|
||||
|
Loading…
Reference in New Issue
Block a user