Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 455d83a

Browse files
authored
Merge pull request #1706 from rmisio/some-tweaks
multiple tweaks
2 parents 8f0cfa9 + 6e917b6 commit 455d83a

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

js/languages/en-US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@
743743
"newConfigTitle": "New Configuration",
744744
"new": "New"
745745
},
746+
"langChangeRestartTitle": "Restart needed for language change",
747+
"langChangeRestartMessage": "In order for your language change to fully take effect, you must restart the app.",
746748
"timezones": {
747749
"-12": "(GMT -12:00) Eniwetok, Kwajalein",
748750
"-11": "(GMT -11:00) Midway Island, Samoa",

js/router.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ module.exports = Backbone.Router.extend({
198198
};
199199
},
200200

201-
newView: function(View, options, ignoreCache) {
201+
newView: function(View, options) {
202202
var now = Date.now(),
203203
cached = this.viewCache[View.getCacheIndex(Backbone.history.getFragment())],
204204
requestedRoute = Backbone.history.getFragment(),
@@ -251,7 +251,7 @@ module.exports = Backbone.Router.extend({
251251
}
252252
}
253253

254-
if (cached && (now - cached.cachedAt < cached.view.cacheExpires && !ignoreCache)) {
254+
if (cached && (now - cached.cachedAt < cached.view.cacheExpires)) {
255255
// we have an un-expired cached view, let's reattach it
256256
this.view = cached.view;
257257

@@ -352,8 +352,6 @@ module.exports = Backbone.Router.extend({
352352
},
353353

354354
home: function(state, searchText){
355-
//if search terms have been given, don't use cached views
356-
var ignoreCache = Boolean(searchText);
357355
this.newView(homeView, {
358356
viewArgs: {
359357
userModel: this.userModel,
@@ -362,7 +360,7 @@ module.exports = Backbone.Router.extend({
362360
state: state,
363361
searchItemsText: searchText
364362
}
365-
}, ignoreCache);
363+
});
366364

367365
// hide the discover onboarding callout
368366
this.$discoverHolder = this.$discoverHolder || $('.js-OnboardingIntroDiscoverHolder');

js/start.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var Polyglot = require('node-polyglot'),
5252
ServerConnectModal = require('./views/serverConnectModal'),
5353
OnboardingModal = require('./views/onboardingModal'),
5454
PageConnectModal = require('./views/pageConnectModal'),
55+
Dialog = require('./views/dialog.js'),
5556
loadProfileNeeded = true,
5657
startUpConnectMaxRetries = 2,
5758
startUpConnectRetryDelay = 2 * 1000,
@@ -107,6 +108,11 @@ updatePolyglot = function(lang){
107108
};
108109

109110
user.on('change:language', function(md, lang) {
111+
// Re-starting the app on lang change. For now leaving in the code in various global views
112+
// that deals with lang change.
113+
// TODO: Once it looks like the restart on lang change approach is fine, go into the different
114+
// views and cleanup any code dealing with lang change.
115+
110116
updatePolyglot(lang);
111117
});
112118

@@ -341,9 +347,16 @@ $(window).bind('keydown', function(e) {
341347

342348
if (route !== null) {
343349
e.preventDefault();
344-
Backbone.history.navigate(route, {
345-
trigger: true
346-
});
350+
351+
if (location.hash.startsWith('#' + route)) {
352+
// Hard refresh if we're already on the page we're trying to route to
353+
// so a cached page is not served.
354+
app.router.refresh();
355+
} else {
356+
Backbone.history.navigate(route, {
357+
trigger: true
358+
});
359+
}
347360
}
348361
}
349362
});
@@ -444,7 +457,40 @@ var loadProfile = function(landingRoute, onboarded) {
444457
app.simpleMessageModal.remove = () => {
445458
throw new Error('This instance of the simpleMessageModal is globally shared ' +
446459
'and should not be removed. When you are done with it, please close it.');
447-
};
460+
};
461+
462+
// any lang changes after our app has loaded will need an app re-start to fully take effect
463+
user.on('change:language', function(md, lang) {
464+
var restartWarning;
465+
466+
restartWarning = new Dialog({
467+
title: window.polyglot.t('langChangeRestartTitle'),
468+
message: window.polyglot.t('langChangeRestartMessage'),
469+
buttons: [{
470+
text: 'Restart Later',
471+
fragment: 'restart-later'
472+
}, {
473+
text: 'Restart Now',
474+
fragment: 'restart-now'
475+
}]
476+
}).on('click-restart-later', () => {
477+
restartWarning.close();
478+
}).on('click-restart-now', () => {
479+
location.reload();
480+
}).render().open();
481+
});
482+
483+
// If navigating to a page you're already on, we'll hard refresh so
484+
// a cached page is not served, which avoids the issue of it looking
485+
// like nothing happened.
486+
$(document).on('click', '[href^="#"]', (e) => {
487+
var href = $(e.target).attr('href');
488+
489+
if (location.hash.startsWith(href)) {
490+
app.router.refresh();
491+
e.preventDefault();
492+
}
493+
});
448494

449495
app.router = new router({userModel: user, userProfile: userProfile, socketView: newSocketView});
450496

js/views/pageNavVw.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,14 @@ module.exports = baseVw.extend({
463463
},
464464

465465
getUnreadNotifCount: function() {
466-
return this.unreadNotifsViaSocket + this.notificationsCl.getUnreadCount() -
466+
var count;
467+
468+
count = this.unreadNotifsViaSocket + this.notificationsCl.getUnreadCount() -
467469
this.fetchNotifsMarkedAsRead || 0;
470+
471+
// fudge fix! sometimes the count is coming back as -1 and we can't reproduce it
472+
// nor track down why, so we're reluctantly fudging it.
473+
return count < 0 ? 0 : count;
468474
},
469475

470476
onNotifMenuOpen: function() {

js/views/settingsVw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ module.exports = pageVw.extend({
674674
},
675675

676676
cancelView: function(){
677-
Backbone.history.loadUrl();
677+
app.router.refresh();
678678
},
679679

680680
themeClick: function(e) {

0 commit comments

Comments
 (0)