Commit 8a3f8667 authored by Hector Carmona's avatar Hector Carmona Committed by Commit Bot

Navi: Remove bookmarks when moving back/forward through history.

Bug: 889222
Change-Id: I718533eef1b76bdee504b678038e598f79146e5f
Reviewed-on: https://chromium-review.googlesource.com/c/1311806
Commit-Queue: Hector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604793}
parent dc362253
...@@ -10,7 +10,7 @@ cr.exportPath('nuxEmail'); ...@@ -10,7 +10,7 @@ cr.exportPath('nuxEmail');
* name: string, * name: string,
* icon: string, * icon: string,
* url: string, * url: string,
* bookmarkId: (string|undefined), * bookmarkId: (string|undefined|null),
* }} * }}
*/ */
nuxEmail.EmailProviderModel; nuxEmail.EmailProviderModel;
...@@ -73,14 +73,36 @@ Polymer({ ...@@ -73,14 +73,36 @@ Polymer({
return; return;
if (this.selectedEmailProvider_) { if (this.selectedEmailProvider_) {
this.emailProxy_.recordProviderSelected( // TODO(hcarmona): metrics.
this.selectedEmailProvider_.id, this.emailList_.length); this.revertBookmark_();
this.bookmarkProxy_.toggleBookmarkBar(this.bookmarkBarWasShown);
} }
this.emailProxy_.recordFinalize(); this.emailProxy_.recordFinalize();
}); });
}, },
/** Initializes the section when navigated to. */
initializeSection: function() {
this.finalized_ = false;
if (this.selectedEmailProvider_) {
this.addBookmark_(this.selectedEmailProvider_);
this.bookmarkProxy_.toggleBookmarkBar(true);
}
},
/** Finalizes the section when navigated away from. */
finalizeSection: function() {
if (this.finalized_)
return;
if (this.selectedEmailProvider_) {
// TODO(hcarmona): metrics?
this.revertBookmark_();
this.bookmarkProxy_.toggleBookmarkBar(this.bookmarkBarWasShown);
}
},
/** /**
* Handle toggling the email selected. * Handle toggling the email selected.
* @param {!{model: {item: !nuxEmail.EmailProviderModel}}} e * @param {!{model: {item: !nuxEmail.EmailProviderModel}}} e
...@@ -122,6 +144,27 @@ Polymer({ ...@@ -122,6 +144,27 @@ Polymer({
item.name === this.selectedEmailProvider_.name; item.name === this.selectedEmailProvider_.name;
}, },
/**
* @param {nuxEmail.EmailProviderModel} emailProvider
* @private
*/
addBookmark_: function(emailProvider) {
if (emailProvider.bookmarkId)
return;
this.emailProxy_.cacheBookmarkIcon(emailProvider.id);
this.bookmarkProxy_.toggleBookmarkBar(true);
this.bookmarkProxy_.addBookmark(
{
title: emailProvider.name,
url: emailProvider.url,
parentId: '1',
},
results => {
this.selectedEmailProvider_.bookmarkId = results.id;
});
},
/** /**
* @param {nuxEmail.EmailProviderModel=} opt_emailProvider * @param {nuxEmail.EmailProviderModel=} opt_emailProvider
* @private * @private
...@@ -129,8 +172,10 @@ Polymer({ ...@@ -129,8 +172,10 @@ Polymer({
revertBookmark_: function(opt_emailProvider) { revertBookmark_: function(opt_emailProvider) {
let emailProvider = opt_emailProvider || this.selectedEmailProvider_; let emailProvider = opt_emailProvider || this.selectedEmailProvider_;
if (emailProvider && emailProvider.bookmarkId) if (emailProvider && emailProvider.bookmarkId) {
this.bookmarkProxy_.removeBookmark(emailProvider.bookmarkId); this.bookmarkProxy_.removeBookmark(emailProvider.bookmarkId);
emailProvider.bookmarkId = null;
}
}, },
/** /**
...@@ -148,21 +193,10 @@ Polymer({ ...@@ -148,21 +193,10 @@ Polymer({
this.revertBookmark_(prevEmail); this.revertBookmark_(prevEmail);
} }
if (newEmail) { if (newEmail)
this.emailProxy_.cacheBookmarkIcon(newEmail.id); this.addBookmark_(newEmail);
this.bookmarkProxy_.toggleBookmarkBar(true); else
this.bookmarkProxy_.addBookmark(
{
title: newEmail.name,
url: newEmail.url,
parentId: '1',
},
results => {
this.selectedEmailProvider_.bookmarkId = results.id;
});
} else {
this.bookmarkProxy_.toggleBookmarkBar(this.bookmarkBarWasShown); this.bookmarkProxy_.toggleBookmarkBar(this.bookmarkBarWasShown);
}
// Announcements are mutually exclusive, so keeping separate. // Announcements are mutually exclusive, so keeping separate.
if (prevEmail && newEmail) { if (prevEmail && newEmail) {
......
...@@ -12,6 +12,18 @@ Polymer({ ...@@ -12,6 +12,18 @@ Polymer({
indicatorModel: Object, indicatorModel: Object,
}, },
/**
* This element can receive an |onRouteChange| notification after it's
* detached. This will make it no-op.
* @private
*/
isDetached_: false,
/** @override */
detached: function() {
this.isDetached_ = true;
},
/** /**
* Elements can override onRouteChange to handle route changes. * Elements can override onRouteChange to handle route changes.
* Overrides function in behavior. * Overrides function in behavior.
...@@ -22,8 +34,14 @@ Polymer({ ...@@ -22,8 +34,14 @@ Polymer({
if (`step-${step}` == this.id) { if (`step-${step}` == this.id) {
nux.BookmarkProxyImpl.getInstance().isBookmarkBarShown().then( nux.BookmarkProxyImpl.getInstance().isBookmarkBarShown().then(
bookmarkBarShown => { bookmarkBarShown => {
if (this.isDetached_)
return;
this.$.emailChooser.bookmarkBarWasShown = bookmarkBarShown; this.$.emailChooser.bookmarkBarWasShown = bookmarkBarShown;
this.$.emailChooser.addBookmark();
}); });
} else {
this.$.emailChooser.removeBookmark();
} }
}, },
}); });
...@@ -66,12 +66,14 @@ Polymer({ ...@@ -66,12 +66,14 @@ Polymer({
/** Called when bookmarks should be created for all selected apps. */ /** Called when bookmarks should be created for all selected apps. */
populateAllBookmarks() { populateAllBookmarks() {
if (!this.appList_) { if (this.appList_) {
this.appList_.forEach(app => this.updateBookmark(app));
} else {
this.appsProxy_.getGoogleAppsList().then(list => { this.appsProxy_.getGoogleAppsList().then(list => {
this.appList_ = list; this.appList_ = list;
this.appList_.forEach(app => { this.appList_.forEach((app, index) => {
// Default select all items. // Default select first few items.
app.selected = true; app.selected = index < 3;
this.updateBookmark(app); this.updateBookmark(app);
}); });
this.updateHasAppsSelected(); this.updateHasAppsSelected();
...@@ -82,17 +84,21 @@ Polymer({ ...@@ -82,17 +84,21 @@ Polymer({
/** Called when bookmarks should be removed for all selected apps. */ /** Called when bookmarks should be removed for all selected apps. */
removeAllBookmarks() { removeAllBookmarks() {
if (!this.appList_)
return; // No apps to remove.
let removedBookmarks = false; let removedBookmarks = false;
this.appList_.forEach(app => { this.appList_.forEach(app => {
if (app.selected) { if (app.selected && app.bookmarkId) {
app.selected = false; // Don't call |updateBookmark| b/c we want to save the selection.
this.updateBookmark(app); this.bookmarkProxy_.removeBookmark(app.bookmarkId);
app.bookmarkId = null;
removedBookmarks = true; removedBookmarks = true;
} }
}); });
// Only update and announce if we removed bookmarks. // Only update and announce if we removed bookmarks.
if (removedBookmarks) { if (removedBookmarks) {
this.updateHasAppsSelected(); this.bookmarkProxy_.toggleBookmarkBar(this.bookmarkBarWasShown);
this.fire('iron-announce', {text: this.i18n('bookmarksRemoved')}); this.fire('iron-announce', {text: this.i18n('bookmarksRemoved')});
} }
}, },
......
...@@ -15,6 +15,19 @@ Polymer({ ...@@ -15,6 +15,19 @@ Polymer({
indicatorModel: Object, indicatorModel: Object,
}, },
/** @private */
finalized_: false,
/** @override */
ready: function() {
window.addEventListener('beforeunload', () => {
if (this.finalized_)
return;
// TODO(hcarmona): Add metrics.
this.$.appChooser.removeAllBookmarks();
});
},
/** /**
* Elements can override onRouteChange to handle route changes. * Elements can override onRouteChange to handle route changes.
* Overrides function in behavior. * Overrides function in behavior.
...@@ -23,11 +36,17 @@ Polymer({ ...@@ -23,11 +36,17 @@ Polymer({
*/ */
onRouteChange: function(route, step) { onRouteChange: function(route, step) {
if (`step-${step}` == this.id) { if (`step-${step}` == this.id) {
this.finalized_ = false;
nux.BookmarkProxyImpl.getInstance().isBookmarkBarShown().then( nux.BookmarkProxyImpl.getInstance().isBookmarkBarShown().then(
bookmarkBarShown => { bookmarkBarShown => {
this.$.appChooser.bookmarkBarWasShown = bookmarkBarShown; this.$.appChooser.bookmarkBarWasShown = bookmarkBarShown;
}); });
this.$.appChooser.populateAllBookmarks(); this.$.appChooser.populateAllBookmarks();
} else {
if (this.finalized_)
return;
// TODO(hcarmona): Add metrics?
this.$.appChooser.removeAllBookmarks();
} }
}, },
...@@ -41,6 +60,7 @@ Polymer({ ...@@ -41,6 +60,7 @@ Polymer({
/** @private */ /** @private */
onGetStartedClicked_: function() { onGetStartedClicked_: function() {
// TODO(hcarmona): Add metrics. // TODO(hcarmona): Add metrics.
this.finalized_ = true;
welcome.navigateToNextStep(); welcome.navigateToNextStep();
}, },
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment