change Map to List in model, scalajs didn't decode

This commit is contained in:
efim 2023-04-23 23:15:59 +04:00
parent f3e51a4750
commit 77b34a2ca7
4 changed files with 5 additions and 28 deletions

View File

@ -22,10 +22,6 @@ object Models {
} }
object RoomStateView { object RoomStateView {
given Encoder[Map[PlayerID, String]] = Encoder.encodeMap[PlayerID, String]
given Decoder[Map[PlayerID, String]] = Decoder.decodeMap[PlayerID, String]
given Codec[Map[PlayerID, String]] = Codec.from(summon[Decoder[Map[PlayerID, String]]], summon[Encoder[Map[PlayerID, String]]])
val empty = RoomStateView( val empty = RoomStateView(
List.empty, PlayerID(0), List.empty, RoundState.Voting(None, List.empty), false List.empty, PlayerID(0), List.empty, RoundState.Voting(None, List.empty), false
) )
@ -45,16 +41,9 @@ object Models {
/** view state for round after opening the votes /** view state for round after opening the votes
*/ */
case Viewing( case Viewing(
votes: Map[PlayerID, String] votes: List[(PlayerID, String)]
) )
final case class PlayerID(id: Long) derives Codec.AsObject final case class PlayerID(id: Long) derives Codec.AsObject
object PlayerID {
given KeyEncoder[PlayerID] with
def apply(key: PlayerID): String = key.toString
given KeyDecoder[PlayerID] with
def apply(key: String): Option[PlayerID] = key.toLongOption.map(PlayerID.apply(_))
}
final case class Player(name: String, id: PlayerID) derives Codec.AsObject final case class Player(name: String, id: PlayerID) derives Codec.AsObject

View File

@ -23,7 +23,7 @@ object TestModels {
me = me.id, me = me.id,
allowedCards = List("xs", "s", "m", "l", "xl"), allowedCards = List("xs", "s", "m", "l", "xl"),
round = RoundState.Viewing( round = RoundState.Viewing(
Map(me.id -> "xs", pony.id -> "l", birdy.id -> "s", horsey.id -> "m") List(me.id -> "xs", pony.id -> "l", birdy.id -> "s", horsey.id -> "m")
), ),
canCloseRound = true canCloseRound = true
) )
@ -98,7 +98,7 @@ object TestModels {
me = me.id, me = me.id,
allowedCards = List("xs", "s", "m", "l", "xl"), allowedCards = List("xs", "s", "m", "l", "xl"),
round = RoundState.Viewing( round = RoundState.Viewing(
Map(me.id -> "m", pony.id -> "l", birdy.id -> "s", horsey.id -> "m") List(me.id -> "m", pony.id -> "l", birdy.id -> "s", horsey.id -> "m")
), ),
canCloseRound = true canCloseRound = true
) )

View File

@ -54,18 +54,6 @@ object Main {
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(
className := "bg-yellow-400",
child.text <-- roomStateWSStream.events
.map { ev =>
{
val a = ev.toString()
g.console.warn(s"got state $a")
a
}
}
.startWith("BEFORE WS")
),
div( div(
className := "h-24 w-full flex flex-for justify-center items-center bg-green-200", className := "h-24 w-full flex flex-for justify-center items-center bg-green-200",
p(className := "text-2xl", "Here be header") p(className := "text-2xl", "Here be header")

View File

@ -46,11 +46,11 @@ object TableView {
} else isOpen.alreadyVoted.find(_.id == id).fold(NoCard(name))(_ => CardBack) } else isOpen.alreadyVoted.find(_.id == id).fold(NoCard(name))(_ => CardBack)
case isClosed: RoundState.Viewing => case isClosed: RoundState.Viewing =>
isClosed.votes isClosed.votes
.get(id) .find(_._1 == id)
.fold { .fold {
g.console.error(s"missing vote for player $name") g.console.error(s"missing vote for player $name")
Open("error") Open("error")
} { vote => Open(vote) } } { case (_, vote) => Open(vote) }
} }
} }