Skip to content

Commit

Permalink
converting the coupling query element
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 9, 2023
1 parent 778205e commit 70a5b51
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PageProps> { 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,
)
},
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -15,12 +18,13 @@ val IntegrationPage = partyPageFunction { props, partyId ->
}
addToSlackUrl()
},
build = { _, _, result ->
IntegrationContent(
party = result.party?.details?.data ?: return@CouplingQuery,
toNode = { _: ReloadFunc, _: DispatchFunc<CommandDispatcher>, 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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ 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) {
party()
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<PartyDetails, List<PairAssignmentDocument>>
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
)
}
Original file line number Diff line number Diff line change
@@ -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<PageProps> { 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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,9 +8,9 @@ import com.zegreatrob.coupling.sdk.gql.graphQuery
import com.zegreatrob.minreact.nfc

val PartyListPage by nfc<PageProps> { props ->
+CouplingQuery(
CouplingQuery(
commander = props.commander,
query = graphQuery { partyList() },
build = { _, _, result -> PartyList(result.partyList?.map(Record<PartyDetails>::data) ?: emptyList()) },
).create()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ 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) {
party()
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,
)
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
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) {
party()
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,
)
}
Original file line number Diff line number Diff line change
@@ -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}",
)
}
Loading

0 comments on commit 70a5b51

Please sign in to comment.