diff --git a/client/src/js/actions/inputHistory.js b/client/src/js/actions/inputHistory.js new file mode 100644 index 00000000..bb5ef46e --- /dev/null +++ b/client/src/js/actions/inputHistory.js @@ -0,0 +1,10 @@ +var Reflux = require('reflux'); + +var inputHistoryActions = Reflux.createActions([ + 'add', + 'reset', + 'increment', + 'decrement' +]); + +module.exports = inputHistoryActions; \ No newline at end of file diff --git a/client/src/js/command.js b/client/src/js/command.js index 596a1767..5fddcb3f 100644 --- a/client/src/js/command.js +++ b/client/src/js/command.js @@ -1,5 +1,4 @@ var channelStore = require('./stores/channel'); -var selectedTabStore = require('./stores/selectedTab'); var channelActions = require('./actions/channel'); var messageActions = require('./actions/message'); var serverActions = require('./actions/server'); diff --git a/client/src/js/components/MessageInput.jsx b/client/src/js/components/MessageInput.jsx index 4cbca436..67bc3f5a 100644 --- a/client/src/js/components/MessageInput.jsx +++ b/client/src/js/components/MessageInput.jsx @@ -1,19 +1,24 @@ var React = require('react'); var Reflux = require('reflux'); +var inputHistoryStore = require('../stores/inputHistory'); var selectedTabStore = require('../stores/selectedTab'); var messageActions = require('../actions/message'); +var inputHistoryActions = require('../actions/inputHistory'); var tabActions = require('../actions/tab'); var MessageInput = React.createClass({ mixins: [ Reflux.connect(selectedTabStore, 'selectedTab'), + Reflux.connect(inputHistoryStore, 'history'), Reflux.listenTo(tabActions.select, 'tabSelected') ], getInitialState: function() { return { - selectedTab: selectedTabStore.getState() + selectedTab: selectedTabStore.getState(), + history: inputHistoryStore.getState(), + value: '' }; }, @@ -34,14 +39,34 @@ var MessageInput = React.createClass({ } else { messageActions.send(e.target.value, tab.channel, tab.server); } - e.target.value = ''; + + inputHistoryActions.add(e.target.value); + inputHistoryActions.reset(); + this.setState({ value: '' }); + } else if (e.which === 38) { + e.preventDefault(); + inputHistoryActions.increment(); + } else if (e.which === 40) { + inputHistoryActions.decrement(); + } else if (e.key === 'Unidentified') { + inputHistoryActions.reset(); } }, + handleChange: function(e) { + this.setState({ value: e.target.value }); + }, + render: function() { return (