Created
November 28, 2018 05:41
-
-
Save mcku/55109ff4999b472f0be696468443d2e7 to your computer and use it in GitHub Desktop.
main single-page app routed render
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dom def render: Binding[Element] = { | |
// init | |
implicit val pageState: PageState = AppState.page.bind | |
//some actions here | |
//actions.action1() | |
//actions.action2() | |
val routePage: Page = Router.route.state.bind | |
// main token verification | |
val authCheckResult: Option[Try[Boolean]] = | |
FutureBinding(AuthClient.checkAuthComplete()).bind | |
authCheckResult match { | |
case Some(Success(authSuccess)) if authSuccess => | |
routePage match { | |
case Router.loginPage => { | |
LoginPage.renderLoginV2.bind | |
} | |
case Router.indivualPage => { | |
if(navDebug) println("rendering nova") | |
NovaPage.render.bind | |
} | |
case _ => { | |
if(navDebug) println("rendering none") | |
<div>NotFound</div>.asInstanceOf[HTMLElement] | |
} | |
} | |
case Some(Success(authSuccess)) if !authSuccess => | |
if(navDebug) println("auth negative, go to login page") | |
routePage match { | |
case Router.signupPage => { | |
SignupPage.render.bind | |
} | |
case Router.loginPage => { | |
if(navDebug) println("rendering loginPage") | |
LoginPage.renderLoginV2.bind | |
} | |
case _ => { | |
Router.gotoPage(Router.loginPage) | |
<div>You need to log in again</div>.asInstanceOf[HTMLElement] | |
} | |
} | |
case Some(Failure(x)) => { | |
if(navDebug) println("auth could not complete, rendering login") | |
Router.gotoPage(Router.loginPage) | |
implicit val lang: Lang = Lang(state.bind.lang.bind) | |
LoginPage.renderLoginV2.bind | |
} | |
case None => { | |
if(navDebug) println("no auth result yet") | |
SemanticComponents.loadingIndicatorComponent.bind | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment