Skip to content

Instantly share code, notes, and snippets.

@mcku
Created November 28, 2018 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcku/55109ff4999b472f0be696468443d2e7 to your computer and use it in GitHub Desktop.
Save mcku/55109ff4999b472f0be696468443d2e7 to your computer and use it in GitHub Desktop.
main single-page app routed render
@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