From c52bd7213ddd9bfcd358d358c23db9bde4fb29cf Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Wed, 5 Jul 2023 15:35:03 -0400 Subject: [PATCH] more conversion --- .../slack/SlackConnectPageContent.kt | 21 +++++---- .../client/components/spin/PrepareSpin.kt | 41 +++++++++--------- .../components/spin/PrepareSpinContent.kt | 26 +++++------ .../client/components/PrepareSpinTest.kt | 43 ++++++++----------- .../slack/SlackConnectPageContentTest.kt | 29 +++++++------ .../coupling/client/demo/DemoPageFrame.kt | 3 +- .../pairassignments/spin/PrepareSpinPage.kt | 8 ++-- .../client/routing/CouplingDataLoadWrapper.kt | 2 +- .../coupling/client/slack/SlackConnectPage.kt | 3 +- 9 files changed, 85 insertions(+), 91 deletions(-) diff --git a/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt b/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt index e35bf88610..d9d5394d8f 100644 --- a/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt +++ b/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt @@ -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 @@ -31,16 +31,15 @@ import react.router.dom.LinkProps import react.useMemo import react.useState -data class SlackConnectPageContent( - val parties: List, - val slackTeam: String, - val slackChannel: String, - val dispatchFunc: DispatchFunc, -) : DataPropsBind( - slackConnectPageContent, -) +external interface SlackConnectPageContentProps : Props { + var parties: List + var slackTeam: String + var slackChannel: String + var dispatchFunc: DispatchFunc +} -val slackConnectPageContent by ntmFC { props -> +@ReactFunc +val SlackConnectPageContent by nfc { props -> val partySelectId = useMemo { "${uuid4()}" } var command by useState { diff --git a/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt b/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt index eff77adb81..d42c2db20f 100644 --- a/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt +++ b/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt @@ -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, - val currentPairsDoc: PairAssignmentDocument?, - val pins: List, - val dispatchFunc: DispatchFunc, -) : DataPropsBind(prepareSpin) +external interface PrepareSpinProps : Props { + var party: PartyDetails + var players: List + var currentPairsDoc: PairAssignmentDocument? + var pins: List + var dispatchFunc: DispatchFunc +} -val prepareSpin by ntmFC { (party, players, currentPairsDoc, pins, dispatchFunc) -> +@ReactFunc +val PrepareSpin by nfc { (party, players, currentPairsDoc, pins, dispatchFunc) -> var playerSelections by useState(defaultSelections(players, currentPairsDoc)) var pinSelections by useState(pins.map { it.id }) var redirectUrl by useState(null) @@ -33,16 +34,14 @@ val prepareSpin by ntmFC { (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, ) } } diff --git a/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpinContent.kt b/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpinContent.kt index 4eed67c0bb..e99aadfc2d 100644 --- a/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpinContent.kt +++ b/client/components/src/main/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpinContent.kt @@ -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 @@ -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>, - var pins: List, - var pinSelections: List, - var setPlayerSelections: (value: List>) -> Unit, - var setPinSelections: (List) -> Unit, - var onSpin: () -> Unit, -) : DataPropsBind(prepareSpinContent) +external interface PrepareSpinContentProps : Props { + var party: PartyDetails + var playerSelections: List> + var pins: List + var pinSelections: List + var setPlayerSelections: (value: List>) -> Unit + var setPinSelections: (List) -> Unit + var onSpin: () -> Unit +} -val prepareSpinContent by ntmFC { props -> +@ReactFunc +val PrepareSpinContent by nfc { props -> val (party, playerSelections, pins, pinSelections, setPlayerSelections, setPinSelections, onSpin) = props val enabled = playerSelections.any { it.second } diff --git a/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt b/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt index dd3c8477af..c64e64a98e 100644 --- a/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt +++ b/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt @@ -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 @@ -53,10 +52,9 @@ class PrepareSpinTest { val players = emptyList() 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") @@ -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") @@ -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() @@ -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() @@ -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 { @@ -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!")) diff --git a/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt b/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt index 07e6e715c5..4e305bb042 100644 --- a/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt +++ b/client/components/src/test/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt @@ -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 @@ -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 @@ -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") @@ -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") @@ -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/" diff --git a/client/src/main/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt b/client/src/main/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt index 094f8e9bab..0f2d2d0d0f 100644 --- a/client/src/main/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt +++ b/client/src/main/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt @@ -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 @@ -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( diff --git a/client/src/main/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt b/client/src/main/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt index 9ee33145c0..60e4ace5be 100644 --- a/client/src/main/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt +++ b/client/src/main/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt @@ -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, ) diff --git a/client/src/main/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt b/client/src/main/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt index 7e43b14fb9..01b6295ea1 100644 --- a/client/src/main/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt +++ b/client/src/main/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt @@ -43,7 +43,7 @@ fun CouplingQuery( query: SuspendAction, build: ChildrenBuilder.(ReloadFunc, DispatchFunc, R) -> Unit, commander: Commander, -) = CouplingQuery( +) = CouplingQuery( query = query, toNode = { r: ReloadFunc, d: DispatchFunc, result: R -> react.Fragment.create { build(r, d, result) } diff --git a/client/src/main/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt b/client/src/main/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt index ad4c2126f3..09ba04b26f 100644 --- a/client/src/main/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt +++ b/client/src/main/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt @@ -12,13 +12,12 @@ import com.zegreatrob.minreact.nfc val SlackConnectPage by nfc { 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::data) ?: emptyList(), slackTeam = slackTeam,