Skip to content

Commit

Permalink
fix issue with state resets and confirm hiding triggering default car…
Browse files Browse the repository at this point in the history
…d actions
  • Loading branch information
jrburke committed Apr 17, 2014
1 parent 61a46a8 commit 9eccccd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 18 additions & 0 deletions apps/email/js/mail_app.js
Expand Up @@ -280,6 +280,11 @@ evt.on('addAccount', function() {
});

function resetApp() {
// Clear any existing local state and reset UI/model state.
waitForAppMessage = false;
waitingForCreateAccountPrompt = false;
activityCallback = null;

Cards.removeAllCards();
model.init();
}
Expand Down Expand Up @@ -340,7 +345,20 @@ model.on('acctsSlice', function() {
}
});

var lastActivityTime = 0;
appMessages.on('activity', function(type, data, rawActivity) {
// Rate limit rapid fire activity triggers, like an accidental
// double tap. While the card code adjusts for the taps, in
// the case of configured account, user can end up with multiple
// compose cards in the stack, which is probably confusing,
// and the rapid tapping is likely just an accident, or an
// incorrect user belief that double taps are needed for
// activation.
var activityTime = Date.now();
if (activityTime < lastActivityTime + 1000) {
return;
}
lastActivityTime = activityTime;

function initComposer() {
Cards.pushCard('compose', 'default', 'immediate', {
Expand Down
21 changes: 14 additions & 7 deletions apps/email/js/mail_common.js
Expand Up @@ -683,14 +683,18 @@ Cards = {
* @param[nextCardSpec #:optional]{
* If a showMethod is not 'none', the card to show after removal.
* }
* @param[skipDefault #:optional Boolean]{
* Skips the default pushCard if the removal ends up with no more
* cards in the stack.
* }
* ]
*/
removeCardAndSuccessors: function(cardDomNode, showMethod, numCards,
nextCardSpec) {
nextCardSpec, skipDefault) {
if (!this._cardStack.length)
return;

if (cardDomNode && this._cardStack.length === 1) {
if (cardDomNode && this._cardStack.length === 1 && !skipDefault) {
// No card to go to when done, so ask for a default
// card and continue work once it exists.
return Cards.pushDefaultCard(function() {
Expand Down Expand Up @@ -724,13 +728,16 @@ Cards = {
numCards = this._cardStack.length - firstIndex;

if (showMethod !== 'none') {
var nextCardIndex = null;
if (nextCardSpec)
var nextCardIndex = -1;
if (nextCardSpec) {
nextCardIndex = this._findCard(nextCardSpec);
else if (this._cardStack.length)
} else if (this._cardStack.length) {
nextCardIndex = Math.min(firstIndex - 1, this._cardStack.length - 1);
}

this._showCard(nextCardIndex, showMethod, 'back');
if (nextCardIndex > -1) {
this._showCard(nextCardIndex, showMethod, 'back');
}
}

// Update activeCardIndex if nodes were removed that would affect its
Expand Down Expand Up @@ -1216,7 +1223,7 @@ function ConfirmDialog(domNode, mode, args) {

ConfirmDialog.prototype = {
hide: function() {
Cards.removeCardAndSuccessors(this.domNode, 'immediate', 1);
Cards.removeCardAndSuccessors(this.domNode, 'immediate', 1, null, true);
},
die: function() {
}
Expand Down

0 comments on commit 9eccccd

Please sign in to comment.