Add manifest.json, icons and install button, flatten client/src
This commit is contained in:
parent
a219e689c1
commit
474afda9c2
105 changed files with 338 additions and 283 deletions
47
client/js/middleware/command.js
Normal file
47
client/js/middleware/command.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { addMessages, inform, print } from 'state/messages';
|
||||
import { isChannel } from 'utils';
|
||||
|
||||
export const beforeHandler = '_before';
|
||||
export const notFoundHandler = 'commandNotFound';
|
||||
|
||||
function createContext({ dispatch, getState }, { server, channel }) {
|
||||
return { dispatch, getState, server, channel, isChannel: isChannel(channel) };
|
||||
}
|
||||
|
||||
// TODO: Pull this out as convenience action
|
||||
function process({ dispatch, server, channel }, result) {
|
||||
if (typeof result === 'string') {
|
||||
dispatch(inform(result, server, channel));
|
||||
} else if (Array.isArray(result)) {
|
||||
if (typeof result[0] === 'string') {
|
||||
dispatch(inform(result, server, channel));
|
||||
} else if (typeof result[0] === 'object') {
|
||||
dispatch(addMessages(result, server, channel));
|
||||
}
|
||||
} else if (typeof result === 'object' && result) {
|
||||
dispatch(print(result.content, server, channel, result.type));
|
||||
}
|
||||
}
|
||||
|
||||
export default function createCommandMiddleware(type, handlers) {
|
||||
return store => next => action => {
|
||||
if (action.type === type) {
|
||||
const words = action.command.slice(1).split(' ');
|
||||
const command = words[0];
|
||||
const params = words.slice(1);
|
||||
|
||||
if (command in handlers) {
|
||||
const ctx = createContext(store, action);
|
||||
if (beforeHandler in handlers) {
|
||||
process(ctx, handlers[beforeHandler](ctx, command, ...params));
|
||||
}
|
||||
process(ctx, handlers[command](ctx, ...params));
|
||||
} else if (notFoundHandler in handlers) {
|
||||
const ctx = createContext(store, action);
|
||||
process(ctx, handlers[notFoundHandler](ctx, command, ...params));
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
};
|
||||
}
|
35
client/js/middleware/message.js
Normal file
35
client/js/middleware/message.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { ADD_MESSAGES, ADD_FETCHED_MESSAGES } from 'state/actions';
|
||||
|
||||
//
|
||||
// This middleware handles waiting until MessageBox
|
||||
// is ready before adding messages to the top
|
||||
//
|
||||
const message = store => next => {
|
||||
const ready = {};
|
||||
const cache = {};
|
||||
|
||||
return action => {
|
||||
if (action.type === ADD_MESSAGES && action.prepend) {
|
||||
const key = `${action.server} ${action.channel}`;
|
||||
|
||||
if (ready[key]) {
|
||||
ready[key] = false;
|
||||
return next(action);
|
||||
}
|
||||
|
||||
cache[key] = action;
|
||||
} else if (action.type === ADD_FETCHED_MESSAGES) {
|
||||
const key = `${action.server} ${action.channel}`;
|
||||
ready[key] = true;
|
||||
|
||||
if (cache[key]) {
|
||||
store.dispatch(cache[key]);
|
||||
cache[key] = undefined;
|
||||
}
|
||||
} else {
|
||||
return next(action);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default message;
|
36
client/js/middleware/socket.js
Normal file
36
client/js/middleware/socket.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
import debounce from 'lodash/debounce';
|
||||
|
||||
const debounceKey = action => {
|
||||
const { key } = action.socket.debounce;
|
||||
if (key) {
|
||||
return `${action.type} ${key}`;
|
||||
}
|
||||
return action.type;
|
||||
};
|
||||
|
||||
export default function createSocketMiddleware(socket) {
|
||||
return () => next => {
|
||||
const debounced = {};
|
||||
|
||||
return action => {
|
||||
if (action.socket) {
|
||||
if (action.socket.debounce) {
|
||||
const key = debounceKey(action);
|
||||
|
||||
if (!debounced[key]) {
|
||||
debounced[key] = debounce((type, data) => {
|
||||
socket.send(type, data);
|
||||
debounced[key] = undefined;
|
||||
}, action.socket.debounce.delay);
|
||||
}
|
||||
|
||||
debounced[key](action.socket.type, action.socket.data);
|
||||
} else {
|
||||
socket.send(action.socket.type, action.socket.data);
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue