Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/61571


Change subject: Story 425 Nearby: Cache last known location/nearby places
......................................................................

Story 425 Nearby: Cache last known location/nearby places

Add an additional level of caching to this page so that back button
is a little more responsive. Note nearby.js runs at bottom of page so
there is still a slight delay. Lets not make mobile.stable load at top
of page just for this..

Change-Id: I458e3ca60c56e25bda65eb4675390b13f4acd91d
---
M javascripts/common/mf-settings.js
M javascripts/specials/nearby.js
2 files changed, 16 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/71/61571/1

diff --git a/javascripts/common/mf-settings.js 
b/javascripts/common/mf-settings.js
index a549870..b058cfb 100644
--- a/javascripts/common/mf-settings.js
+++ b/javascripts/common/mf-settings.js
@@ -59,8 +59,9 @@
                                ( useCookieFallback ? writeCookie( name, value, 
1 ) : false );
        }
 
-       function getUserSetting( name ) {
-               return supportsLocalStorage ? localStorage.getItem( name ) : 
readCookie( name );
+       function getUserSetting( name, useCookieFallback ) {
+               return supportsLocalStorage ? localStorage.getItem( name ) :
+                       ( useCookieFallback ? readCookie( name ) : false );
        }
 
        return {
diff --git a/javascripts/specials/nearby.js b/javascripts/specials/nearby.js
index abd4a81..4ed571b 100644
--- a/javascripts/specials/nearby.js
+++ b/javascripts/specials/nearby.js
@@ -1,4 +1,6 @@
 ( function( M, $ ) {
+var CACHE_KEY_RESULTS = 'mfNearbyLastSearchResult',
+       CACHE_KEY_LAST_LOCATION = 'mfNearbyLastKnownLocation';
 
 ( function() {
        var supported = !!navigator.geolocation,
@@ -6,6 +8,9 @@
                View = M.require( 'view' ),
                cachedPages,
                curLocation,
+               lastKnownLocation = M.settings.getUserSetting( 
CACHE_KEY_LAST_LOCATION ),
+               cache = M.settings.saveUserSetting,
+               lastSearchResult = M.settings.getUserSetting( CACHE_KEY_RESULTS 
),
                Nearby = View.extend( {
                        template: M.template.get( 'articleList' )
                } );
@@ -63,6 +68,7 @@
        }
 
        function render( $content, pages ) {
+               cache( CACHE_KEY_RESULTS, $.toJSON( pages ) ); // cache result
                pages = $.map( pages, function( page ) {
                        var coords, lngLat, thumb;
 
@@ -152,6 +158,7 @@
                navigator.geolocation.watchPosition( function( geo ) {
                        var lat = geo.coords.latitude, lng = 
geo.coords.longitude;
                        curLocation = geo.coords;
+                       cache( CACHE_KEY_LAST_LOCATION, $.toJSON( curLocation ) 
);
                        findResults( lat, lng );
                },
                function() {
@@ -163,7 +170,13 @@
        }
 
        if ( supported ) {
+               if ( lastKnownLocation ) {
+                       curLocation = $.parseJSON( lastKnownLocation );
+               }
                init();
+               if ( lastSearchResult ) {
+                       render( $( '#content' ), $.parseJSON( lastSearchResult 
) );
+               }
        }
        M.define( 'nearby', {
                distanceMessage: distanceMessage

-- 
To view, visit https://gerrit.wikimedia.org/r/61571
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I458e3ca60c56e25bda65eb4675390b13f4acd91d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to