Island UI: finish the routing implementation related to landing page (if mode not chosen redirect to landing page, etc.)

This commit is contained in:
VakarisZ 2021-07-15 10:08:14 +03:00
parent 980f06ed73
commit 4dc138ca48
1 changed files with 31 additions and 20 deletions

View File

@ -79,25 +79,26 @@ class AppComponent extends AuthComponent {
if (res) {
this.checkMode()
.then(() => {
if(this.state.islandMode === null) {
return
}
this.authFetch('/api')
.then(res => res.json())
.then(res => {
// This check is used to prevent unnecessary re-rendering
let isChanged = false;
for (let step in this.state.completedSteps) {
if (this.state.completedSteps[step] !== res['completed_steps'][step]) {
isChanged = true;
break;
if (this.state.islandMode === null) {
return
}
this.authFetch('/api')
.then(res => res.json())
.then(res => {
// This check is used to prevent unnecessary re-rendering
let isChanged = false;
for (let step in this.state.completedSteps) {
if (this.state.completedSteps[step] !== res['completed_steps'][step]) {
isChanged = true;
break;
}
}
}
if (isChanged) {
this.setState({completedSteps: res['completed_steps']});
this.showInfectionDoneNotification();
}
});}
if (isChanged) {
this.setState({completedSteps: res['completed_steps']});
this.showInfectionDoneNotification();
}
});
}
)
}
@ -115,9 +116,9 @@ class AppComponent extends AuthComponent {
let render_func = () => {
switch (this.state.isLoggedIn) {
case true:
if (this.state.islandMode === null && route_path !== Routes.LandingPage) {
if (this.needsRedirectionToLandingPage(route_path)) {
return <Redirect to={{pathname: Routes.LandingPage}}/>
} else if(route_path === Routes.LandingPage && this.state.islandMode !== null){
} else if (this.needsRedirectionToGettingStarted(route_path)) {
return <Redirect to={{pathname: Routes.GettingStartedPage}}/>
}
return page_component;
@ -142,6 +143,16 @@ class AppComponent extends AuthComponent {
}
};
needsRedirectionToLandingPage = (route_path) => {
return (this.state.islandMode === null && route_path !== Routes.LandingPage)
}
needsRedirectionToGettingStarted = (route_path) => {
return route_path === Routes.LandingPage &&
this.state.islandMode !== null &&
this.state.islandMode !== undefined
}
redirectTo = (userPath, targetPath) => {
let pathQuery = new RegExp(userPath + '[/]?$', 'g');
if (window.location.pathname.match(pathQuery)) {