From 71bf8604abc7dffcc80aa9dbf8a97f5cb102d13f Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Thu, 8 Mar 2018 11:22:55 -0800 Subject: [PATCH] Move error handling inside Minerva ReferenceDrawer Instead of doing this inside the ReferenceDrawer component itself, we'll do this here. To be backwards compatible we check the value is truthy. When I5a7b23f60722eb5017a85c68f38844dd460f8b63 is merged this can be removed. For NotificationBadge we pass the onError option which is now available and allows us to clean up the NotificationBadge Change-Id: I47db11fa945a05f3b2a9a43c3cf053ca489a38fa --- .../NotificationBadge.js | 4 ++++ resources/skins.minerva.scripts/references.js | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/resources/skins.minerva.notifications.badge/NotificationBadge.js b/resources/skins.minerva.notifications.badge/NotificationBadge.js index 75f1d6c..1c87a66 100644 --- a/resources/skins.minerva.notifications.badge/NotificationBadge.js +++ b/resources/skins.minerva.notifications.badge/NotificationBadge.js @@ -27,6 +27,10 @@ options.title = $el.find( 'a' ).attr( 'title' ); options.url = $el.find( 'a' ).attr( 'href' ); count = Number( $el.find( 'span' ).data( 'notification-count' ) ); + options.onError = function () { + // FIXME: Blocked on T189173. Ideally we'd use the router here. + window.location.href = this.getNotificationURL(); + }.bind( this ); } View.call( this, options ); this.url = options.url; diff --git a/resources/skins.minerva.scripts/references.js b/resources/skins.minerva.scripts/references.js index e1f6614..70c41d9 100644 --- a/resources/skins.minerva.scripts/references.js +++ b/resources/skins.minerva.scripts/references.js @@ -2,6 +2,9 @@ var drawer, skin = M.require( 'skins.minerva.scripts/skin' ), page = M.getCurrentPage(), + router = require( 'mediawiki.router' ), + util = M.require( 'mobile.startup/util' ), + ReferencesGateway = M.require( 'mobile.references.gateway/ReferencesGateway' ), ReferencesMobileViewGateway = M.require( 'mobile.references.gateway/ReferencesMobileViewGateway' ), @@ -40,7 +43,7 @@ * @param {Page} page */ function showReference( ev, drawer, page ) { - var urlComponents, + var urlComponents, result, $dest = $( ev.currentTarget ), href = $dest.attr( 'href' ); @@ -52,7 +55,16 @@ if ( urlComponents.length > 1 ) { href = '#' + urlComponents[1]; } - drawer.showReference( href, page, $dest.text() ); + result = drawer.showReference( href, page, $dest.text() ); + // Previously showReference method returns nothing so we check its truthy + // Can be removed when I5a7b23f60722eb5017a85c68f38844dd460f8b63 is merged. + if ( result ) { + result.then( util.noop, function ( err ) { + if ( err === ReferencesGateway.ERROR_NOT_EXIST ) { + router.navigate( href ); + } + } ); + } // don't hide drawer (stop propagation of click) if it is already shown // (e.g. click another reference)