Skip to content

Commit

Permalink
more conversions. they're easy now
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 9, 2023
1 parent df3c040 commit 8bb06ee
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.zegreatrob.coupling.model.pairassignmentdocument.PinnedPlayer
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.pin.Pin
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import csstype.PropertiesBuilder
import emotion.react.css
Expand Down Expand Up @@ -61,11 +60,8 @@ val CurrentPairAssignmentsPanel by nfc<CurrentPairAssignmentsPanelProps> { props
}
}

private fun ChildrenBuilder.dateHeader(pairAssignments: PairAssignmentDocument) = div {
div {
add(PairAssignmentsHeader(pairAssignments))
}
}
private fun ChildrenBuilder.dateHeader(pairAssignments: PairAssignmentDocument) =
div { div { PairAssignmentsHeader(pairAssignments) } }

private fun ChildrenBuilder.pairAssignmentList(
party: PartyDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import com.zegreatrob.coupling.model.pairassignmentdocument.PinnedCouplingPair
import com.zegreatrob.coupling.model.pairassignmentdocument.players
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.player.Player
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.react.dataloader.DataLoader
import com.zegreatrob.react.dataloader.EmptyState
import com.zegreatrob.react.dataloader.PendingState
import com.zegreatrob.react.dataloader.ResolvedState
import csstype.PropertiesBuilder
import emotion.css.ClassName
import react.Props
import react.PropsWithChildren
import react.dom.html.ReactHTML.div
import web.cssom.Color
Expand All @@ -32,19 +32,20 @@ import web.cssom.Padding
import web.cssom.px
import web.cssom.vh

data class PairAssignments(
val party: PartyDetails,
val players: List<Player>,
val pairs: PairAssignmentDocument?,
val setPairs: (PairAssignmentDocument) -> Unit,
val controls: Controls<DeletePairAssignmentsCommand.Dispatcher>,
val message: CouplingSocketMessage,
val allowSave: Boolean,
) : DataPropsBind<PairAssignments>(pairAssignments)

val pairAssignmentsClassName = ClassName { pairAssignmentStyles() }

private val pairAssignments by ntmFC<PairAssignments> { props ->
external interface PairAssignmentsProps : Props {
var party: PartyDetails
var players: List<Player>
var pairs: PairAssignmentDocument?
var setPairs: (PairAssignmentDocument) -> Unit
var controls: Controls<DeletePairAssignmentsCommand.Dispatcher>
var message: CouplingSocketMessage
var allowSave: Boolean
}

@ReactFunc
val PairAssignments by nfc<PairAssignmentsProps> { props ->
val (party, players, pairs, setPairs, controls, message, allowSave) = props

val pairAssignments = pairs?.overlayUpdatedPlayers(players)
Expand All @@ -55,7 +56,7 @@ private val pairAssignments by ntmFC<PairAssignments> { props ->
className = pairAssignmentsClassName
div {
PartyBrowser(party)
add(PairSection(party, players, pairAssignments, allowSave, setPairs, controls))
PairSection(party, players, pairAssignments, allowSave, setPairs, controls)
}
ControlPanel(party)
add(PlayerRoster(label = "Unpaired players", partyId = party.id, players = notPairedPlayers))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.zegreatrob.coupling.client.components.pairassignments

import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.nfc
import react.Props

data class PairAssignmentsHeader(val pairAssignments: PairAssignmentDocument) :
DataPropsBind<PairAssignmentsHeader>(pairAssignmentsHeader)
external interface PairAssignmentsHeaderProps : Props {
var pairAssignments: PairAssignmentDocument
}

val pairAssignmentsHeader by ntmFC<PairAssignmentsHeader> { (pairAssignments) ->
@ReactFunc
val PairAssignmentsHeader by nfc<PairAssignmentsHeaderProps> { (pairAssignments) ->
PairAssignmentBlock {
+"Couples for ${pairAssignments.dateText()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import com.zegreatrob.coupling.client.components.white
import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.player.Player
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.minreact.nfc
import emotion.react.css
import kotlinx.browser.window
import org.w3c.dom.DataTransfer
import react.ChildrenBuilder
import react.MutableRefObject
import react.Props
import react.dom.html.ButtonHTMLAttributes
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.i
Expand All @@ -32,24 +33,25 @@ import kotlin.js.Json
import kotlin.js.Promise
import kotlin.js.json

data class PairSection(
val party: PartyDetails,
val players: List<Player>,
val pairAssignments: PairAssignmentDocument?,
val allowSave: Boolean,
val setPairs: (PairAssignmentDocument) -> Unit,
val controls: Controls<DeletePairAssignmentsCommand.Dispatcher>,
) : DataPropsBind<PairSection>(pairSection)
external interface PairSectionProps : Props {
var party: PartyDetails
var players: List<Player>
var pairAssignments: PairAssignmentDocument?
var allowSave: Boolean
var setPairs: (PairAssignmentDocument) -> Unit
var controls: Controls<DeletePairAssignmentsCommand.Dispatcher>
}

private val pairSection by ntmFC<PairSection> { (party, players, pairs, allowSave, setPairs, controls) ->
@ReactFunc
val PairSection by nfc<PairSectionProps> { (party, players, pairs, allowSave, setPairs, controls) ->
val pairSectionNode = useRef<HTMLElement>(null)

div {
css { verticalAlign = VerticalAlign.top }
div {
ref = pairSectionNode
css { display = Display.inlineBlock }
add(PairSectionPanel(party, players, pairs, allowSave, setPairs, controls))
PairSectionPanel(party, players, pairs, allowSave, setPairs, controls)
}
div {
css { float = Float.right; width = 0.px }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import com.zegreatrob.coupling.client.components.pairassignments.spin.PairAssign
import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.player.Player
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.minreact.nfc
import csstype.PropertiesBuilder
import emotion.react.css
import react.ChildrenBuilder
import react.Props
import react.dom.html.ReactHTML.div
import web.cssom.Border
import web.cssom.BoxShadow
Expand All @@ -25,16 +26,17 @@ import web.cssom.Padding
import web.cssom.px
import web.cssom.rgb

data class PairSectionPanel(
val party: PartyDetails,
val players: List<Player>,
val pairAssignments: PairAssignmentDocument?,
val allowSave: Boolean,
val setPairs: (PairAssignmentDocument) -> Unit,
val controls: Controls<DeletePairAssignmentsCommand.Dispatcher>,
) : DataPropsBind<PairSectionPanel>(pairSectionPanel)
external interface PairSectionPanelProps : Props {
var party: PartyDetails
var players: List<Player>
var pairAssignments: PairAssignmentDocument?
var allowSave: Boolean
var setPairs: (PairAssignmentDocument) -> Unit
var controls: Controls<DeletePairAssignmentsCommand.Dispatcher>
}

val pairSectionPanel by ntmFC<PairSectionPanel> { props ->
@ReactFunc
val PairSectionPanel by nfc<PairSectionPanelProps> { props ->
val (party, players, pairAssignments, allowSave, setPairs, controls) = props
div {
css { pairSectionCss() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val spinAnimationPanel by ntmFC<SpinAnimationPanel> { (party, rosteredPairAssign
val players = rosteredPairAssignments.selectedPlayers
val (rosterPlayers, revealedPairs, shownPlayer) = state.stateData(players, pairAssignments)
div {
add(PairAssignmentsHeader(pairAssignments))
PairAssignmentsHeader(pairAssignments)
assignedPairs(party, revealedPairs)
playerSpotlight(shownPlayer)
playerRoster(rosterPlayers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.party.PartyId
import com.zegreatrob.coupling.model.player.Player
import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.minreact.create
import com.zegreatrob.testmints.async.asyncSetup
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
Expand Down Expand Up @@ -55,15 +54,15 @@ class PairAssignmentsTest {
)
}) exercise {
render(
PairAssignments(
PairAssignments.create(
party,
players,
pairAssignments,
{ pairAssignments = it },
controls = Controls(StubDispatchFunc()) {},
message = CouplingSocketMessage("", emptySet(), null),
allowSave = false,
).create(),
),
jso { wrapper = MemoryRouter },
)
} verify {
Expand All @@ -90,15 +89,15 @@ class PairAssignmentsTest {
)
}) exercise {
render(
PairAssignments(
PairAssignments.create(
party,
players,
null,
{},
controls = Controls(StubDispatchFunc()) {},
message = CouplingSocketMessage("", emptySet(), null),
allowSave = false,
).create(),
),
jso { wrapper = MemoryRouter },
)
} verify {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,14 @@ private fun ChildrenBuilder.playerConfigFrame(state: AddPlayer) = add(
private fun ChildrenBuilder.pinConfigFrame(state: AddPin) =
PinConfigContent(state.party, state.newPin, state.pins, {}, {}, {})

private fun ChildrenBuilder.pairAssignmentsFrame(state: CurrentPairs) = add(
PairAssignments(
state.party,
state.players,
state.pairAssignments,
{ },
Controls(noOpDispatchFunc) {},
CouplingSocketMessage("", emptySet()),
state.allowSave,
),
private fun ChildrenBuilder.pairAssignmentsFrame(state: CurrentPairs) = PairAssignments(
party = state.party,
players = state.players,
pairs = state.pairAssignments,
setPairs = { },
controls = Controls(noOpDispatchFunc) {},
message = CouplingSocketMessage("", emptySet()),
allowSave = state.allowSave,
)

private val noOpDispatchFunc = NoOpDispatcherDispatchFunc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.zegreatrob.coupling.client.components.CouplingWebsocket
import com.zegreatrob.coupling.client.components.disconnectedMessage
import com.zegreatrob.coupling.client.components.external.auth0.react.useAuth0Data
import com.zegreatrob.coupling.client.components.pairassignments.PairAssignments
import com.zegreatrob.coupling.client.create
import com.zegreatrob.coupling.client.components.pairassignments.create
import com.zegreatrob.coupling.model.CouplingSocketMessage
import com.zegreatrob.coupling.model.Message
import com.zegreatrob.coupling.model.PairAssignmentAdjustmentMessage
Expand Down Expand Up @@ -51,19 +51,18 @@ where D : SavePairAssignmentsCommand.Dispatcher, D : DeletePairAssignmentsComman

if (token.isNotBlank()) {
CouplingWebsocket(
party.id,
partyId = party.id,
onMessage = onMessageFunc,
buildChild = {
PairAssignments(
party,
players,
pairAssignments,
updatePairAssignments,
controls,
message,
allowSave,
PairAssignments.create(
party = party,
players = players,
pairs = pairAssignments,
setPairs = updatePairAssignments,
controls = controls,
message = message,
allowSave = allowSave,
)
.create()
},
token = token,
)
Expand Down

0 comments on commit 8bb06ee

Please sign in to comment.