You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.9 KiB
108 lines
2.9 KiB
package nova.monadic_sfx.screens
|
|
import nova.monadic_sfx.AppTypes
|
|
import scalafx.scene.control.TextField
|
|
import scalafx.scene.control._
|
|
import scalafx.scene.layout.VBox
|
|
import scalafx.scene.Node
|
|
import scalafx.Includes._
|
|
import scalafx.scene.Parent
|
|
import scalafx.application.JFXApp.PrimaryStage
|
|
import nova.monadic_sfx.http.requests.DummyRequest
|
|
import monix.eval.Task
|
|
import monix.execution.Scheduler
|
|
import cats.effect.Effect
|
|
import cats.effect.implicits._
|
|
import nova.monadic_sfx.util.Action
|
|
import io.odin.Logger
|
|
import nova.monadic_sfx.http.Requesters
|
|
import sttp.client.Response
|
|
import nova.monadic_sfx.models.HttpBinResponse
|
|
import sttp.client.ResponseError
|
|
import nova.monadic_sfx.executors.Schedulers
|
|
import nova.monadic_sfx.ui.screens.Screen
|
|
// import io.odin.syntax._
|
|
// import _root_.monix.eval.Task
|
|
// import io.odin.monix._
|
|
// import javafx.beans.property.ObjectProperty
|
|
// import javafx.event.{ActionEvent, EventHandler}
|
|
class LoginScreen(
|
|
override protected val appStage: PrimaryStage,
|
|
logger: Logger[Task],
|
|
backend: AppTypes.HttpBackend,
|
|
system: akka.actor.ActorSystem,
|
|
requesters: Requesters,
|
|
schedulers: Schedulers
|
|
) extends Screen {
|
|
val dummyRequester: DummyRequest = requesters.dummyRequester
|
|
//pure function callbacks, but with side effects still
|
|
|
|
// lazy val hs = {
|
|
// import com.softwaremill.macwire._
|
|
// lazy val action = () => onLogout(appStage)
|
|
// wire[HomeScreen]
|
|
// }
|
|
|
|
private def onLogout(stage: PrimaryStage) =
|
|
for {
|
|
_ <- logger.info("Logging out")
|
|
root <- render
|
|
_ <- changeRootL(root)
|
|
} yield ()
|
|
|
|
private def onLogin(stage: PrimaryStage) =
|
|
for {
|
|
_ <- logger.info("Logging in")
|
|
homeScreen <- HomeScreen(
|
|
backend,
|
|
system,
|
|
() => onLogout(appStage)
|
|
)
|
|
_ <- Task { stage.scene().setRoot(homeScreen) }
|
|
} yield ()
|
|
|
|
private lazy val root = Task.deferAction(implicit scheduler =>
|
|
Task {
|
|
new VBox {
|
|
children = Seq(
|
|
new Label {
|
|
text = "username"
|
|
},
|
|
new TextField(),
|
|
new Label {
|
|
text = "password"
|
|
},
|
|
new TextField(),
|
|
new Button {
|
|
text = "Login"
|
|
onAction = () =>
|
|
Action.asyncT {
|
|
Task
|
|
.parSequence(
|
|
List(
|
|
testRequest,
|
|
// .executeOn(Scheduler.global)
|
|
onLogin(appStage)
|
|
)
|
|
)
|
|
}
|
|
}
|
|
)
|
|
}
|
|
}
|
|
)
|
|
def render: Task[Parent] = root
|
|
|
|
val testRequest = for {
|
|
res <- dummyRequester.send()
|
|
_ <- logger.info(res.body.toString())
|
|
} yield ()
|
|
|
|
}
|
|
|
|
// object LoginScreen {
|
|
// def apply(
|
|
// appStage: PrimaryStage,
|
|
// backend: AppTypes.HttpBackend,
|
|
// system: akka.actor.ActorSystem
|
|
// ) = new LoginScreen(appStage, backend, system).render
|
|
// }
|