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 {
val me = Player("wormy", PlayerID())
val testRoom = {
val me = Player("wormy", PlayerID())
val pony = Player("pony", PlayerID())
RoomStateView(
players = List(me, Player("birdy", PlayerID()), pony),
me = me.id,
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
)
}
val testOpenedRoom = {
val me = Player("wormy", PlayerID())
val pony = Player("pony", PlayerID())
val birdy = Player("birdy", PlayerID())
val horsey = Player("horsey", PlayerID())

View File

@ -11,20 +11,24 @@ import org.scalajs.dom
val javascriptLogo: String = js.native
@main
def LiveChart(): Unit =
def PlanningPokerUrgh(): Unit =
renderOnDomContentLoaded(
dom.document.getElementById("app"),
Main.appElement()
)
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 = {
div(
className := "w-screen h-screen flex flex-col justify-center items-center",
div(
className := "h-24 w-full flex flex-for justify-center items-center",
className := bgColor,
className := "h-24 w-full flex flex-for justify-center items-center bg-green-200",
p(className := "text-2xl", "Here be header"),
),
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...
def renderTable(roundSignal: Signal[RoomStateView]): Element = {
val playerIdToCardTypeSignal =
roundSignal.map(state =>
roundSignal.combineWith(Main.appStateSignal.map(_.myId)).map((state, myIdOpt) =>
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(
id: PlayerID,
state: RoundState,
name: String
name: String,
myId: Option[PlayerID]
): CardState = {
state match {
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 =>
isClosed.votes
.get(id)