Bug 1062126: Loop panel UI shouldn't be fully reset when reopened, r=mikedeboer.

This commit is contained in:
Nicolas Perriault
2014-09-11 20:54:48 +01:00
parent 174310732d
commit d1c45aea6b
16 changed files with 296 additions and 205 deletions

View File

@@ -11,10 +11,10 @@ var loop = loop || {};
loop.panel = (function(_, mozL10n) {
"use strict";
var sharedViews = loop.shared.views,
sharedModels = loop.shared.models,
// aliasing translation function as __ for concision
__ = mozL10n.get;
var sharedViews = loop.shared.views;
var sharedModels = loop.shared.models;
var sharedMixins = loop.shared.mixins;
var __ = mozL10n.get; // aliasing translation function as __ for concision
/**
* Panel router.
@@ -73,41 +73,11 @@ loop.panel = (function(_, mozL10n) {
}
});
/**
* Dropdown menu mixin.
* @type {Object}
*/
var DropdownMenuMixin = {
getInitialState: function() {
return {showMenu: false};
},
_onBodyClick: function() {
this.setState({showMenu: false});
},
componentDidMount: function() {
document.body.addEventListener("click", this._onBodyClick);
},
componentWillUnmount: function() {
document.body.removeEventListener("click", this._onBodyClick);
},
showDropdownMenu: function() {
this.setState({showMenu: true});
},
hideDropdownMenu: function() {
this.setState({showMenu: false});
}
};
/**
* Availability drop down menu subview.
*/
var AvailabilityDropdown = React.createClass({displayName: 'AvailabilityDropdown',
mixins: [DropdownMenuMixin],
mixins: [sharedMixins.DropdownMenuMixin],
getInitialState: function() {
return {
@@ -239,7 +209,7 @@ loop.panel = (function(_, mozL10n) {
* Panel settings (gear) menu.
*/
var SettingsDropdown = React.createClass({displayName: 'SettingsDropdown',
mixins: [DropdownMenuMixin],
mixins: [sharedMixins.DropdownMenuMixin],
handleClickSettingsEntry: function() {
// XXX to be implemented
@@ -308,7 +278,12 @@ loop.panel = (function(_, mozL10n) {
}
});
/**
* Call url result view.
*/
var CallUrlResult = React.createClass({displayName: 'CallUrlResult',
mixins: [sharedMixins.DocumentVisibilityMixin],
propTypes: {
callUrl: React.PropTypes.string,
callUrlExpiry: React.PropTypes.number,
@@ -325,6 +300,14 @@ loop.panel = (function(_, mozL10n) {
};
},
/**
* Provided by DocumentVisibilityMixin. Schedules retrieval of a new call
* URL everytime the panel is reopened.
*/
onDocumentVisible: function() {
this._fetchCallUrl();
},
/**
* Returns a random 5 character string used to identify
* the conversation.
@@ -341,6 +324,13 @@ loop.panel = (function(_, mozL10n) {
return;
}
this._fetchCallUrl();
},
/**
* Fetches a call URL.
*/
_fetchCallUrl: function() {
this.setState({pending: true});
this.props.client.requestCallUrl(this.conversationIdentifier(),
this._onCallUrlReceived);
@@ -506,7 +496,8 @@ loop.panel = (function(_, mozL10n) {
__("display_name_guest");
return (
React.DOM.div(null,
NotificationListView({notifications: this.props.notifications}),
NotificationListView({notifications: this.props.notifications,
clearOnDocumentHidden: true}),
TabView({onSelect: this.selectTab},
Tab({name: "call"},
CallUrlResult({client: this.props.client,
@@ -547,42 +538,12 @@ loop.panel = (function(_, mozL10n) {
if (!options.document) {
throw new Error("missing required document");
}
this.document = options.document;
this._registerVisibilityChangeEvent();
this.on("panel:open", this.reset, this);
},
/**
* Register the DOM visibility API event for the whole document, and trigger
* appropriate events accordingly:
*
* - `panel:opened` when the panel is open
* - `panel:closed` when the panel is closed
*
* @link http://www.w3.org/TR/page-visibility/
*/
_registerVisibilityChangeEvent: function() {
// XXX pass in the visibility status to detect when to generate a new
// panel view
this.document.addEventListener("visibilitychange", function(event) {
this.trigger(event.currentTarget.hidden ? "panel:closed"
: "panel:open");
}.bind(this));
},
/**
* Default entry point.
*/
home: function() {
this.reset();
},
/**
* Resets this router to its initial state.
*/
reset: function() {
this._notifications.reset();
var client = new loop.Client({
baseServerUrl: navigator.mozLoop.serverUrl