Add support for UnknownCommandResult

This commit is contained in:
Borys_Levytskyi
2016-11-22 00:16:01 +02:00
parent e65bc29e78
commit 3f34d875e8
7 changed files with 33 additions and 3 deletions

View File

@@ -55,8 +55,7 @@ var cmd = {
};
function displayCommandError(input, message) {
var error = new app.models.ErrorResult(message);
cmdController.display(new app.models.DisplayResult(input, error));
console.error('[displayCommandError] not implemented');
}
function invokeHandler (input, handler) {

View File

@@ -1,5 +1,6 @@
import appState from './appState';
import HelpResult from './models/HelpResult';
import UnknownCommandResult from './models/UnknownCommandResult';
var cmdConfig = {};
@@ -41,5 +42,10 @@ export default {
},
'-notrack': function () {}
});
cmd.command({
canHandle: () => true,
handle: (c) => appState.addCommandResult(new UnknownCommandResult(c.input))
})
}
}

View File

@@ -12,7 +12,7 @@ export default class AppRoot extends React.Component {
this.setState(this.props.appState);
}
render() {
var results = this.state.commandResults.map((r, i) => <DisplayResultView key={i} content={r} input="sad" inputHash="asd" />);
var results = this.state.commandResults.map((r, i) => <DisplayResultView key={i} content={r} input={r.input} inputHash={r.inputHash} />);
return <div>
<div className="header">
<h1>Bitwise<span style={{color: "#c5c5c5"}}>Cmd</span></h1>

View File

@@ -1,9 +1,16 @@
import React from 'react';
import HelpResultView from './HelpResultView';
import HelpResult from '../../models/HelpResult';
import UnknownCommandResult from '../../models/UnknownCommandResult';
export default class DisplayResult extends React.Component {
render() {
if(this.props.content instanceof UnknownCommandResult) {
return this.renderUnknown();
}
return <div className="result">
<div className="input mono"><span className="cur">&gt;</span>{this.props.content.input}<a class="hashLink" title="Link for this expression" href={window.location.pathname + '#' + this.props.inputHash}>#</a></div>
<div className="content">
@@ -12,6 +19,10 @@ export default class DisplayResult extends React.Component {
</div>;
}
renderUnknown() {
return <div className="error">Sorry, i don't know what <strong>{this.props.input}</strong> is :(</div>
}
findResultComponent(result, key) {
if(result instanceof HelpResult) {
return <HelpResultView key={key} content={result} />

View File

@@ -9,6 +9,7 @@ import AppRoot from './components/AppRoot';
commands.initialize(cmd);
cmd.execute('help');
cmd.execute('bluh');
var root = <AppRoot appState={appState} />;
ReactDOM.render(root, document.getElementById('root'));

View File

@@ -1,5 +1,10 @@
export default class CommandResult {
constructor(input) {
this.input = input;
this.inputHash = this.encodeHash(input);
}
encodeHash (string) {
return encodeURI(string.trim().replace(/\s/g,','));
}
}

View File

@@ -0,0 +1,8 @@
import CommandResult from './CommandResult';
export default class UnknownCommandResult extends CommandResult {
constructor(input) {
super(input);
this.message = `Sorry, i don''t know what ${input} is :(`;
}
}