From dfd2e885f81655b51653450cd9211872334dc1d8 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Fri, 31 Jul 2015 12:21:07 +0100 Subject: [PATCH] Fix timer for updating createdAt --- lib/react/message.jsx | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/react/message.jsx b/lib/react/message.jsx index 503a97d..72e58be 100644 --- a/lib/react/message.jsx +++ b/lib/react/message.jsx @@ -8,7 +8,7 @@ var Chatroom = React.createClass({ }, componentDidMount: function () { var self = this; - var TIMER_INTERVAL = 60000; // Every minute + var TIMER_INTERVAL = 5000; // Every minute socket.on("message:new", function (data) { var history = self.props.history; @@ -30,7 +30,7 @@ var Chatroom = React.createClass({ socket.emit("message:refresh", {}); self.timer = setInterval(function () { - if (self.refs.messages) self.refs.messages.refreshTime(); + self.forceUpdate(); }, TIMER_INTERVAL); }, @@ -48,11 +48,8 @@ var Chatroom = React.createClass({ var messages = this.props.history.map(function (message) { return ( + message={message} + key={message.id} /> ); }); return ( @@ -71,16 +68,19 @@ var Chatroom = React.createClass({ } }); +var updateMessageCallbacks = []; + +var timer = setInterval(function () { + updateMessageCallbacks.forEach(function (callback) { + callback(); + }); +}, 60000); + var ChatMessage = React.createClass({ - getInitialState: function () { - return { - timeAgo: $.timeago(this.props.createdAt) - } - }, - refreshTime: function () { + componentDidMount: function () { var self = this; - self.setState({ - timeAgo: $.timeago(self.props.createdAt) + updateMessageCallbacks.push(function () { + self.forceUpdate(); }); }, render: function () { @@ -88,7 +88,7 @@ var ChatMessage = React.createClass({
  • User Avatar
    - {this.props.username} + {this.props.message.author.username} - {this.state.timeAgo} + {$.timeago(this.props.message.createdAt)}
    -

    {this.props.content}

    +

    {this.props.message.content}

  • );