Skip to content

Commit

Permalink
fixed it: apparently an anonymous class caused the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 8, 2023
1 parent 7e1ccd0 commit f8cfd7c
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ val DemoPage by nfc<PageProps> { props ->
val frameIndex = props.search["frame"]
val currentFrame = frameIndex?.toIntOrNull()?.let { demoSequence.toList()[it] }
if (currentFrame != null) {
// add(DemoPageFrame(currentFrame.data))
DemoPageFrame(currentFrame.data)
} else {
add(
FrameRunner(demoSequence, 1.0) { // state: DemoAnimationState ->
// add(DemoPageFrame(state))
FrameRunner(demoSequence, 1.0) { state: DemoAnimationState ->
DemoPageFrame(state)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.zegreatrob.coupling.client.demo

import com.zegreatrob.coupling.action.pairassignmentdocument.DeletePairAssignmentsCommand
import com.zegreatrob.coupling.action.pairassignmentdocument.SpinCommand
import com.zegreatrob.coupling.client.aboutPageContent
import com.zegreatrob.coupling.client.components.Controls
import com.zegreatrob.coupling.client.components.DispatchFunc
import com.zegreatrob.coupling.client.components.external.reactmarkdown.Markdown
import com.zegreatrob.coupling.client.components.pairassignments.PairAssignments
import com.zegreatrob.coupling.client.components.party.PartyConfigContent
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.add
import com.zegreatrob.minreact.nfc
import com.zegreatrob.testmints.action.async.SuspendAction
import emotion.react.css
import js.core.jso
import kotlinx.browser.document
import popper.core.ReferenceElement
import popper.core.modifier
import popper.core.modifiers.Arrow
import popper.core.modifiers.Offset
import react.ChildrenBuilder
import react.MutableRefObject
import react.Props
import react.dom.html.ReactHTML.div
import react.popper.UsePopperOptions
import react.popper.usePopper
import react.useLayoutEffect
import react.useRef
import react.useState
import web.cssom.Auto
import web.cssom.Color
import web.cssom.None
import web.cssom.Position
import web.cssom.vw
import web.html.HTMLElement

external interface DemoPageFrameProps : Props {
var state: DemoAnimationState
}

val DemoPageFrame by nfc<DemoPageFrameProps> { (state) ->
val popperRef = useRef<HTMLElement>()
val arrowRef = useRef<HTMLElement>()

val (referenceElement, setReferenceElement) = useState<ReferenceElement?>(null)

val popperInstance = usePopper(referenceElement, popperRef.current, popperOptions(arrowRef, state))

useLayoutEffect(state) {
val className = state.descriptionSelector
val element: ReferenceElement? = if (className.isNotBlank()) {
document.querySelector(className).unsafeCast<ReferenceElement>()
} else {
null
}
setReferenceElement(element)
popperInstance.forceUpdate?.invoke()
}

div {
popperDiv(popperRef, arrowRef, state, popperInstance)
div {
css {
position = Position.absolute
backgroundColor = Color("#e3002b61")
width = 100.vw
marginLeft = Auto.auto
marginRight = Auto.auto
}
+"-- DEMO MODE -- ALL BUTTONS WILL NOT WORK -- DON'T GET IT TWISTED --"
}

div {
css { pointerEvents = None.none }
when (state) {
is Start -> aboutPageContent { Markdown { +state.text } }
is ShowIntro -> aboutPageContent { Markdown { +state.text } }
is MakeParty -> partyConfigFrame(state)
is AddPlayer -> playerConfigFrame(state)
is AddPin -> pinConfigFrame(state)
is CurrentPairs -> pairAssignmentsFrame(state)
is PrepareToSpin -> prepareSpinFrame(state)
}
}
}
}

private fun popperOptions(arrowRef: MutableRefObject<HTMLElement>, state: DemoAnimationState): UsePopperOptions = jso {
this.placement = state.placement
this.modifiers = arrayOf(
Arrow.modifier {
this.options = jso {
this.element = arrowRef.current
}
},
Offset.modifier {
this.options = jso { offset = Offset(0.0, 10.0) }
},
)
}

private fun ChildrenBuilder.partyConfigFrame(state: MakeParty) {
PartyConfigContent(state.party, true, {}, {}, {})
}

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

private fun ChildrenBuilder.playerConfigFrame(state: AddPlayer) = add(
PlayerConfigContent(state.party, state.newPlayer, state.players, {}, {}, {}),
)

private fun ChildrenBuilder.pinConfigFrame(state: AddPin) =
PinConfigContent(state.party, state.newPin, state.pins, {}, {}, {})

private fun ChildrenBuilder.pairAssignmentsFrame(state: CurrentPairs) = add(
PairAssignments(
state.party,
state.players,
state.pairAssignments,
{ },
Controls(noOpDispatchFunc) {},
CouplingSocketMessage("", emptySet()),
state.allowSave,
),
)

private val noOpDispatchFunc = NoOpDispatcherDispatchFunc()

class NoOpDispatcherDispatchFunc : DispatchFunc<NoOpDispatcher> {
override fun <C : SuspendAction<NoOpDispatcher, R>, R> invoke(
commandFunc: () -> C,
response: (R) -> Unit,
): () -> Unit = {}
}

interface NoOpDispatcher :
DeletePairAssignmentsCommand.Dispatcher,
SpinCommand.Dispatcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.zegreatrob.coupling.client.demo

import com.zegreatrob.coupling.client.components.external.reactmarkdown.Markdown
import emotion.react.css
import popper.core.Popper
import popper.core.modifiers.Arrow
import react.ChildrenBuilder
import react.MutableRefObject
import react.dom.html.ReactHTML.div
import react.popper.PopperInstance
import web.cssom.Color
import web.cssom.Display
import web.cssom.FontWeight
import web.cssom.Globals
import web.cssom.NamedColor
import web.cssom.None
import web.cssom.Padding
import web.cssom.Position
import web.cssom.Visibility
import web.cssom.deg
import web.cssom.integer
import web.cssom.px
import web.cssom.rotate
import web.cssom.string
import web.html.HTMLElement
import kotlin.js.Json

fun ChildrenBuilder.popperDiv(
popperRef: MutableRefObject<HTMLElement>,
arrowRef: MutableRefObject<HTMLElement>,
state: DemoAnimationState,
popperInstance: PopperInstance,
) = div {
css {
if (state.description.isBlank()) display = None.none
}
div {
css {
background = Color("#333333eb")
color = NamedColor.white
fontWeight = FontWeight.bold
padding = Padding(4.px, 8.px)
fontSize = 24.px
borderRadius = 20.px
width = 400.px
zIndex = integer(200)
display = Display.inlineBlock

"h2" {
fontSize = 30.px
}
}
ref = popperRef
style = popperInstance.styles[Popper]

+popperInstance.attributes[Popper]
Markdown { +state.description }
if (state.showReturnButton) {
returnToCouplingButton()
}
div {
css {
visibility = Visibility.hidden
position = Position.absolute
width = 8.px
height = 8.px
background = Globals.inherit
when (
popperInstance.attributes[Popper]
?.unsafeCast<Json>()
?.get("data-popper-placement")
) {
"top" -> bottom = (-4).px
"bottom", "bottom-start" -> top = (-4).px
"left" -> right = (-4).px
"right" -> left = (-4).px
}
before {
position = Position.absolute
width = 8.px
height = 8.px
background = Globals.inherit
visibility = Visibility.visible
content = string("''")
transform = rotate(45.deg)
top = 0.px
left = 0.px
}
}
ref = arrowRef
style = popperInstance.styles[Arrow]
+popperInstance.attributes[Arrow]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.zegreatrob.coupling.client.AboutPage
import com.zegreatrob.coupling.client.ClientConfig
import com.zegreatrob.coupling.client.components.animationsDisabledContext
import com.zegreatrob.coupling.client.components.external.auth0.react.useAuth0Data
import com.zegreatrob.coupling.client.demo.DemoPage
import com.zegreatrob.coupling.client.demo.LoadingPage
import com.zegreatrob.coupling.client.graphql.GraphIQLPage
import com.zegreatrob.coupling.client.incubating.IncubatingPage
Expand Down Expand Up @@ -46,7 +47,7 @@ val couplingRouter by ntmFC<CouplingRouter> { (animationsDisabled, config) ->
routes = arrayOf(
couplingRoute("/welcome/", "Welcome", WelcomePage),
couplingRoute("/about", "About", AboutPage),
// couplingRoute("/demo", "Demo", DemoPage),
couplingRoute("/demo", "Demo", DemoPage),
couplingRoute("/loading", "Loading Test", LoadingPage),
).plus(routes(isSignedIn, config)),
opts = jso { basename = config.basename },
Expand Down

0 comments on commit f8cfd7c

Please sign in to comment.