From eddf33a68952f71148786038ef0e001deda3c57c Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 8 Mar 2017 14:57:13 +0000 Subject: [PATCH 1/3] Refactor screen set after login --- src/vector/index.js | 47 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 05346888..892d9086 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -101,15 +101,24 @@ var validBrowser = checkBrowserFeatures([ "objectfit" ]); +// Parse the given window.location and return parameters that can be used when calling +// MatrixChat.showScreen(screen, params) +function getScreenFromLocation(location) { + const fragparts = parseQsFromFragment(location); + return { + screen: fragparts.location.substring(1), + params: fragparts.params, + } +} + // Here, we do some crude URL analysis to allow // deep-linking. function routeUrl(location) { if (!window.matrixChat) return; - console.log("Routing URL "+location); - var fragparts = parseQsFromFragment(location); - window.matrixChat.showScreen(fragparts.location.substring(1), - fragparts.params); + console.log("Routing URL ", location.href); + const s = getScreenFromLocation(location); + window.matrixChat.showScreen(s.screen, s.params); } function onHashChange(ev) { @@ -120,22 +129,13 @@ function onHashChange(ev) { routeUrl(window.location); } -var loaded = false; -var lastLoadedScreen = null; - // This will be called whenever the SDK changes screens, // so a web page can update the URL bar appropriately. var onNewScreen = function(screen) { console.log("newscreen "+screen); - // just remember the most recent screen while we are loading, so that the - // user doesn't see the URL bar doing a dance - if (!loaded) { - lastLoadedScreen = screen; - } else { - var hash = '#/' + screen; - lastLocationHashSet = hash; - window.location.hash = hash; - } + var hash = '#/' + screen; + lastLocationHashSet = hash; + window.location.hash = hash; } // We use this to work out what URL the SDK should @@ -255,6 +255,11 @@ async function loadApp() { var MatrixChat = sdk.getComponent('structures.MatrixChat'); + // Clone the current location before MatrixChat gets a chance to change it. This + // can be used to go to the correct screen after login + const entryLocation = {}; + Object.keys(window.location).forEach((k) => {entryLocation[k] = window.location[k]}); + window.matrixChat = ReactDOM.render( , document.getElementById('matrixchat') ); - - routeUrl(window.location); - - // we didn't propagate screen changes to the URL bar while we were loading; do it now. - loaded = true; - if (lastLoadedScreen) { - onNewScreen(lastLoadedScreen); - lastLoadedScreen = null; - } } else { console.error("Browser is missing required features."); From cbc31a6c418c4b87878b74f915e5fdefec9f8ed7 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Thu, 9 Mar 2017 10:03:23 +0000 Subject: [PATCH 2/3] Remove redundant thing --- src/vector/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 892d9086..6fb6506d 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -254,12 +254,6 @@ async function loadApp() { UpdateChecker.start(); var MatrixChat = sdk.getComponent('structures.MatrixChat'); - - // Clone the current location before MatrixChat gets a chance to change it. This - // can be used to go to the correct screen after login - const entryLocation = {}; - Object.keys(window.location).forEach((k) => {entryLocation[k] = window.location[k]}); - window.matrixChat = ReactDOM.render( Date: Thu, 9 Mar 2017 10:04:15 +0000 Subject: [PATCH 3/3] const --- src/vector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/index.js b/src/vector/index.js index 6fb6506d..e4471be7 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -253,7 +253,7 @@ async function loadApp() { } else if (validBrowser) { UpdateChecker.start(); - var MatrixChat = sdk.getComponent('structures.MatrixChat'); + const MatrixChat = sdk.getComponent('structures.MatrixChat'); window.matrixChat = ReactDOM.render(