aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/main.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-01-29 22:08:16 +0100
committerNoah Loomans <noahloomans@gmail.com>2017-01-29 22:08:16 +0100
commitacbdba98a7ab37e76c856cc751b78e2a974036b9 (patch)
tree7081e85fe729a2a76c6d086a2d5dcac483cb5b5e /public/javascripts/main.js
parent29ea424009be3bd8561e74587b651c1c44bf2f7e (diff)
Update the page URL when selecting user
When you select a user and press the back button of your browser, it will exit out of schedule page instead of going back inside of the app. This is unexpected behavior. This commit will update the URL using history.pushState() when a user is selected. Allowing the browser navigation buttons to nicely integrate with the schedule.
Diffstat (limited to 'public/javascripts/main.js')
-rw-r--r--public/javascripts/main.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/public/javascripts/main.js b/public/javascripts/main.js
index 6f99621..6c7fd05 100644
--- a/public/javascripts/main.js
+++ b/public/javascripts/main.js
@@ -7,6 +7,7 @@ const weekSelector = require('./weekSelector')
const favorite = require('./favorite')
const scrollSnap = require('./scrollSnap')
const analytics = require('./analytics')
+const url = require('./url')
const state = {}
@@ -17,9 +18,15 @@ frontpage.show()
weekSelector.updateCurrentWeek()
scrollSnap.startListening()
-if (favorite.get() != null) {
+if (url.hasSelectedItem()) {
+ state.selectedItem = url.getSelectedItem()
+ favorite.update(state.selectedItem)
+ analytics.send.search(state.selectedItem)
+ schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem)
+} else if (favorite.get() != null) {
state.selectedItem = favorite.get()
favorite.update(state.selectedItem)
+ url.update(state.selectedItem)
analytics.send.search(state.selectedItem, true)
schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem)
} else {
@@ -29,6 +36,7 @@ if (favorite.get() != null) {
search.on('search', function (selectedItem) {
state.selectedItem = selectedItem
favorite.update(state.selectedItem)
+ url.update(state.selectedItem)
analytics.send.search(state.selectedItem)
schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem)
})
@@ -42,4 +50,10 @@ favorite.on('click', function () {
favorite.toggle(state.selectedItem)
})
+url.on('update', function (selectedItem) {
+ state.selectedItem = selectedItem
+ favorite.update(state.selectedItem)
+ schedule.viewItem(weekSelector.getSelectedWeek(), state.selectedItem)
+})
+
document.body.style.opacity = 1