From 70a5b51aae43261f2839f5415f36c92907be782d Mon Sep 17 00:00:00 2001 From: Rob Murdock Date: Sun, 9 Jul 2023 14:57:59 -0400 Subject: [PATCH] converting the coupling query element --- .../coupling/client/incubating/Incubating.kt | 19 ++++----- .../client/integration/IntegrationPage.kt | 18 ++++---- .../pairassignments/CurrentPairsPage.kt | 14 +++---- .../pairassignments/NewPairAssignmentsPage.kt | 14 +++---- .../pairassignments/list/HistoryPage.kt | 12 +++--- .../pairassignments/spin/PrepareSpinPage.kt | 17 ++++---- .../coupling/client/party/PartyConfigPage.kt | 42 ++++++++++--------- .../coupling/client/party/PartyListPage.kt | 5 +-- .../coupling/client/pin/PinListPage.kt | 14 +++---- .../zegreatrob/coupling/client/pin/PinPage.kt | 15 +++---- .../coupling/client/player/PlayerPage.kt | 11 ++--- .../player/retired/RetiredPlayerPage.kt | 15 +++---- .../player/retired/RetiredPlayersPage.kt | 14 +++---- .../client/routing/CouplingDataLoadWrapper.kt | 25 +++++------ .../coupling/client/slack/SlackConnectPage.kt | 25 +++++------ .../coupling/client/stats/StatisticsPage.kt | 9 ++-- .../coupling/client/user/UserPage.kt | 11 ++--- 17 files changed, 141 insertions(+), 139 deletions(-) diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/incubating/Incubating.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/incubating/Incubating.kt index 97cd20a50d..e50cfd1099 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/incubating/Incubating.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/incubating/Incubating.kt @@ -5,23 +5,20 @@ import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.client.routing.PageProps import com.zegreatrob.coupling.sdk.gql.graphQuery import com.zegreatrob.minreact.ReactFunc -import com.zegreatrob.minreact.add import com.zegreatrob.minreact.nfc import react.Props import react.dom.html.ReactHTML.div import web.cssom.Color val IncubatingPage by nfc { props -> - add( - CouplingQuery( - commander = props.commander, - query = graphQuery { addToSlackUrl() }, - build = { _, _, result -> - IncubatingContent( - addToSlackUrl = result.addToSlackUrl ?: return@CouplingQuery, - ) - }, - ), + CouplingQuery( + commander = props.commander, + query = graphQuery { addToSlackUrl() }, + build = { _, _, result -> + IncubatingContent( + addToSlackUrl = result.addToSlackUrl ?: return@CouplingQuery, + ) + }, ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/integration/IntegrationPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/integration/IntegrationPage.kt index 3febce847b..606ca0dbb0 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/integration/IntegrationPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/integration/IntegrationPage.kt @@ -1,12 +1,15 @@ package com.zegreatrob.coupling.client.integration +import com.zegreatrob.coupling.client.CommandDispatcher +import com.zegreatrob.coupling.client.components.DispatchFunc import com.zegreatrob.coupling.client.partyPageFunction import com.zegreatrob.coupling.client.routing.CouplingQuery +import com.zegreatrob.coupling.model.CouplingQueryResult import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create +import com.zegreatrob.react.dataloader.ReloadFunc val IntegrationPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -15,12 +18,13 @@ val IntegrationPage = partyPageFunction { props, partyId -> } addToSlackUrl() }, - build = { _, _, result -> - IntegrationContent( - party = result.party?.details?.data ?: return@CouplingQuery, + toNode = { _: ReloadFunc, _: DispatchFunc, result: CouplingQueryResult -> + IntegrationContent.create( + party = result.party?.details?.data ?: return@CouplingQuery null, integration = result.party?.integration?.data, - addToSlackUrl = result.addToSlackUrl ?: return@CouplingQuery, + addToSlackUrl = result.addToSlackUrl ?: return@CouplingQuery null, ) }, - ).create(key = partyId.value) + key = partyId.value, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/CurrentPairsPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/CurrentPairsPage.kt index 4b5a4e0f70..2aacbb7b3e 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/CurrentPairsPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/CurrentPairsPage.kt @@ -6,10 +6,9 @@ import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.model.element import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create val CurrentPairsPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -18,14 +17,15 @@ val CurrentPairsPage = partyPageFunction { props, partyId -> currentPairAssignments() } }, - build = { reload, dispatchFunc, result -> - SocketedPairAssignments( - party = result.party?.details?.data ?: return@CouplingQuery, - players = result.party?.playerList?.elements ?: return@CouplingQuery, + toNode = { reload, dispatchFunc, result -> + SocketedPairAssignments.create( + party = result.party?.details?.data ?: return@CouplingQuery null, + players = result.party?.playerList?.elements ?: return@CouplingQuery null, pairAssignments = result.party?.currentPairAssignmentDocument?.element, controls = Controls(dispatchFunc, reload), allowSave = false, ) }, - ).create(key = partyId.value) + key = partyId.value, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/NewPairAssignmentsPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/NewPairAssignmentsPage.kt index 4d50fa1777..ab27287619 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/NewPairAssignmentsPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/NewPairAssignmentsPage.kt @@ -6,10 +6,9 @@ import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.model.element import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create val NewPairAssignmentsPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -18,14 +17,15 @@ val NewPairAssignmentsPage = partyPageFunction { props, partyId -> currentPairAssignments() } }, - build = { reload, dispatchFunc, result -> - SocketedPairAssignments( - party = result.party?.details?.data ?: return@CouplingQuery, - players = result.party?.playerList?.elements ?: return@CouplingQuery, + toNode = { reload, dispatchFunc, result -> + SocketedPairAssignments.create( + party = result.party?.details?.data ?: return@CouplingQuery null, + players = result.party?.playerList?.elements ?: return@CouplingQuery null, pairAssignments = result.party?.currentPairAssignmentDocument?.element, controls = Controls(dispatchFunc, reload), allowSave = true, ) }, - ).create(key = partyId.value) + key = partyId.value, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/list/HistoryPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/list/HistoryPage.kt index 431b011a98..28e3a23dde 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/list/HistoryPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/list/HistoryPage.kt @@ -8,10 +8,9 @@ import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument import com.zegreatrob.coupling.model.party.PartyDetails import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create val HistoryPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -19,12 +18,13 @@ val HistoryPage = partyPageFunction { props, partyId -> pairAssignmentDocumentList() } }, - build = { reload, commandFunc, result -> + toNode = { reload, commandFunc, result -> val (party, history) = result.toHistoryData() - ?: return@CouplingQuery - History(party, history, Controls(commandFunc, reload)) + ?: return@CouplingQuery null + History.create(party, history, Controls(commandFunc, reload)) }, - ).create(key = partyId.value) + key = partyId.value, + ) } typealias HistoryData = Pair> diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt index 60e4ace5be..7b8362b476 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/spin/PrepareSpinPage.kt @@ -1,15 +1,15 @@ package com.zegreatrob.coupling.client.pairassignments.spin import com.zegreatrob.coupling.client.components.spin.PrepareSpin +import com.zegreatrob.coupling.client.components.spin.create import com.zegreatrob.coupling.client.partyPageFunction import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.model.element import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create val PrepareSpinPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -19,14 +19,15 @@ val PrepareSpinPage = partyPageFunction { props, partyId -> pinList() } }, - build = { _, dispatcher, result -> - PrepareSpin( - party = result.party?.details?.data ?: return@CouplingQuery, - players = result.party?.playerList?.elements ?: return@CouplingQuery, - pins = result.party?.pinList?.elements ?: return@CouplingQuery, + toNode = { _, dispatcher, result -> + PrepareSpin.create( + party = result.party?.details?.data ?: return@CouplingQuery null, + players = result.party?.playerList?.elements ?: return@CouplingQuery null, + pins = result.party?.pinList?.elements ?: return@CouplingQuery null, currentPairsDoc = result.party?.currentPairAssignmentDocument?.element, dispatchFunc = dispatcher, ) }, - ).create(key = partyId.value) + key = partyId.value, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyConfigPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyConfigPage.kt index 7ab56f0da0..6c813f849c 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyConfigPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyConfigPage.kt @@ -1,31 +1,33 @@ package com.zegreatrob.coupling.client.party import com.zegreatrob.coupling.client.components.party.PartyConfig +import com.zegreatrob.coupling.client.components.party.create import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.client.routing.PageProps import com.zegreatrob.coupling.client.routing.partyId -import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.add import com.zegreatrob.minreact.nfc val PartyConfigPage by nfc { props -> - add((props.partyId?.partyQueryProps(props) ?: newPartyProps(props)), key = props.partyId?.value) -} - -private fun PartyId.partyQueryProps(pageProps: PageProps) = CouplingQuery( - commander = pageProps.commander, - query = graphQuery { party(this@partyQueryProps) { party() } }, - build = { _, commandFunc, result -> - PartyConfig( - party = result.party?.details?.data ?: return@CouplingQuery, - dispatchFunc = commandFunc, + val partyId = props.partyId + if (partyId != null) { + CouplingQuery( + commander = props.commander, + query = graphQuery { party(partyId) { party() } }, + toNode = { _, commandFunc, result -> + PartyConfig.create( + party = result.party?.details?.data ?: return@CouplingQuery null, + dispatchFunc = commandFunc, + ) + }, + key = props.partyId?.value, ) - }, -) - -private fun newPartyProps(pageProps: PageProps) = CouplingQuery( - commander = pageProps.commander, - query = NewPartyCommand(), - build = { _, commandFunc, data -> PartyConfig(data, commandFunc) }, -) + } else { + CouplingQuery( + commander = props.commander, + query = NewPartyCommand(), + toNode = { _, commandFunc, data -> PartyConfig.create(data, commandFunc) }, + key = props.partyId?.value, + ) + } +} diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyListPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyListPage.kt index 4147473006..e8d287e5bc 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyListPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/party/PartyListPage.kt @@ -1,6 +1,5 @@ package com.zegreatrob.coupling.client.party -import com.zegreatrob.coupling.client.create import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.client.routing.PageProps import com.zegreatrob.coupling.model.Record @@ -9,9 +8,9 @@ import com.zegreatrob.coupling.sdk.gql.graphQuery import com.zegreatrob.minreact.nfc val PartyListPage by nfc { props -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { partyList() }, build = { _, _, result -> PartyList(result.partyList?.map(Record::data) ?: emptyList()) }, - ).create() + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinListPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinListPage.kt index 2d8b5d332d..bae3654b64 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinListPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinListPage.kt @@ -4,10 +4,9 @@ import com.zegreatrob.coupling.client.partyPageFunction import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create val PinListPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -15,11 +14,12 @@ val PinListPage = partyPageFunction { props, partyId -> pinList() } }, - build = { _, _, result -> - PinList( - party = result.party?.details?.data ?: return@CouplingQuery, - pins = result.party?.pinList?.elements ?: return@CouplingQuery, + toNode = { _, _, result -> + PinList.create( + party = result.party?.details?.data ?: return@CouplingQuery null, + pins = result.party?.pinList?.elements ?: return@CouplingQuery null, ) }, - ).create(key = partyId.value) + key = partyId.value, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinPage.kt index 857d21fea1..3c653954df 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pin/PinPage.kt @@ -1,17 +1,17 @@ package com.zegreatrob.coupling.client.pin import com.zegreatrob.coupling.client.components.pin.PinConfig +import com.zegreatrob.coupling.client.components.pin.create import com.zegreatrob.coupling.client.partyPageFunction import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.client.routing.pinId import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.model.pin.Pin import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create val PinPage = partyPageFunction { props, partyId -> val pinId = props.pinId - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -19,15 +19,16 @@ val PinPage = partyPageFunction { props, partyId -> pinList() } }, - build = { reload, commandFunc, result -> - val pinList = result.party?.pinList?.elements ?: return@CouplingQuery - PinConfig( - party = result.party?.details?.data ?: return@CouplingQuery, + toNode = { reload, commandFunc, result -> + val pinList = result.party?.pinList?.elements ?: return@CouplingQuery null + PinConfig.create( + party = result.party?.details?.data ?: return@CouplingQuery null, pinList = pinList, pin = pinList.firstOrNull { it.id == pinId } ?: Pin(), reload = reload, dispatchFunc = commandFunc, ) }, - ).create(key = pinId) + key = pinId, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/PlayerPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/PlayerPage.kt index a7c4e680e8..df29710865 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/PlayerPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/PlayerPage.kt @@ -1,20 +1,21 @@ package com.zegreatrob.coupling.client.player import com.zegreatrob.coupling.client.components.player.PlayerConfig +import com.zegreatrob.coupling.client.components.player.create import com.zegreatrob.coupling.client.partyPageFunction import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.client.routing.PageProps import com.zegreatrob.coupling.client.routing.playerId import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.sdk.PartyPlayerQuery -import com.zegreatrob.minreact.create val PlayerPage = partyPageFunction { props: PageProps, partyId: PartyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = PartyPlayerQuery(partyId, props.playerId), - build = { reload, commandFunc, (party, players, player) -> - PlayerConfig(party, player, players, reload, commandFunc) + toNode = { reload, commandFunc, (party, players, player) -> + PlayerConfig.create(party, player, players, reload, commandFunc) }, - ).create(key = "${partyId.value}-${props.playerId}") + key = "${partyId.value}-${props.playerId}", + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayerPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayerPage.kt index 491275c39b..286390f728 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayerPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayerPage.kt @@ -1,6 +1,7 @@ package com.zegreatrob.coupling.client.player.retired import com.zegreatrob.coupling.client.components.player.PlayerConfig +import com.zegreatrob.coupling.client.components.player.create import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.client.routing.PageProps import com.zegreatrob.coupling.client.routing.partyId @@ -8,7 +9,6 @@ import com.zegreatrob.coupling.client.routing.playerId import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create import com.zegreatrob.minreact.nfc import react.ChildrenBuilder import react.dom.html.ReactHTML.div @@ -25,7 +25,7 @@ val RetiredPlayerPage by nfc { props -> } private fun ChildrenBuilder.loadedRetiredPlayer(props: PageProps, partyId: PartyId, playerId: String) = - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -33,14 +33,15 @@ private fun ChildrenBuilder.loadedRetiredPlayer(props: PageProps, partyId: Party retiredPlayers() } }, - build = { reload, commandFunc, result -> - val players = result.party?.retiredPlayers?.elements ?: return@CouplingQuery - PlayerConfig( - party = result.party?.details?.data ?: return@CouplingQuery, + toNode = { reload, commandFunc, result -> + val players = result.party?.retiredPlayers?.elements ?: return@CouplingQuery null + PlayerConfig.create( + party = result.party?.details?.data ?: return@CouplingQuery null, player = players.first { it.id == playerId }, players = players, reload = reload, dispatchFunc = commandFunc, ) }, - ).create(key = playerId) + key = playerId, + ) diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayersPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayersPage.kt index f0f916561e..2d6f8459b2 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayersPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/player/retired/RetiredPlayersPage.kt @@ -4,10 +4,9 @@ import com.zegreatrob.coupling.client.partyPageFunction import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.create val RetiredPlayersPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = graphQuery { party(partyId) { @@ -15,11 +14,12 @@ val RetiredPlayersPage = partyPageFunction { props, partyId -> retiredPlayers() } }, - build = { _, _, result -> - RetiredPlayers( - party = result.party?.details?.data ?: return@CouplingQuery, - retiredPlayers = result.party?.retiredPlayers?.elements ?: return@CouplingQuery, + toNode = { _, _, result -> + RetiredPlayers.create( + party = result.party?.details?.data ?: return@CouplingQuery null, + retiredPlayers = result.party?.retiredPlayers?.elements ?: return@CouplingQuery null, ) }, - ).create(key = partyId.value) + key = partyId.value, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt index 01b6295ea1..9ff6586c05 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/routing/CouplingDataLoadWrapper.kt @@ -5,10 +5,9 @@ import com.zegreatrob.coupling.client.DecoratedDispatchFunc import com.zegreatrob.coupling.client.components.DispatchFunc import com.zegreatrob.coupling.client.create import com.zegreatrob.minreact.DataProps -import com.zegreatrob.minreact.DataPropsBind -import com.zegreatrob.minreact.TMFC +import com.zegreatrob.minreact.ReactFunc import com.zegreatrob.minreact.add -import com.zegreatrob.minreact.ntmFC +import com.zegreatrob.minreact.nfc import com.zegreatrob.react.dataloader.DataLoadState import com.zegreatrob.react.dataloader.DataLoader import com.zegreatrob.react.dataloader.DataLoaderTools @@ -17,17 +16,12 @@ import com.zegreatrob.react.dataloader.ResolvedState import com.zegreatrob.testmints.action.async.SuspendAction import com.zegreatrob.testmints.action.async.execute import react.ChildrenBuilder +import react.Props import react.ReactNode import react.create import react.useCallback -data class CouplingQuery( - val query: SuspendAction, - val toNode: (ReloadFunc, DispatchFunc, R) -> ReactNode?, - val commander: Commander, -) : DataPropsBind>(couplingQuery.unsafeCast()) - -fun

, R> CouplingQuery( +fun

, R> ChildrenBuilder.CouplingQuery( query: SuspendAction, toDataprops: (ReloadFunc, DispatchFunc, R) -> P?, commander: Commander, @@ -39,7 +33,7 @@ fun

, R> CouplingQuery( commander = commander, ) -fun CouplingQuery( +fun ChildrenBuilder.CouplingQuery( query: SuspendAction, build: ChildrenBuilder.(ReloadFunc, DispatchFunc, R) -> Unit, commander: Commander, @@ -51,7 +45,14 @@ fun CouplingQuery( commander = commander, ) -private val couplingQuery by ntmFC { props: CouplingQuery -> +external interface CouplingQueryProps : Props { + var query: SuspendAction + var toNode: (ReloadFunc, DispatchFunc, R) -> ReactNode? + var commander: Commander +} + +@ReactFunc +val CouplingQuery by nfc> { props -> val (query, toDataprops, commander) = props val getDataAsync: suspend (DataLoaderTools) -> ReactNode? = useCallback { tools -> diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt index 09ba04b26f..df0b457d7a 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/slack/SlackConnectPage.kt @@ -6,26 +6,23 @@ import com.zegreatrob.coupling.client.routing.PageProps import com.zegreatrob.coupling.model.Record import com.zegreatrob.coupling.model.party.PartyDetails import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.add 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() }, - build = { _, dispatch, result -> - SlackConnectPageContent( - parties = result.partyList?.map(Record::data) ?: emptyList(), - slackTeam = slackTeam, - slackChannel = slackChannel, - dispatchFunc = dispatch, - ) - }, - ), + CouplingQuery( + commander = props.commander, + query = graphQuery { partyList() }, + build = { _, dispatch, result -> + SlackConnectPageContent( + parties = result.partyList?.map(Record::data) ?: emptyList(), + slackTeam = slackTeam, + slackChannel = slackChannel, + dispatchFunc = dispatch, + ) + }, ) } } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/stats/StatisticsPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/stats/StatisticsPage.kt index 9d03e991b1..18f595b0e0 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/stats/StatisticsPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/stats/StatisticsPage.kt @@ -2,14 +2,15 @@ package com.zegreatrob.coupling.client.stats import com.zegreatrob.coupling.action.stats.StatisticsQuery import com.zegreatrob.coupling.client.components.stats.PartyStatistics +import com.zegreatrob.coupling.client.components.stats.create import com.zegreatrob.coupling.client.partyPageFunction import com.zegreatrob.coupling.client.routing.CouplingQuery -import com.zegreatrob.minreact.create val StatisticsPage = partyPageFunction { props, partyId -> - +CouplingQuery( + CouplingQuery( commander = props.commander, query = StatisticsQuery(partyId), - build = { _, _, queryResult -> PartyStatistics(queryResult) }, - ).create(key = partyId.value) + toNode = { _, _, queryResult -> PartyStatistics.create(queryResult) }, + key = partyId.value, + ) } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/user/UserPage.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/user/UserPage.kt index 4ae1036d43..d4497dc6a5 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/user/UserPage.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/user/UserPage.kt @@ -3,15 +3,12 @@ package com.zegreatrob.coupling.client.user import com.zegreatrob.coupling.client.routing.CouplingQuery import com.zegreatrob.coupling.client.routing.PageProps import com.zegreatrob.coupling.sdk.gql.graphQuery -import com.zegreatrob.minreact.add import com.zegreatrob.minreact.nfc val UserPage by nfc { - add( - CouplingQuery( - commander = it.commander, - query = graphQuery { user() }, - toDataprops = { _, _, result -> UserConfig(result.user) }, - ), + CouplingQuery( + commander = it.commander, + query = graphQuery { user() }, + toDataprops = { _, _, result -> UserConfig(result.user) }, ) }