From 3a041ec3ec527bde6c7261c2e415ee3df0b8ec22 Mon Sep 17 00:00:00 2001 From: David Petersen Date: Fri, 29 Aug 2014 14:52:21 -0700 Subject: [PATCH] Add history message box - addresses #335 --- src/components/app/messageInput.jsx | 83 ++++++++++++++++++++++++----- src/js/handle_irc.js | 1 - src/styl/messageInput.styl | 25 +++++++-- 3 files changed, 90 insertions(+), 19 deletions(-) diff --git a/src/components/app/messageInput.jsx b/src/components/app/messageInput.jsx index 6cf652b..9ffa591 100644 --- a/src/components/app/messageInput.jsx +++ b/src/components/app/messageInput.jsx @@ -1,11 +1,40 @@ /** @jsx React.DOM */ app.components.message_input = function() { + var messageBox = React.createBackboneClass({ + componentDidUpdate: function() { + if(this.props.historyMode) { + var position = $('ul li:nth-child(' + this.props.historyOffset + ')', this.getDOMNode()).position(); + position = position ? position.top : 0; + $(this.getDOMNode()).animate({ + scrollTop: position + }, 200); + } + }, + + render: function() { + var _this = this; + return ( +
+ +
+ ) + } + }); + var nickBox = React.createBackboneClass({ componentDidUpdate: function() { - var position = $('ul li:nth-child(' + this.props.selectedIndex + ')', this.getDOMNode()).position(); - position = position ? position.top : 0; if(this.props.tabMode) { + var position = $('ul li:nth-child(' + this.props.selectedIndex + ')', this.getDOMNode()).position(); + position = position ? position.top : 0; $(this.getDOMNode()).animate({ scrollTop: position }, 200); @@ -42,7 +71,8 @@ app.components.message_input = function() { getInitialState: function() { return { nicks: [], - selectedIndex: 0 + selectedIndex: 0, + history: [] }; }, @@ -61,10 +91,43 @@ app.components.message_input = function() { }, keyDown: function(ev) { + var server = app.irc.getActiveServer(); + var channel = app.irc.getActiveChannel(); + var historyVal; + + if (ev.keyCode === 38) { + // handle up key + historyVal = channel.getNextHistory(); + } + + if (ev.keyCode === 40) { + // handle down key + historyVal = channel.getPrevHistory(); + } + + if (ev.keyCode === 38 || ev.keyCode === 40) { + this.setState({ + history: channel.attributes.history, + historyMode: true, + historyOffset: channel.attributes.history_offset + }); + + if (historyVal !== undefined) { + ev.target.value = historyVal; + } else { + ev.target.value = ""; + } + } else { + this.setState({historyMode: false}) + } + + // Handle esc key + if (ev.keyCode === 27) { + this.setState({historyMode: false, tabMode: false}) + } + // handle tabKey and autocompletion if (ev.keyCode === 9) { - var server = app.irc.getActiveServer(); - var channel = app.irc.getActiveChannel(); var sentence = ev.target.value.split(" "); ev.target.focus(); @@ -142,20 +205,12 @@ app.components.message_input = function() { ev.target.value = ""; } - if (ev.keyCode === 38) { - // handle up key - ev.target.value = channel.getNextHistory(); - } - - if (ev.keyCode === 40) { - // handle down key - ev.target.value = channel.getPrevHistory(); - } }, render: function() { return (
+
diff --git a/src/js/handle_irc.js b/src/js/handle_irc.js index efbca67..84630d5 100644 --- a/src/js/handle_irc.js +++ b/src/js/handle_irc.js @@ -24,7 +24,6 @@ util.handle_irc = function(message, irc, app_ref) { if (!app.initialized && message.client_server) { app.initialized = true; - console.log(app); app.irc.set({ active_server: message.client_server, active_channel: "status" diff --git a/src/styl/messageInput.styl b/src/styl/messageInput.styl index e583e8a..fb5e59f 100644 --- a/src/styl/messageInput.styl +++ b/src/styl/messageInput.styl @@ -1,28 +1,45 @@ .messageInput position: relative +.messageBox + background: white; + right: 0 + .nickBox + background: #F8F8F8 + border-radius: 0 5px 0 0 + border-right: 1px solid #DDD + +.nickBox, .messageBox position: absolute bottom: 63px left: 0 - background: #F8F8F8 - border-radius: 0 5px 0 0 border-top: 1px solid #DDD - border-right: 1px solid #DDD max-height: 250px overflow: scroll -.nickBox ul +.nickBox ul, .messageBox ul list-style: none margin: 0 padding: 0 overflow: hidden +.messageBox li.selected + background: #BBBBBB + color: white + .nickBox li.selected background: #8D8D8D color: white +.messageBox li + padding: 8px + border-bottom: 1px solid #EEE + + &:last-child + border-bottom: none + .nickBox li padding-right: 250px