Skip to content

Instantly share code, notes, and snippets.

@piatra
Created July 6, 2015 18:11
Show Gist options
  • Save piatra/b084e6e520aa054d511f to your computer and use it in GitHub Desktop.
Save piatra/b084e6e520aa054d511f to your computer and use it in GitHub Desktop.
var AppControllerView = React.createClass({
mixins: [
Backbone.Events,
loop.store.StoreMixin("conversationAppStore"),
sharedMixins.WindowCloseMixin
],
propTypes: {
dispatcher: React.PropTypes.instanceOf(loop.Dispatcher).isRequired,
mozLoop: React.PropTypes.object.isRequired,
roomStore: React.PropTypes.instanceOf(loop.store.RoomStore)
},
getInitialState: function() {
return this.getStoreState();
},
/**
* Update the time feedback view was displayed.
*
* @private
*/
_setFeedbackTimestamp: function() {
var timestamp = (new Date()).getTime() / 1000;
this.props.mozLoop.setLoopPref("feedback.dateLastSeenSec", timestamp);
},
_showFeedbackForm: function() {
this.setState({
closeConversation: false,
showFeedbackForm: true
});
},
_closeConversation: function() {
this.setState({
closeConversation: true,
showFeedbackForm: false
});
},
/**
* We only show the feedback for once every 6 months.
*
* @returns {boolean}
* @private
*/
onCallTerminated: function() {
// 0 is default value for pref. Always show feedback form on first use.
if (this.state.timestamp === 0) {
return this._showFeedbackForm();
}
var delta = new Date() - (new Date(this.state.timestamp));
// Show timestamp if feedback period (6 months) passed.
if (delta >= this.state.feedbackPeriod) {
this._setFeedbackTimestamp();
return this._showFeedbackForm();
}
this._closeConversation();
},
render: function() {
switch(this.state.windowType) {
// CallControllerView is used for both.
case "incoming":
case "outgoing": {
return (<CallControllerView
dispatcher={this.props.dispatcher}
mozLoop={this.props.mozLoop}
onCallTerminated={this.onCallTerminated} />);
}
case "room": {
return (<DesktopRoomConversationView
dispatcher={this.props.dispatcher}
mozLoop={this.props.mozLoop}
onCallTerminated={this.onCallTerminated}
roomStore={this.props.roomStore} />);
}
case "failed": {
return <GenericFailureView cancelCall={this.closeWindow} />;
}
default: {
if (this.state.showFeedbackForm === true) {
this.setTitle(mozL10n.get("conversation_has_ended"));
return <FeedbackView />;
}
if (this.state.closeConversation === true) {
this.closeWindow();
return null;
}
// If we don't have a windowType, we don't know what we are yet,
// so don't display anything.
return null;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment