front: simple table control buttons
This commit is contained in:
parent
f8bf1b961b
commit
ecb1717eb3
|
@ -0,0 +1,41 @@
|
|||
package industries.sunshine.planningpoker
|
||||
|
||||
import scala.scalajs.js
|
||||
import com.raquo.laminar.api.L.{*, given}
|
||||
import industries.sunshine.planningpoker.common.Models.RoundState
|
||||
import com.raquo.airstream.core.Signal
|
||||
import industries.sunshine.planningpoker.common.Models.RoundState
|
||||
import industries.sunshine.planningpoker.common.Models.RoundState
|
||||
import io.laminext.fetch.Fetch
|
||||
import scala.scalajs.js.Dynamic.{global => g}
|
||||
|
||||
import concurrent.ExecutionContext.Implicits.global
|
||||
|
||||
object TableControls {
|
||||
def render(roundSignal: Signal[RoundState]): Element = {
|
||||
div(
|
||||
child <-- roundSignal.map {
|
||||
case RoundState.Viewing(_) => newPollButton()
|
||||
case RoundState.Voting(_, _) => endPollButton()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val commonButtonStyle = "border-2 border-black rounded-xl m-2 p-1"
|
||||
def endPollButton(): Element = button(
|
||||
className := commonButtonStyle,
|
||||
"end voting",
|
||||
onClick.flatMap(_ => Fetch.get("/api/end-voting").text) --> Observer(resp =>
|
||||
g.console.info(resp.toString())
|
||||
)
|
||||
)
|
||||
|
||||
def newPollButton(): Element = button(
|
||||
className := commonButtonStyle,
|
||||
"start next round",
|
||||
onClick.flatMap(_ => Fetch.get("/api/new-poll").text) --> Observer(resp =>
|
||||
g.console.info(resp.toString())
|
||||
)
|
||||
)
|
||||
|
||||
}
|
|
@ -11,17 +11,23 @@ object TableView {
|
|||
// but, can't have map to player, because overall state is required.
|
||||
// but can i split full state into several observables by that key? i think i should be able to
|
||||
// so, it's more efficient to share an observable, than to create multiple copies...
|
||||
def renderTable(roundSignal: Signal[RoomStateView]): Element = {
|
||||
def renderTable(roomStateSignal: Signal[RoomStateView]): Element = {
|
||||
val playerIdToCardTypeSignal =
|
||||
roundSignal
|
||||
roomStateSignal
|
||||
.map(state =>
|
||||
state.players.map(p => p.id -> getPlayerCardType(p.id, state.round, p.name, state.me))
|
||||
)
|
||||
|
||||
div(
|
||||
className := "w-full h-full border-2 border-amber-700 flex flex-row justify-center items-center bg-green-100",
|
||||
children <-- playerIdToCardTypeSignal.split(_._1) { (id, initial, cardTypeSignal) =>
|
||||
renderPlayerCard(cardTypeSignal.map(_._2))
|
||||
className := "w-full h-full border-2 border-amber-700 flex flex-col justify-center items-center bg-green-100",
|
||||
div(
|
||||
className := "w-full border-2 border-amber-600 flex flex-row justify-center items-center bg-green-100",
|
||||
children <-- playerIdToCardTypeSignal.split(_._1) { (id, initial, cardTypeSignal) =>
|
||||
renderPlayerCard(cardTypeSignal.map(_._2))
|
||||
}
|
||||
),
|
||||
child <-- roomStateSignal.map { state =>
|
||||
if (state.canCloseRound) TableControls.render(roomStateSignal.map(_.round)) else emptyNode
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue