|
| 1 | +/** |
| 2 | + * This file is provided by Facebook for testing and evaluation purposes |
| 3 | + * only. Facebook reserves all rights not expressly granted. |
| 4 | + * |
| 5 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 6 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 7 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 8 | + * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 9 | + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 10 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 11 | + */ |
| 12 | + |
| 13 | +var React = require('react') |
| 14 | +var Chat = require('../modules/chat') |
| 15 | +var cx = require('react/lib/cx') |
| 16 | +// var NuclearMixin = require('nuclear-js-react-addons/nuclearMixin') |
| 17 | +var nuclearComponent = require('nuclear-js-react-addons/nuclearComponent') |
| 18 | + |
| 19 | +var ReactPropTypes = React.PropTypes |
| 20 | + |
| 21 | +var ThreadListItem = React.createClass({ |
| 22 | + // mixins: [NuclearMixin], // mixin use |
| 23 | + |
| 24 | + propTypes: { |
| 25 | + thread: ReactPropTypes.object, |
| 26 | + currentThreadID: ReactPropTypes.string, |
| 27 | + }, |
| 28 | + |
| 29 | + render: function() { |
| 30 | + var thread = this.props.thread |
| 31 | + var lastMessage = thread.get('messages').last() |
| 32 | + var dateString = (new Date(lastMessage.get('timestamp'))).toLocaleTimeString() |
| 33 | + return ( |
| 34 | + <li |
| 35 | + className={cx({ |
| 36 | + 'thread-list-item': true, |
| 37 | + 'active': thread.get('threadID') === this.props.currentThreadID, |
| 38 | + })} |
| 39 | + onClick={this._onClick}> |
| 40 | + <h5 className="thread-name">{thread.get('threadName')}</h5> |
| 41 | + <div className="thread-time"> |
| 42 | + {dateString} |
| 43 | + </div> |
| 44 | + <div className="thread-last-message"> |
| 45 | + {lastMessage.get('text')} |
| 46 | + </div> |
| 47 | + </li> |
| 48 | + ) |
| 49 | + }, |
| 50 | + |
| 51 | + _onClick: function() { |
| 52 | + var threadID = this.props.thread.get('threadID') |
| 53 | + if (this.props.currentThreadID !== threadID) { |
| 54 | + /** |
| 55 | + * If you use the mixin, dataBindings is state and reactor is in context, |
| 56 | + * if you use the HoC nuclearComponent, both are props |
| 57 | + */ |
| 58 | + // Chat.actions.clickThread(this.context.reactor, threadID) // with mixin |
| 59 | + Chat.actions.clickThread(this.props.reactor, threadID) // with HoC |
| 60 | + } |
| 61 | + }, |
| 62 | +}) |
| 63 | + |
| 64 | +// HoC use with |
| 65 | +module.exports = nuclearComponent(ThreadListItem/*, optionalDataBindingsObject */) |
0 commit comments