Refactor screen set after login
This commit is contained in:
parent
c6da4d93f1
commit
eddf33a689
|
@ -101,15 +101,24 @@ var validBrowser = checkBrowserFeatures([
|
||||||
"objectfit"
|
"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
|
// Here, we do some crude URL analysis to allow
|
||||||
// deep-linking.
|
// deep-linking.
|
||||||
function routeUrl(location) {
|
function routeUrl(location) {
|
||||||
if (!window.matrixChat) return;
|
if (!window.matrixChat) return;
|
||||||
|
|
||||||
console.log("Routing URL "+location);
|
console.log("Routing URL ", location.href);
|
||||||
var fragparts = parseQsFromFragment(location);
|
const s = getScreenFromLocation(location);
|
||||||
window.matrixChat.showScreen(fragparts.location.substring(1),
|
window.matrixChat.showScreen(s.screen, s.params);
|
||||||
fragparts.params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onHashChange(ev) {
|
function onHashChange(ev) {
|
||||||
|
@ -120,22 +129,13 @@ function onHashChange(ev) {
|
||||||
routeUrl(window.location);
|
routeUrl(window.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
var loaded = false;
|
|
||||||
var lastLoadedScreen = null;
|
|
||||||
|
|
||||||
// This will be called whenever the SDK changes screens,
|
// This will be called whenever the SDK changes screens,
|
||||||
// so a web page can update the URL bar appropriately.
|
// so a web page can update the URL bar appropriately.
|
||||||
var onNewScreen = function(screen) {
|
var onNewScreen = function(screen) {
|
||||||
console.log("newscreen "+screen);
|
console.log("newscreen "+screen);
|
||||||
// just remember the most recent screen while we are loading, so that the
|
var hash = '#/' + screen;
|
||||||
// user doesn't see the URL bar doing a dance
|
lastLocationHashSet = hash;
|
||||||
if (!loaded) {
|
window.location.hash = hash;
|
||||||
lastLoadedScreen = screen;
|
|
||||||
} else {
|
|
||||||
var hash = '#/' + screen;
|
|
||||||
lastLocationHashSet = hash;
|
|
||||||
window.location.hash = hash;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use this to work out what URL the SDK should
|
// We use this to work out what URL the SDK should
|
||||||
|
@ -255,6 +255,11 @@ async function loadApp() {
|
||||||
|
|
||||||
var MatrixChat = sdk.getComponent('structures.MatrixChat');
|
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(
|
window.matrixChat = ReactDOM.render(
|
||||||
<MatrixChat
|
<MatrixChat
|
||||||
onNewScreen={onNewScreen}
|
onNewScreen={onNewScreen}
|
||||||
|
@ -265,19 +270,11 @@ async function loadApp() {
|
||||||
startingFragmentQueryParams={fragparts.params}
|
startingFragmentQueryParams={fragparts.params}
|
||||||
enableGuest={true}
|
enableGuest={true}
|
||||||
onLoadCompleted={onLoadCompleted}
|
onLoadCompleted={onLoadCompleted}
|
||||||
|
initialScreenAfterLogin={getScreenFromLocation(window.location)}
|
||||||
defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()}
|
defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()}
|
||||||
/>,
|
/>,
|
||||||
document.getElementById('matrixchat')
|
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 {
|
else {
|
||||||
console.error("Browser is missing required features.");
|
console.error("Browser is missing required features.");
|
||||||
|
|
Loading…
Reference in New Issue