Inform about commands not found
This commit is contained in:
parent
7e080f2c99
commit
41d6099d89
File diff suppressed because one or more lines are too long
@ -7,6 +7,7 @@
|
||||
"rules": {
|
||||
"arrow-parens": 0,
|
||||
"comma-dangle": [2, "never"],
|
||||
"consistent-return": 0,
|
||||
"jsx-a11y/no-static-element-interactions": 0,
|
||||
"new-cap": [2, { "capIsNewExceptions": ["Map", "List", "Record", "Set"] }],
|
||||
"no-console": 0,
|
||||
|
@ -96,10 +96,12 @@ i[class^="icon-"]:before, i[class*=" icon-"]:before {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.tab-indicator {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
.tab-label {
|
||||
margin-top: 10px;
|
||||
margin-left: 15px;
|
||||
margin-bottom: 5px;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.button-connect {
|
||||
|
@ -3,7 +3,7 @@ import { COMMAND } from './actions';
|
||||
import { setNick, disconnect, whois, away } from './actions/server';
|
||||
import { join, part, invite, kick } from './actions/channel';
|
||||
import { select } from './actions/tab';
|
||||
import { sendMessage, addMessage, inform, raw } from './actions/message';
|
||||
import { sendMessage, addMessage, raw } from './actions/message';
|
||||
|
||||
const help = [
|
||||
'/join <channel> - Join a channel',
|
||||
@ -62,7 +62,7 @@ export default createCommandMiddleware(COMMAND, {
|
||||
content: topic
|
||||
}));
|
||||
} else {
|
||||
dispatch(inform('No topic set', server, channel));
|
||||
return 'No topic set';
|
||||
}
|
||||
},
|
||||
|
||||
@ -104,11 +104,17 @@ export default createCommandMiddleware(COMMAND, {
|
||||
|
||||
raw({ dispatch, server }, ...message) {
|
||||
if (message) {
|
||||
dispatch(raw(message.join(' '), server));
|
||||
const cmd = message.join(' ');
|
||||
dispatch(raw(cmd, server));
|
||||
return `=> ${cmd}`;
|
||||
}
|
||||
},
|
||||
|
||||
help({ dispatch, server, channel }) {
|
||||
dispatch(inform(help, server, channel));
|
||||
help() {
|
||||
return help;
|
||||
},
|
||||
|
||||
commandNotFound(_, command) {
|
||||
return `The command /${command} was not found`;
|
||||
}
|
||||
});
|
||||
|
@ -34,7 +34,9 @@ export default class TabList extends PureComponent {
|
||||
/>
|
||||
));
|
||||
|
||||
if (privateChats.has(address)) {
|
||||
if (privateChats.has(address) && privateChats.get(address).size > 0) {
|
||||
tabs.push(<div className="tab-label">Private messages</div>);
|
||||
|
||||
privateChats.get(address).forEach(nick => tabs.push(
|
||||
<TabListItem
|
||||
key={address + nick}
|
||||
|
@ -7,34 +7,27 @@ export default class TabListItem extends PureComponent {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { target, content, selected } = this.props;
|
||||
const { target, content, selected, connected } = this.props;
|
||||
const classes = [];
|
||||
const style = {};
|
||||
|
||||
if (!target) {
|
||||
classes.push('tab-server');
|
||||
|
||||
if (connected) {
|
||||
style.color = '#6BB758';
|
||||
} else {
|
||||
style.color = '#F6546A';
|
||||
}
|
||||
}
|
||||
|
||||
if (selected) {
|
||||
classes.push('selected');
|
||||
}
|
||||
|
||||
let indicator = null;
|
||||
if (this.props.connected !== undefined) {
|
||||
const style = {};
|
||||
|
||||
if (this.props.connected) {
|
||||
style.background = '#6BB758';
|
||||
} else {
|
||||
style.background = '#F6546A';
|
||||
}
|
||||
|
||||
indicator = <i className="tab-indicator" style={style} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<p className={classes.join(' ')} onClick={this.handleClick}>
|
||||
<p className={classes.join(' ')} style={style} onClick={this.handleClick}>
|
||||
<span className="tab-content">{content}</span>
|
||||
{indicator}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
@ -1,17 +1,28 @@
|
||||
import { inform } from '../actions/message';
|
||||
|
||||
const notFound = 'commandNotFound';
|
||||
|
||||
function createContext({ dispatch, getState }, { server, channel }) {
|
||||
return { dispatch, getState, server, channel };
|
||||
}
|
||||
|
||||
export default function createCommandMiddleware(type, handlers) {
|
||||
return ({ dispatch, getState }) => next => action => {
|
||||
return store => next => action => {
|
||||
if (action.type === type) {
|
||||
const words = action.command.slice(1).split(' ');
|
||||
const command = words[0];
|
||||
const params = words.slice(1);
|
||||
|
||||
let result;
|
||||
|
||||
if (command in handlers) {
|
||||
handlers[command]({
|
||||
dispatch,
|
||||
getState,
|
||||
server: action.server,
|
||||
channel: action.channel
|
||||
}, ...params);
|
||||
result = handlers[command](createContext(store, action), ...params);
|
||||
} else if (notFound in handlers) {
|
||||
result = handlers[notFound](createContext(store, action), command);
|
||||
}
|
||||
|
||||
if (typeof result === 'string' || Array.isArray(result)) {
|
||||
store.dispatch(inform(result, action.server, action.channel));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,5 +52,4 @@ export function find(arr, pred) {
|
||||
return arr[i];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ export function routeMiddleware() {
|
||||
default:
|
||||
return next(action);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user