From e2ce12d414bcbdbab579b2261b67138057086e79 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Wed, 18 Mar 2020 11:12:23 +1000 Subject: [PATCH] FIX: Broken computing of userHasTimezone in bookmark modal and missing tap-tile templates for regular users (#9229) Based on reports here https://meta.discourse.org/t/improved-bookmarks-with-reminders/144542 * Because the `userHasTimezone` property was computed and we were checking on an (essentially) global object, ember was not aware that the user timezone had changed because it changed in a different place. instead set the timezone as internal state for the modal on show and base the computed property off of that so it mutates correctly * The tap-tile components were in the admin folder completely unnecessarily, move them out into the main discourse folder otherwise noone else can use the new bookmarks (icon + text is missing) --- .../discourse/controllers/bookmark.js | 18 ++++++++---------- .../templates/components/tap-tile-grid.hbs | 0 .../templates/components/tap-tile.hbs | 0 .../controllers/bookmark-test.js.es6 | 17 +++++++++++++++-- 4 files changed, 23 insertions(+), 12 deletions(-) rename app/assets/javascripts/{admin => discourse}/templates/components/tap-tile-grid.hbs (100%) rename app/assets/javascripts/{admin => discourse}/templates/components/tap-tile.hbs (100%) diff --git a/app/assets/javascripts/discourse/controllers/bookmark.js b/app/assets/javascripts/discourse/controllers/bookmark.js index 375a9a53412..ecafa0dd23d 100644 --- a/app/assets/javascripts/discourse/controllers/bookmark.js +++ b/app/assets/javascripts/discourse/controllers/bookmark.js @@ -32,6 +32,7 @@ export default Controller.extend(ModalFunctionality, { customReminderTime: null, lastCustomReminderDate: null, lastCustomReminderTime: null, + userTimezone: null, onShow() { this.setProperties({ @@ -43,7 +44,8 @@ export default Controller.extend(ModalFunctionality, { customReminderDate: null, customReminderTime: null, lastCustomReminderDate: null, - lastCustomReminderTime: null + lastCustomReminderTime: null, + userTimezone: this.currentUser.timezone }); this.loadLastUsedCustomReminderDatetime(); @@ -174,9 +176,9 @@ export default Controller.extend(ModalFunctionality, { return Discourse.BaseUri; }, - @discourseComputed() - userHasTimezoneSet() { - return !_.isEmpty(this.userTimezone()); + @discourseComputed("userTimezone") + userHasTimezoneSet(userTimezone) { + return !_.isEmpty(userTimezone); }, saveBookmark() { @@ -216,7 +218,7 @@ export default Controller.extend(ModalFunctionality, { }, parseCustomDateTime(date, time) { - return moment.tz(date + " " + time, this.userTimezone()); + return moment.tz(date + " " + time, this.userTimezone); }, reminderAt() { @@ -288,12 +290,8 @@ export default Controller.extend(ModalFunctionality, { return momentDate.hour(START_OF_DAY_HOUR).startOf("hour"); }, - userTimezone() { - return this.currentUser.timezone; - }, - now() { - return moment.tz(this.userTimezone()); + return moment.tz(this.userTimezone); }, laterToday() { diff --git a/app/assets/javascripts/admin/templates/components/tap-tile-grid.hbs b/app/assets/javascripts/discourse/templates/components/tap-tile-grid.hbs similarity index 100% rename from app/assets/javascripts/admin/templates/components/tap-tile-grid.hbs rename to app/assets/javascripts/discourse/templates/components/tap-tile-grid.hbs diff --git a/app/assets/javascripts/admin/templates/components/tap-tile.hbs b/app/assets/javascripts/discourse/templates/components/tap-tile.hbs similarity index 100% rename from app/assets/javascripts/admin/templates/components/tap-tile.hbs rename to app/assets/javascripts/discourse/templates/components/tap-tile.hbs diff --git a/test/javascripts/controllers/bookmark-test.js.es6 b/test/javascripts/controllers/bookmark-test.js.es6 index f8fc3720110..978b7cd19f0 100644 --- a/test/javascripts/controllers/bookmark-test.js.es6 +++ b/test/javascripts/controllers/bookmark-test.js.es6 @@ -3,7 +3,8 @@ let BookmarkController; moduleFor("controller:bookmark", { beforeEach() { - BookmarkController = this.subject({ currentUser: currentUser() }); + Discourse.currentUser = currentUser(); + BookmarkController = this.subject({ currentUser: Discourse.currentUser }); }, afterEach() { @@ -12,7 +13,7 @@ moduleFor("controller:bookmark", { }); function mockMomentTz(dateString) { - let now = moment.tz(dateString, BookmarkController.currentUser.timezone); + let now = moment.tz(dateString, BookmarkController.userTimezone); sandbox.useFakeTimers(now.valueOf()); } @@ -179,3 +180,15 @@ QUnit.test( assert.equal(BookmarkController.lastCustomReminderTime, null); } ); + +QUnit.test( + "userHasTimezoneSet updates true/false based on whether the current user timezone is set globally", + function(assert) { + Discourse.currentUser.timezone = null; + BookmarkController.onShow(); + assert.equal(BookmarkController.userHasTimezoneSet, false); + Discourse.currentUser.timezone = "Australia/Brisbane"; + BookmarkController.onShow(); + assert.equal(BookmarkController.userHasTimezoneSet, true); + } +);