table - make my own vote visible

adding overall app state, "my player id"
with intent to feed in data from auth methods, and read in other parts,
for example visibility of sections

don't quite sure that's the intended way
This commit is contained in:
efim 2023-04-22 01:03:04 +04:00
parent 42e092e747
commit 7e488b7e62
3 changed files with 17 additions and 11 deletions

View File

@ -23,19 +23,18 @@ final case class RoomStateView(
} }
object RoomStateView { object RoomStateView {
val testRoom = {
val me = Player("wormy", PlayerID()) val me = Player("wormy", PlayerID())
val testRoom = {
val pony = Player("pony", PlayerID()) val pony = Player("pony", PlayerID())
RoomStateView( RoomStateView(
players = List(me, Player("birdy", PlayerID()), pony), players = List(me, Player("birdy", PlayerID()), pony),
me = me.id, me = me.id,
allowedCards = List("xs", "s", "m", "l", "xl"), allowedCards = List("xs", "s", "m", "l", "xl"),
round = VotingRound(myCard = Some("l"), alreadyVoted = List(me, pony)), round = VotingRound(myCard = Some("s"), alreadyVoted = List(me, pony)),
canCloseRound = true canCloseRound = true
) )
} }
val testOpenedRoom = { val testOpenedRoom = {
val me = Player("wormy", PlayerID())
val pony = Player("pony", PlayerID()) val pony = Player("pony", PlayerID())
val birdy = Player("birdy", PlayerID()) val birdy = Player("birdy", PlayerID())
val horsey = Player("horsey", PlayerID()) val horsey = Player("horsey", PlayerID())

View File

@ -11,20 +11,24 @@ import org.scalajs.dom
val javascriptLogo: String = js.native val javascriptLogo: String = js.native
@main @main
def LiveChart(): Unit = def PlanningPokerUrgh(): Unit =
renderOnDomContentLoaded( renderOnDomContentLoaded(
dom.document.getElementById("app"), dom.document.getElementById("app"),
Main.appElement() Main.appElement()
) )
object Main { object Main {
val bgColor = "bg-green-200" final case class AppState(
myId: Option[PlayerID]
)
// TODO is this ok for state creation? link with auth component and use in another?
val appStateSignal = Var(AppState(Some(RoomStateView.me.id))).signal
def appElement(): Element = { def appElement(): Element = {
div( div(
className := "w-screen h-screen flex flex-col justify-center items-center", className := "w-screen h-screen flex flex-col justify-center items-center",
div( div(
className := "h-24 w-full flex flex-for justify-center items-center", className := "h-24 w-full flex flex-for justify-center items-center bg-green-200",
className := bgColor,
p(className := "text-2xl", "Here be header"), p(className := "text-2xl", "Here be header"),
), ),
RoomView.renderRoom(RoomStateView.testRoom) RoomView.renderRoom(RoomStateView.testRoom)

View File

@ -12,9 +12,9 @@ object TableView {
// so, it's more efficient to share an observable, than to create multiple copies... // so, it's more efficient to share an observable, than to create multiple copies...
def renderTable(roundSignal: Signal[RoomStateView]): Element = { def renderTable(roundSignal: Signal[RoomStateView]): Element = {
val playerIdToCardTypeSignal = val playerIdToCardTypeSignal =
roundSignal.map(state => roundSignal.combineWith(Main.appStateSignal.map(_.myId)).map((state, myIdOpt) =>
state.players.map(p => state.players.map(p =>
p.id -> getPlayerCardType(p.id, state.round, p.name) p.id -> getPlayerCardType(p.id, state.round, p.name, myIdOpt)
) )
) )
@ -35,11 +35,14 @@ object TableView {
def getPlayerCardType( def getPlayerCardType(
id: PlayerID, id: PlayerID,
state: RoundState, state: RoundState,
name: String name: String,
myId: Option[PlayerID]
): CardState = { ): CardState = {
state match { state match {
case isOpen: VotingRound => case isOpen: VotingRound =>
isOpen.alreadyVoted.find(_.id == id).fold(NoCard(name))(_ => CardBack) if (myId.forall(_ == id)) {
isOpen.myCard.fold(NoCard(name))(vote => Open(vote))
} else isOpen.alreadyVoted.find(_.id == id).fold(NoCard(name))(_ => CardBack)
case isClosed: ViewingRound => case isClosed: ViewingRound =>
isClosed.votes isClosed.votes
.get(id) .get(id)