Skip to content

Commit

Permalink
last of the old style of minreact has been converted
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 9, 2023
1 parent 70a5b51 commit f599932
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.zegreatrob.coupling.client.SessionConfig.animationsDisabled
import com.zegreatrob.coupling.client.components.external.auth0.react.Auth0Provider
import com.zegreatrob.coupling.client.components.external.w3c.WindowFunctions.Companion.window
import com.zegreatrob.coupling.client.routing.CouplingRouter
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import js.core.jso
import react.Props
Expand All @@ -27,7 +26,7 @@ val RootComponent by nfc<RootProps> { props ->
skipRedirectCallback = isCallbackFromOtherProvider()
useRefreshTokens = true

add(CouplingRouter(animationsDisabled, config))
CouplingRouter(animationsDisabled, config)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ val IncubatingPage by nfc<PageProps> { props ->
CouplingQuery(
commander = props.commander,
query = graphQuery { addToSlackUrl() },
build = { _, _, result ->
IncubatingContent(
addToSlackUrl = result.addToSlackUrl ?: return@CouplingQuery,
)
},
toNode = { _, _, result -> result.addToSlackUrl?.let(IncubatingContent::create) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ val PartyListPage by nfc<PageProps> { props ->
CouplingQuery(
commander = props.commander,
query = graphQuery { partyList() },
build = { _, _, result -> PartyList(result.partyList?.map(Record<PartyDetails>::data) ?: emptyList()) },
toNode = { _, _, result -> PartyList.create(result.partyList?.map(Record<PartyDetails>::data) ?: emptyList()) },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.zegreatrob.coupling.client.routing
import com.zegreatrob.coupling.client.CommandDispatcher
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.ReactFunc
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
Expand All @@ -18,33 +16,8 @@ import com.zegreatrob.testmints.action.async.execute
import react.ChildrenBuilder
import react.Props
import react.ReactNode
import react.create
import react.useCallback

fun <P : DataProps<P>, R> ChildrenBuilder.CouplingQuery(
query: SuspendAction<CommandDispatcher, R?>,
toDataprops: (ReloadFunc, DispatchFunc<CommandDispatcher>, R) -> P?,
commander: Commander,
) = CouplingQuery(
query = query,
toNode = { r: ReloadFunc, d: DispatchFunc<CommandDispatcher>, result: R ->
toDataprops(r, d, result)?.create()
},
commander = commander,
)

fun <R> ChildrenBuilder.CouplingQuery(
query: SuspendAction<CommandDispatcher, R?>,
build: ChildrenBuilder.(ReloadFunc, DispatchFunc<CommandDispatcher>, R) -> Unit,
commander: Commander,
) = CouplingQuery(
query = query,
toNode = { r: ReloadFunc, d: DispatchFunc<CommandDispatcher>, result: R ->
react.Fragment.create { build(r, d, result) }
},
commander = commander,
)

external interface CouplingQueryProps<R> : Props {
var query: SuspendAction<CommandDispatcher, R?>
var toNode: (ReloadFunc, DispatchFunc<CommandDispatcher>, R) -> ReactNode?
Expand All @@ -53,14 +26,14 @@ external interface CouplingQueryProps<R> : Props {

@ReactFunc
val CouplingQuery by nfc<CouplingQueryProps<Any>> { props ->
val (query, toDataprops, commander) = props
val (query, toNode, commander) = props

val getDataAsync: suspend (DataLoaderTools) -> ReactNode? = useCallback { tools ->
val dispatchFunc = DecoratedDispatchFunc(commander::tracingDispatcher, tools)
commander.tracingDispatcher()
.execute(query)
?.let { value ->
toDataprops(tools.reloadData, dispatchFunc, value)
toNode(tools.reloadData, dispatchFunc, value)
}
}
add(
Expand All @@ -70,7 +43,7 @@ val CouplingQuery by nfc<CouplingQueryProps<Any>> { props ->
)
}

private fun <P : DataProps<P>> ChildrenBuilder.animationFrame(state: DataLoadState<ReactNode?>) =
private fun ChildrenBuilder.animationFrame(state: DataLoadState<ReactNode?>) =
animationFrame {
this.state = state
if (state is ResolvedState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import com.zegreatrob.coupling.client.stats.StatisticsPage
import com.zegreatrob.coupling.client.user.Logout
import com.zegreatrob.coupling.client.user.UserPage
import com.zegreatrob.coupling.client.welcome.WelcomePage
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.nfc
import js.core.jso
import react.Props
import react.create
import react.router.Navigate
import react.router.RouteObject
Expand All @@ -37,10 +38,13 @@ import react.router.dom.createBrowserRouter
import react.router.useParams
import react.useMemo

data class CouplingRouter(val animationsDisabled: Boolean, val config: ClientConfig) :
DataPropsBind<CouplingRouter>(couplingRouter)
external interface CouplingRouterProps : Props {
var animationsDisabled: Boolean
var config: ClientConfig
}

val couplingRouter by ntmFC<CouplingRouter> { (animationsDisabled, config) ->
@ReactFunc
val CouplingRouter by nfc<CouplingRouterProps> { (animationsDisabled, config) ->
val (_, isSignedIn, isLoading) = useAuth0Data()
val browserRouter = useMemo(isSignedIn, config) {
createBrowserRouter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zegreatrob.coupling.client.slack

import com.zegreatrob.coupling.client.components.slack.SlackConnectPageContent
import com.zegreatrob.coupling.client.components.slack.create
import com.zegreatrob.coupling.client.routing.CouplingQuery
import com.zegreatrob.coupling.client.routing.PageProps
import com.zegreatrob.coupling.model.Record
Expand All @@ -15,8 +16,8 @@ val SlackConnectPage by nfc<PageProps> { props ->
CouplingQuery(
commander = props.commander,
query = graphQuery { partyList() },
build = { _, dispatch, result ->
SlackConnectPageContent(
toNode = { _, dispatch, result ->
SlackConnectPageContent.create(
parties = result.partyList?.map(Record<PartyDetails>::data) ?: emptyList(),
slackTeam = slackTeam,
slackChannel = slackChannel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import com.zegreatrob.coupling.client.components.PageFrame
import com.zegreatrob.coupling.client.components.party.GeneralControlBar
import com.zegreatrob.coupling.client.party.AboutButton
import com.zegreatrob.coupling.model.user.User
import com.zegreatrob.minreact.DataProps
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.nfc
import react.Props
import react.dom.html.ReactHTML.div
import web.cssom.Color

data class UserConfig(val user: User?) : DataProps<UserConfig> {
override val component = userConfig
external interface UserConfigProps : Props {
var user: User?
}

private val userConfig by ntmFC<UserConfig> { (user) ->
@ReactFunc
val UserConfig by nfc<UserConfigProps> { (user) ->
PageFrame(
borderColor = Color("rgb(94, 84, 102)"),
backgroundColor = Color("floralwhite"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ val UserPage by nfc<PageProps> {
CouplingQuery(
commander = it.commander,
query = graphQuery { user() },
toDataprops = { _, _, result -> UserConfig(result.user) },
toNode = { _, _, result -> UserConfig.create(result.user) },
)
}

0 comments on commit f599932

Please sign in to comment.