Combine init actions
This commit is contained in:
parent
02e9df865e
commit
d844f6ee1a
File diff suppressed because one or more lines are too long
@ -343,14 +343,18 @@ i[class*=' icon-']:before {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tab-prefix {
|
.tab-prefix {
|
||||||
color: #777;
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error .tab-prefix {
|
||||||
|
color: #f6546a;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-label {
|
.tab-label {
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #777;
|
color: #999;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
@ -369,7 +373,7 @@ i[class*=' icon-']:before {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
background: none;
|
background: none;
|
||||||
color: #777;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-label:hover button {
|
.tab-label:hover button {
|
||||||
@ -388,7 +392,7 @@ i[class*=' icon-']:before {
|
|||||||
|
|
||||||
.side-buttons button {
|
.side-buttons button {
|
||||||
background: #222;
|
background: #222;
|
||||||
color: #777;
|
color: #999;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ const Settings = ({
|
|||||||
<Checkbox
|
<Checkbox
|
||||||
name="coloredNicks"
|
name="coloredNicks"
|
||||||
label="Colored nicks"
|
label="Colored nicks"
|
||||||
checked={settings.coloredNicks}
|
checked={!!settings.coloredNicks}
|
||||||
onChange={e => setSetting('coloredNicks', e.target.checked)}
|
onChange={e => setSetting('coloredNicks', e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,56 +1,24 @@
|
|||||||
import { socket as socketActions } from 'state/actions';
|
import { INIT } from 'state/actions';
|
||||||
import { getConnected, getWrapWidth, appSet } from 'state/app';
|
import { getConnected, getWrapWidth } from 'state/app';
|
||||||
import { searchChannels } from 'state/channelSearch';
|
import { searchChannels } from 'state/channelSearch';
|
||||||
import { addMessages } from 'state/messages';
|
import { addMessages } from 'state/messages';
|
||||||
import { setSettings } from 'state/settings';
|
|
||||||
import { when } from 'utils/observe';
|
import { when } from 'utils/observe';
|
||||||
|
|
||||||
function loadState({ store }, env) {
|
function loadState({ store }, env) {
|
||||||
store.dispatch(setSettings(env.settings, true));
|
store.dispatch({
|
||||||
|
type: INIT,
|
||||||
if (env.networks) {
|
settings: env.settings,
|
||||||
store.dispatch({
|
networks: env.networks,
|
||||||
type: socketActions.NETWORKS,
|
channels: env.channels,
|
||||||
data: env.networks
|
openDMs: env.openDMs,
|
||||||
});
|
users: env.users,
|
||||||
|
app: {
|
||||||
when(store, getConnected, () =>
|
|
||||||
// Cache top channels for each network
|
|
||||||
env.networks.forEach(({ host }) =>
|
|
||||||
store.dispatch(searchChannels(host, ''))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (env.channels) {
|
|
||||||
store.dispatch({
|
|
||||||
type: socketActions.CHANNELS,
|
|
||||||
data: env.channels
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (env.openDMs) {
|
|
||||||
store.dispatch({
|
|
||||||
type: 'PRIVATE_CHATS',
|
|
||||||
privateChats: env.openDMs
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (env.users) {
|
|
||||||
store.dispatch({
|
|
||||||
type: socketActions.USERS,
|
|
||||||
...env.users
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
appSet({
|
|
||||||
connectDefaults: env.defaults,
|
connectDefaults: env.defaults,
|
||||||
initialized: true,
|
initialized: true,
|
||||||
hexIP: env.hexIP,
|
hexIP: env.hexIP,
|
||||||
version: env.version
|
version: env.version
|
||||||
})
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
if (env.messages) {
|
if (env.messages) {
|
||||||
// Wait until wrapWidth gets initialized so that height calculations
|
// Wait until wrapWidth gets initialized so that height calculations
|
||||||
@ -60,6 +28,15 @@ function loadState({ store }, env) {
|
|||||||
store.dispatch(addMessages(messages, network, to, false, next));
|
store.dispatch(addMessages(messages, network, to, false, next));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (env.networks) {
|
||||||
|
when(store, getConnected, () =>
|
||||||
|
// Cache top channels for each network
|
||||||
|
env.networks.forEach(({ host }) =>
|
||||||
|
store.dispatch(searchChannels(host, ''))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable no-underscore-dangle */
|
/* eslint-disable no-underscore-dangle */
|
||||||
|
@ -276,31 +276,31 @@ describe('channel reducer', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles SOCKET_CHANNELS', () => {
|
it('handles channels from INIT', () => {
|
||||||
const state = reducer(undefined, {
|
const state = reducer(undefined, {
|
||||||
type: actions.socket.CHANNELS,
|
type: actions.INIT,
|
||||||
data: [
|
channels: [
|
||||||
{ network: 'srv', name: 'chan1', topic: 'the topic' },
|
{ network: 'srv', name: 'chan1', topic: 'the topic' },
|
||||||
{ network: 'srv', name: 'chan2' },
|
{ network: 'srv', name: 'chan2', joined: true },
|
||||||
{ network: 'srv2', name: 'chan1' }
|
{ network: 'srv2', name: 'chan1' }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(state).toEqual({
|
expect(state).toEqual({
|
||||||
srv: {
|
srv: {
|
||||||
chan1: { name: 'chan1', joined: true, topic: 'the topic', users: [] },
|
chan1: { name: 'chan1', topic: 'the topic', users: [] },
|
||||||
chan2: { name: 'chan2', joined: true, users: [] }
|
chan2: { name: 'chan2', joined: true, users: [] }
|
||||||
},
|
},
|
||||||
srv2: {
|
srv2: {
|
||||||
chan1: { name: 'chan1', joined: true, users: [] }
|
chan1: { name: 'chan1', users: [] }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles SOCKET_NETWORKS', () => {
|
it('handles networks from INIT', () => {
|
||||||
const state = reducer(undefined, {
|
const state = reducer(undefined, {
|
||||||
type: actions.socket.NETWORKS,
|
type: actions.INIT,
|
||||||
data: [{ host: '127.0.0.1' }, { host: 'thehost' }]
|
networks: [{ host: '127.0.0.1' }, { host: 'thehost' }]
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(state).toEqual({
|
expect(state).toEqual({
|
||||||
|
@ -182,10 +182,10 @@ describe('network reducer', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds the networks on SOCKET_NETWORKS', () => {
|
it('adds the networks on INIT', () => {
|
||||||
let state = reducer(undefined, {
|
let state = reducer(undefined, {
|
||||||
type: actions.socket.NETWORKS,
|
type: actions.INIT,
|
||||||
data: [
|
networks: [
|
||||||
{
|
{
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
name: 'stuff',
|
name: 'stuff',
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
export const INIT = 'INIT';
|
||||||
export const APP_SET = 'APP_SET';
|
export const APP_SET = 'APP_SET';
|
||||||
|
|
||||||
export const INVITE = 'INVITE';
|
export const INVITE = 'INVITE';
|
||||||
@ -27,7 +28,6 @@ export const CLOSE_MODAL = 'CLOSE_MODAL';
|
|||||||
|
|
||||||
export const CLOSE_PRIVATE_CHAT = 'CLOSE_PRIVATE_CHAT';
|
export const CLOSE_PRIVATE_CHAT = 'CLOSE_PRIVATE_CHAT';
|
||||||
export const OPEN_PRIVATE_CHAT = 'OPEN_PRIVATE_CHAT';
|
export const OPEN_PRIVATE_CHAT = 'OPEN_PRIVATE_CHAT';
|
||||||
export const PRIVATE_CHATS = 'PRIVATE_CHATS';
|
|
||||||
|
|
||||||
export const SEARCH_MESSAGES = 'SEARCH_MESSAGES';
|
export const SEARCH_MESSAGES = 'SEARCH_MESSAGES';
|
||||||
export const TOGGLE_SEARCH = 'TOGGLE_SEARCH';
|
export const TOGGLE_SEARCH = 'TOGGLE_SEARCH';
|
||||||
@ -67,7 +67,6 @@ function createSocketActions(types) {
|
|||||||
export const socket = createSocketActions([
|
export const socket = createSocketActions([
|
||||||
'cert_fail',
|
'cert_fail',
|
||||||
'cert_success',
|
'cert_success',
|
||||||
'channels',
|
|
||||||
'channel_forward',
|
'channel_forward',
|
||||||
'channel_search',
|
'channel_search',
|
||||||
'connected',
|
'connected',
|
||||||
@ -84,7 +83,6 @@ export const socket = createSocketActions([
|
|||||||
'pm',
|
'pm',
|
||||||
'quit',
|
'quit',
|
||||||
'search',
|
'search',
|
||||||
'networks',
|
|
||||||
'topic',
|
'topic',
|
||||||
'users'
|
'users'
|
||||||
]);
|
]);
|
||||||
|
@ -45,6 +45,10 @@ export default createReducer(initialState, {
|
|||||||
state.wrapWidth = action.wrapWidth;
|
state.wrapWidth = action.wrapWidth;
|
||||||
state.charWidth = action.charWidth;
|
state.charWidth = action.charWidth;
|
||||||
state.windowWidth = action.windowWidth;
|
state.windowWidth = action.windowWidth;
|
||||||
|
},
|
||||||
|
|
||||||
|
[actions.INIT](state, { app }) {
|
||||||
|
Object.assign(state, app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -183,14 +183,6 @@ export default createReducer(
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.socket.USERS](state, { network, channel, users }) {
|
|
||||||
state[network][channel].users = users.map(nick => loadUser(nick));
|
|
||||||
},
|
|
||||||
|
|
||||||
[actions.socket.TOPIC](state, { network, channel, topic }) {
|
|
||||||
state[network][channel].topic = topic;
|
|
||||||
},
|
|
||||||
|
|
||||||
[actions.socket.MODE](state, { network, channel, user, remove, add }) {
|
[actions.socket.MODE](state, { network, channel, user, remove, add }) {
|
||||||
const u = find(state[network][channel].users, v => v.nick === user);
|
const u = find(state[network][channel].users, v => v.nick === user);
|
||||||
if (u) {
|
if (u) {
|
||||||
@ -209,19 +201,31 @@ export default createReducer(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.socket.CHANNELS](state, { data }) {
|
[actions.socket.TOPIC](state, { network, channel, topic }) {
|
||||||
if (data) {
|
state[network][channel].topic = topic;
|
||||||
data.forEach(({ network, name, topic }) => {
|
},
|
||||||
|
|
||||||
|
[actions.socket.USERS](state, { network, channel, users }) {
|
||||||
|
state[network][channel].users = users.map(nick => loadUser(nick));
|
||||||
|
},
|
||||||
|
|
||||||
|
[actions.INIT](state, { networks, channels, users }) {
|
||||||
|
if (networks) {
|
||||||
|
networks.forEach(({ host }) => init(state, host));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channels) {
|
||||||
|
channels.forEach(({ network, name, topic, joined }) => {
|
||||||
const chan = init(state, network, name);
|
const chan = init(state, network, name);
|
||||||
chan.joined = true;
|
chan.joined = joined;
|
||||||
chan.topic = topic;
|
chan.topic = topic;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
[actions.socket.NETWORKS](state, { data }) {
|
if (users) {
|
||||||
if (data) {
|
state[users.network][users.channel].users = users.users.map(nick =>
|
||||||
data.forEach(({ host }) => init(state, host));
|
loadUser(nick)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -76,9 +76,9 @@ export default createReducer(
|
|||||||
state[network].editedNick = null;
|
state[network].editedNick = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.socket.NETWORKS](state, { data }) {
|
[actions.INIT](state, { networks }) {
|
||||||
if (data) {
|
if (networks) {
|
||||||
data.forEach(
|
networks.forEach(
|
||||||
({ host, name = host, nick, connected, error, features = {} }) => {
|
({ host, name = host, nick, connected, error, features = {} }) => {
|
||||||
state[host] = {
|
state[host] = {
|
||||||
name,
|
name,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import sortBy from 'lodash/sortBy';
|
import sortBy from 'lodash/sortBy';
|
||||||
import { isChannel } from 'utils';
|
import { isDM } from 'utils';
|
||||||
import createReducer from 'utils/createReducer';
|
import createReducer from 'utils/createReducer';
|
||||||
import { updateSelection } from './tab';
|
import { updateSelection } from './tab';
|
||||||
import * as actions from './actions';
|
import * as actions from './actions';
|
||||||
@ -30,20 +30,21 @@ export default createReducer(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.PRIVATE_CHATS](state, { privateChats }) {
|
[actions.INIT](state, { openDMs }) {
|
||||||
privateChats.forEach(({ network, name }) => {
|
if (openDMs) {
|
||||||
if (!state[network]) {
|
openDMs.forEach(({ network, name }) => {
|
||||||
state[network] = [];
|
if (!state[network]) {
|
||||||
}
|
state[network] = [];
|
||||||
|
}
|
||||||
|
|
||||||
state[network].push(name);
|
state[network].push(name);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.ADD_MESSAGE](state, { message }) {
|
[actions.ADD_MESSAGE](state, { message }) {
|
||||||
const { network, from, to } = message;
|
if (isDM(message)) {
|
||||||
if (!to && from.indexOf('.') === -1 && !isChannel(from)) {
|
open(state, message.network, message.from);
|
||||||
open(state, network, from);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -44,6 +44,10 @@ export default createReducer(
|
|||||||
} else {
|
} else {
|
||||||
state[key] = value;
|
state[key] = value;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
[actions.INIT](state, { settings }) {
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -34,6 +34,10 @@ function isString(s, maxLength) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isDM({ from, to }) {
|
||||||
|
return !to && from?.indexOf('.') === -1 && !isChannel(from);
|
||||||
|
}
|
||||||
|
|
||||||
export function trimPrefixChar(str, char) {
|
export function trimPrefixChar(str, char) {
|
||||||
if (!isString(str)) {
|
if (!isString(str)) {
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
Reference in New Issue
Block a user