Skip to content

Commit

Permalink
more conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 5, 2023
1 parent 5228aa7 commit c52bd72
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import com.zegreatrob.coupling.client.components.loadMarkdownString
import com.zegreatrob.coupling.client.components.orange
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.party.PartyId
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 react.Props
import react.dom.aria.ariaLabel
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.label
Expand All @@ -31,16 +31,15 @@ import react.router.dom.LinkProps
import react.useMemo
import react.useState

data class SlackConnectPageContent(
val parties: List<PartyDetails>,
val slackTeam: String,
val slackChannel: String,
val dispatchFunc: DispatchFunc<out SaveSlackIntegrationCommand.Dispatcher>,
) : DataPropsBind<SlackConnectPageContent>(
slackConnectPageContent,
)
external interface SlackConnectPageContentProps : Props {
var parties: List<PartyDetails>
var slackTeam: String
var slackChannel: String
var dispatchFunc: DispatchFunc<out SaveSlackIntegrationCommand.Dispatcher>
}

val slackConnectPageContent by ntmFC<SlackConnectPageContent> { props ->
@ReactFunc
val SlackConnectPageContent by nfc<SlackConnectPageContentProps> { props ->
val partySelectId = useMemo { "${uuid4()}" }

var command by useState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ import com.zegreatrob.coupling.model.pairassignmentdocument.players
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.pin.Pin
import com.zegreatrob.coupling.model.player.Player
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.nfc
import react.Props
import react.router.Navigate
import react.useState

data class PrepareSpin(
val party: PartyDetails,
val players: List<Player>,
val currentPairsDoc: PairAssignmentDocument?,
val pins: List<Pin>,
val dispatchFunc: DispatchFunc<out SpinCommand.Dispatcher>,
) : DataPropsBind<PrepareSpin>(prepareSpin)
external interface PrepareSpinProps : Props {
var party: PartyDetails
var players: List<Player>
var currentPairsDoc: PairAssignmentDocument?
var pins: List<Pin>
var dispatchFunc: DispatchFunc<out SpinCommand.Dispatcher>
}

val prepareSpin by ntmFC<PrepareSpin> { (party, players, currentPairsDoc, pins, dispatchFunc) ->
@ReactFunc
val PrepareSpin by nfc<PrepareSpinProps> { (party, players, currentPairsDoc, pins, dispatchFunc) ->
var playerSelections by useState(defaultSelections(players, currentPairsDoc))
var pinSelections by useState(pins.map { it.id })
var redirectUrl by useState<String?>(null)
Expand All @@ -33,16 +34,14 @@ val prepareSpin by ntmFC<PrepareSpin> { (party, players, currentPairsDoc, pins,
if (redirectUrl != null) {
Navigate { to = redirectUrl ?: "" }
} else {
add(
PrepareSpinContent(
party,
playerSelections,
pins,
pinSelections,
setPlayerSelections,
setPinSelections,
onSpin,
),
PrepareSpinContent(
party,
playerSelections,
pins,
pinSelections,
setPlayerSelections,
setPinSelections,
onSpin,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import com.zegreatrob.coupling.client.components.supersize
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.coupling.model.pin.Pin
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.css.ClassName
import emotion.react.css
import react.ChildrenBuilder
import react.Props
import react.dom.html.ReactHTML.br
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.h1
Expand All @@ -40,17 +41,18 @@ import web.cssom.px
import web.cssom.rgb
import web.cssom.s

data class PrepareSpinContent(
var party: PartyDetails,
var playerSelections: List<Pair<Player, Boolean>>,
var pins: List<Pin>,
var pinSelections: List<String?>,
var setPlayerSelections: (value: List<Pair<Player, Boolean>>) -> Unit,
var setPinSelections: (List<String?>) -> Unit,
var onSpin: () -> Unit,
) : DataPropsBind<PrepareSpinContent>(prepareSpinContent)
external interface PrepareSpinContentProps : Props {
var party: PartyDetails
var playerSelections: List<Pair<Player, Boolean>>
var pins: List<Pin>
var pinSelections: List<String?>
var setPlayerSelections: (value: List<Pair<Player, Boolean>>) -> Unit
var setPinSelections: (List<String?>) -> Unit
var onSpin: () -> Unit
}

val prepareSpinContent by ntmFC<PrepareSpinContent> { props ->
@ReactFunc
val PrepareSpinContent by nfc<PrepareSpinContentProps> { props ->
val (party, playerSelections, pins, pinSelections, setPlayerSelections, setPinSelections, onSpin) = props

val enabled = playerSelections.any { it.second }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.zegreatrob.coupling.stubmodel.stubPin
import com.zegreatrob.coupling.stubmodel.stubPlayers
import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.minassert.assertIsNotEqualTo
import com.zegreatrob.minreact.create
import com.zegreatrob.testmints.async.asyncSetup
import com.zegreatrob.testmints.async.asyncTestTemplate
import com.zegreatrob.testmints.setup
Expand Down Expand Up @@ -53,10 +52,9 @@ class PrepareSpinTest {
val players = emptyList<Player>()
val pins = listOf(stubPin(), stubPin())
val firstPin = pins[0]
val wrapper = render(
PrepareSpin(party, players, null, pins, StubDispatchFunc()).create(),
jso { wrapper = MemoryRouter },
)
val wrapper = render(jso { wrapper = MemoryRouter }) {
PrepareSpin(party, players, null, pins, StubDispatchFunc())
}
}) exercise {
user.click(
wrapper.container.querySelector(".$selectedPinsClass")
Expand Down Expand Up @@ -84,10 +82,9 @@ class PrepareSpinTest {
val pins = listOf(stubPin(), stubPin())
val firstPin = pins[0]

val render = render(
PrepareSpin(party, players, null, pins, StubDispatchFunc()).create(),
jso { wrapper = MemoryRouter },
)
val render = render(jso { wrapper = MemoryRouter }) {
PrepareSpin(party, players, null, pins, StubDispatchFunc())
}
}) {
user.click(
render.container.querySelector(".$selectedPinsClass")
Expand Down Expand Up @@ -120,10 +117,9 @@ class PrepareSpinTest {
val players = stubPlayers(3)
val currentPairs = null
}) exercise {
render(
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc()).create(),
jso { wrapper = MemoryRouter },
)
render(jso { wrapper = MemoryRouter }) {
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc())
}
} verify { result ->
result.container.querySelectorAll("[data-player-id]")
.asList()
Expand All @@ -150,10 +146,9 @@ class PrepareSpinTest {
pairOf(players[2]).withPins(emptySet()),
),
)
val result = render(
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc()).create(),
jso { wrapper = MemoryRouter },
)
val result = render(jso { wrapper = MemoryRouter }) {
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc())
}
}) exercise {
result.container.querySelectorAll("[data-player-id]")
.asList()
Expand All @@ -177,10 +172,9 @@ class PrepareSpinTest {
val players = stubPlayers(3)
val user = UserEvent.setup()
val currentPairs = null
val context = render(
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc()).create(),
jso { wrapper = MemoryRouter },
)
val context = render(jso { wrapper = MemoryRouter }) {
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc())
}
}) exercise {
user.click(screen.getByText("All in!"))
} verify {
Expand All @@ -203,10 +197,9 @@ class PrepareSpinTest {
date = DateTime.now(),
pairs = players.map { pairOf(it).withPins(emptySet()) },
)
val context = render(
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc()).create(),
jso { wrapper = MemoryRouter },
)
val context = render(jso { wrapper = MemoryRouter }) {
PrepareSpin(party, players, currentPairs, emptyList(), StubDispatchFunc())
}
}) {
} exercise {
user.click(screen.getByText("All out!"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.zegreatrob.coupling.stubmodel.stubPartyDetails
import com.zegreatrob.coupling.stubmodel.uuidString
import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.minassert.assertIsNotEqualTo
import com.zegreatrob.minreact.create
import com.zegreatrob.testmints.async.asyncSetup
import com.zegreatrob.wrapper.testinglibrary.react.RoleOptions
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.act
Expand All @@ -17,6 +16,7 @@ import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import react.Fragment
import react.ReactNode
import react.create
import react.router.MemoryRouter
Expand All @@ -39,15 +39,14 @@ class SlackConnectPageContentTest {
val slackTeam = uuidString()
val slackChannel = uuidString()
}) {
render(
render(jso { wrapper = MemoryRouter }) {
SlackConnectPageContent(
parties = parties,
slackTeam = slackTeam,
slackChannel = slackChannel,
dispatchFunc = stubber.func(),
).create {},
jso { wrapper = MemoryRouter },
)
)
}
actor.selectOptions(partySelect, targetParty.id.value)
returnButton
.assertIsEqualTo(null, "Return button showed up unexpectedly early")
Expand All @@ -71,14 +70,14 @@ class SlackConnectPageContentTest {
@Test
fun willNotShowReturnImmediately() = asyncSetup(object {
}) exercise {
render(
render {
SlackConnectPageContent(
parties = stubParties(2),
slackTeam = uuidString(),
slackChannel = uuidString(),
dispatchFunc = StubDispatcher().func(),
).create {},
)
)
}
} verify {
returnButton
.assertIsEqualTo(null, "Return button showed up unexpectedly early")
Expand All @@ -96,12 +95,14 @@ class SlackConnectPageContentTest {
arrayOf(
jso {
path = "*"
element = SlackConnectPageContent(
parties = listOf(party),
slackTeam = uuidString(),
slackChannel = uuidString(),
dispatchFunc = stubDispatcher.func(),
).create()
element = Fragment.create {
SlackConnectPageContent(
parties = listOf(party),
slackTeam = uuidString(),
slackChannel = uuidString(),
dispatchFunc = stubDispatcher.func(),
)
}
},
jso {
path = "/${party.id.value}/pairAssignments/current/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.zegreatrob.coupling.client.components.pin.PinConfigContent
import com.zegreatrob.coupling.client.components.player.PlayerConfigContent
import com.zegreatrob.coupling.client.components.spin.PrepareSpinContent
import com.zegreatrob.coupling.model.CouplingSocketMessage
import com.zegreatrob.coupling.model.pin.Pin
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.ntmFC
Expand Down Expand Up @@ -190,7 +191,7 @@ private fun ChildrenBuilder.partyConfigFrame(state: MakeParty) {

private fun ChildrenBuilder.prepareSpinFrame(state: PrepareToSpin) {
val (party, players, pins) = state
add(PrepareSpinContent(party, players, pins, pins.map { it.id }, {}, {}, {}))
PrepareSpinContent(party, players, pins, pins.map(Pin::id), {}, {}, {})
}

private fun ChildrenBuilder.playerConfigFrame(state: AddPlayer) = add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ val PrepareSpinPage = partyPageFunction { props, partyId ->
pinList()
}
},
toDataprops = { _, dispatcher, result ->
build = { _, dispatcher, result ->
PrepareSpin(
party = result.party?.details?.data ?: return@CouplingQuery null,
players = result.party?.playerList?.elements ?: return@CouplingQuery null,
pins = result.party?.pinList?.elements ?: return@CouplingQuery null,
party = result.party?.details?.data ?: return@CouplingQuery,
players = result.party?.playerList?.elements ?: return@CouplingQuery,
pins = result.party?.pinList?.elements ?: return@CouplingQuery,
currentPairsDoc = result.party?.currentPairAssignmentDocument?.element,
dispatchFunc = dispatcher,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fun <R> CouplingQuery(
query: SuspendAction<CommandDispatcher, R?>,
build: ChildrenBuilder.(ReloadFunc, DispatchFunc<CommandDispatcher>, R) -> Unit,
commander: Commander,
) = CouplingQuery<R>(
) = CouplingQuery(
query = query,
toNode = { r: ReloadFunc, d: DispatchFunc<CommandDispatcher>, result: R ->
react.Fragment.create { build(r, d, result) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import com.zegreatrob.minreact.nfc
val SlackConnectPage by nfc<PageProps> { props ->
val slackTeam = props.search["slackTeam"] ?: ""
val slackChannel = props.search["slackChannel"] ?: ""

SlackConnectPageFrame {
add(
CouplingQuery(
commander = props.commander,
query = graphQuery { partyList() },
toDataprops = { _, dispatch, result ->
build = { _, dispatch, result ->
SlackConnectPageContent(
parties = result.partyList?.map(Record<PartyDetails>::data) ?: emptyList(),
slackTeam = slackTeam,
Expand Down

0 comments on commit c52bd72

Please sign in to comment.