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