Skip to content

Commit 4e6541b

Browse files
authored
Merge pull request element-hq#3385 from vector-im/luke/fix-screen-after-login
Refactor screen set after login
2 parents df22c90 + 7ff2871 commit 4e6541b

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

‎src/vector/index.js‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,24 @@ var validBrowser = checkBrowserFeatures([
102102
"objectfit"
103103
]);
104104

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

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

116125
function onHashChange(ev) {
@@ -121,22 +130,13 @@ function onHashChange(ev) {
121130
routeUrl(window.location);
122131
}
123132

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

142142
// We use this to work out what URL the SDK should
@@ -268,8 +268,7 @@ async function loadApp() {
268268
} else if (validBrowser) {
269269
UpdateChecker.start();
270270

271-
var MatrixChat = sdk.getComponent('structures.MatrixChat');
272-
271+
const MatrixChat = sdk.getComponent('structures.MatrixChat');
273272
window.matrixChat = ReactDOM.render(
274273
<MatrixChat
275274
onNewScreen={onNewScreen}
@@ -280,19 +279,11 @@ async function loadApp() {
280279
startingFragmentQueryParams={fragparts.params}
281280
enableGuest={true}
282281
onLoadCompleted={onLoadCompleted}
282+
initialScreenAfterLogin={getScreenFromLocation(window.location)}
283283
defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()}
284284
/>,
285285
document.getElementById('matrixchat')
286286
);
287-
288-
routeUrl(window.location);
289-
290-
// we didn't propagate screen changes to the URL bar while we were loading; do it now.
291-
loaded = true;
292-
if (lastLoadedScreen) {
293-
onNewScreen(lastLoadedScreen);
294-
lastLoadedScreen = null;
295-
}
296287
}
297288
else {
298289
console.error("Browser is missing required features.");

0 commit comments

Comments
 (0)