Skip to content

Commit eddf33a

Browse files
author
Luke Barnard
committed
Refactor screen set after login
1 parent c6da4d9 commit eddf33a

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

‎src/vector/index.js‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,24 @@ var validBrowser = checkBrowserFeatures([
101101
"objectfit"
102102
]);
103103

104+
// Parse the given window.location and return parameters that can be used when calling
105+
// MatrixChat.showScreen(screen, params)
106+
function getScreenFromLocation(location) {
107+
const fragparts = parseQsFromFragment(location);
108+
return {
109+
screen: fragparts.location.substring(1),
110+
params: fragparts.params,
111+
}
112+
}
113+
104114
// Here, we do some crude URL analysis to allow
105115
// deep-linking.
106116
function routeUrl(location) {
107117
if (!window.matrixChat) return;
108118

109-
console.log("Routing URL "+location);
110-
var fragparts = parseQsFromFragment(location);
111-
window.matrixChat.showScreen(fragparts.location.substring(1),
112-
fragparts.params);
119+
console.log("Routing URL ", location.href);
120+
const s = getScreenFromLocation(location);
121+
window.matrixChat.showScreen(s.screen, s.params);
113122
}
114123

115124
function onHashChange(ev) {
@@ -120,22 +129,13 @@ function onHashChange(ev) {
120129
routeUrl(window.location);
121130
}
122131

123-
var loaded = false;
124-
var lastLoadedScreen = null;
125-
126132
// This will be called whenever the SDK changes screens,
127133
// so a web page can update the URL bar appropriately.
128134
var onNewScreen = function(screen) {
129135
console.log("newscreen "+screen);
130-
// just remember the most recent screen while we are loading, so that the
131-
// user doesn't see the URL bar doing a dance
132-
if (!loaded) {
133-
lastLoadedScreen = screen;
134-
} else {
135-
var hash = '#/' + screen;
136-
lastLocationHashSet = hash;
137-
window.location.hash = hash;
138-
}
136+
var hash = '#/' + screen;
137+
lastLocationHashSet = hash;
138+
window.location.hash = hash;
139139
}
140140

141141
// We use this to work out what URL the SDK should
@@ -255,6 +255,11 @@ async function loadApp() {
255255

256256
var MatrixChat = sdk.getComponent('structures.MatrixChat');
257257

258+
// Clone the current location before MatrixChat gets a chance to change it. This
259+
// can be used to go to the correct screen after login
260+
const entryLocation = {};
261+
Object.keys(window.location).forEach((k) => {entryLocation[k] = window.location[k]});
262+
258263
window.matrixChat = ReactDOM.render(
259264
<MatrixChat
260265
onNewScreen={onNewScreen}
@@ -265,19 +270,11 @@ async function loadApp() {
265270
startingFragmentQueryParams={fragparts.params}
266271
enableGuest={true}
267272
onLoadCompleted={onLoadCompleted}
273+
initialScreenAfterLogin={getScreenFromLocation(window.location)}
268274
defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()}
269275
/>,
270276
document.getElementById('matrixchat')
271277
);
272-
273-
routeUrl(window.location);
274-
275-
// we didn't propagate screen changes to the URL bar while we were loading; do it now.
276-
loaded = true;
277-
if (lastLoadedScreen) {
278-
onNewScreen(lastLoadedScreen);
279-
lastLoadedScreen = null;
280-
}
281278
}
282279
else {
283280
console.error("Browser is missing required features.");

0 commit comments

Comments
 (0)