jenkins-bot has submitted this change and it was merged. Change subject: Add support for future toasts ......................................................................
Add support for future toasts * Add toast.showOnPageReload() that lets showing toast messages after a page reload. * Use the newly created function to show the success message after a page has been edited successfully. Bug: T97067 Change-Id: I2f862cf1e1e488de3a11c7b28d4a7108a0017639 --- M resources/mobile.editor.common/EditorOverlayBase.js M resources/mobile.editor/init.js M resources/mobile.toast/toast.js 3 files changed, 45 insertions(+), 11 deletions(-) Approvals: Phuedx: Looks good to me, approved jenkins-bot: Verified diff --git a/resources/mobile.editor.common/EditorOverlayBase.js b/resources/mobile.editor.common/EditorOverlayBase.js index 9fce916..4f651ae 100644 --- a/resources/mobile.editor.common/EditorOverlayBase.js +++ b/resources/mobile.editor.common/EditorOverlayBase.js @@ -5,7 +5,6 @@ Icon = M.require( 'Icon' ), toast = M.require( 'toast' ), user = M.require( 'user' ), - settings = M.require( 'settings' ), pageApi = M.require( 'pageApi' ), skin = M.require( 'skin' ), EditorOverlayBase; @@ -133,8 +132,7 @@ msg = 'mobile-frontend-editor-success'; } msg = mw.msg( msg ); - - settings.save( 'mobile-pending-toast', msg ); + toast.showOnPageReload( msg, 'success' ); // Ensure we don't lose this event when logging this.log( 'success' ).always( function () { diff --git a/resources/mobile.editor/init.js b/resources/mobile.editor/init.js index 2a0eed8..fcbe86d 100644 --- a/resources/mobile.editor/init.js +++ b/resources/mobile.editor/init.js @@ -29,16 +29,8 @@ // FIXME: Should we consider default site options and user prefs? isVisualEditorEnabled = browser.isWideScreen() && veConfig, CtaDrawer = M.require( 'CtaDrawer' ), - toast = M.require( 'toast' ), - pendingToast = settings.get( 'mobile-pending-toast' ), drawer, $caEdit = $( '#ca-edit' ); - - if ( pendingToast ) { - // delete the pending toast - settings.save( 'mobile-pending-toast', '' ); - toast.show( pendingToast ); - } /** * Prepend an edit page button to the container diff --git a/resources/mobile.toast/toast.js b/resources/mobile.toast/toast.js index 6ba1674..5f5fb89 100644 --- a/resources/mobile.toast/toast.js +++ b/resources/mobile.toast/toast.js @@ -1,5 +1,7 @@ ( function ( M ) { var Toast, + settingsKey = 'mobileFrontend/toast', + settings = M.require( 'settings' ), Drawer = M.require( 'Drawer' ); /** @@ -10,6 +12,13 @@ Toast = Drawer.extend( { className: 'toast position-fixed', minHideDelay: 1000, + /** + * @inheritdoc + */ + postRender: function () { + Drawer.prototype.postRender.call( this ); + this._showPending(); + }, /** * Show the toast message with a given class and content * @method @@ -23,6 +32,41 @@ .addClass( this.className ) .addClass( className ); Drawer.prototype.show.apply( this, arguments ); + }, + /** + * Save the toast data in settings so that we can show it on page reload. + * Also check whether there is a pending message that's not shown yet. + * If yes, output a warning message and discard this message. + * This is to ensure that the page needs to be reloaded before adding + * a new message for showing later. + * @method + * @param {String} content Content to be placed in element + * @param {String} className class to add to element + */ + showOnPageReload: function ( content, className ) { + if ( settings.get( settingsKey ) ) { + mw.log.warn( + 'A pending toast message already exits. ' + + 'The page should have been reloaded by now.' + ); + return; + } + settings.save( settingsKey, JSON.stringify( { + content: content, + className: className + } ) ); + }, + /** + * Show the previously saved toast data and delete it from settings + * @private + */ + _showPending: function () { + var data = settings.get( settingsKey ); + if ( data ) { + data = JSON.parse( data ); + this.show( data.content, data.className ); + settings.remove( settingsKey ); + } } } ); -- To view, visit https://gerrit.wikimedia.org/r/209777 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2f862cf1e1e488de3a11c7b28d4a7108a0017639 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org> Gerrit-Reviewer: Bmansurov <bmansu...@wikimedia.org> Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.wel...@t-online.de> Gerrit-Reviewer: Jhernandez <jhernan...@wikimedia.org> Gerrit-Reviewer: Phuedx <g...@samsmith.io> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits