diff options
author | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
commit | cf7a05f80f68b5b1c8bcc0089679dd497cec2506 (patch) | |
tree | 70007378570a6962d7c175ca96af732b71aeb6da /web/react/components/command_list.jsx | |
download | chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.gz chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.bz2 chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.zip |
first commit
Diffstat (limited to 'web/react/components/command_list.jsx')
-rw-r--r-- | web/react/components/command_list.jsx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/web/react/components/command_list.jsx b/web/react/components/command_list.jsx new file mode 100644 index 000000000..023f5f760 --- /dev/null +++ b/web/react/components/command_list.jsx @@ -0,0 +1,67 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var client = require('../utils/client.jsx'); + +module.exports = React.createClass({ + getInitialState: function() { + return { suggestions: [ ], cmd: "" }; + }, + handleClick: function(i) { + this.props.addCommand(this.state.suggestions[i].suggestion) + this.setState({ suggestions: [ ], cmd: "" }); + }, + addFirstCommand: function() { + if (this.state.suggestions.length == 0) return; + this.handleClick(0); + }, + isEmpty: function() { + return this.state.suggestions.length == 0; + }, + getSuggestedCommands: function(cmd) { + + if (cmd == "") { + this.setState({ suggestions: [ ], cmd: "" }); + return; + } + + if (cmd.indexOf("/") != 0) { + this.setState({ suggestions: [ ], cmd: "" }); + return; + } + + client.executeCommand( + this.props.channelId, + cmd, + true, + function(data) { + if (data.suggestions.length === 1 && data.suggestions[0].suggestion === cmd) data.suggestions = []; + this.setState({ suggestions: data.suggestions, cmd: cmd }); + }.bind(this), + function(err){ + }.bind(this) + ); + }, + render: function() { + if (this.state.suggestions.length == 0) return (<div/>); + + var suggestions = [] + + for (var i = 0; i < this.state.suggestions.length; i++) { + if (this.state.suggestions[i].suggestion != this.state.cmd) { + suggestions.push( + <div key={i} className="command-name" onClick={this.handleClick.bind(this, i)}> + <div className="pull-left"><strong>{ this.state.suggestions[i].suggestion }</strong></div> + <div className="command-desc pull-right">{ this.state.suggestions[i].description }</div> + </div> + ); + } + } + + return ( + <div ref="mentionlist" className="command-box" style={{height:(this.state.suggestions*37)+2}}> + { suggestions } + </div> + ); + } +}); |