1
+ package baaahs.app.ui
2
+
3
+ import baaahs.app.ui.editor.ControlEditIntent
4
+ import baaahs.app.ui.editor.ShowEditableManager
5
+ import baaahs.app.ui.editor.editableManagerUi
6
+ import baaahs.client.WebClient
7
+ import baaahs.client.document.ShowManager
8
+ import baaahs.gl.Toolchain
9
+ import baaahs.gl.withCache
10
+ import baaahs.model.Model
11
+ import baaahs.plugin.Plugins
12
+ import baaahs.scene.OpenScene
13
+ import baaahs.scene.SceneMonitor
14
+ import baaahs.show.SampleData
15
+ import baaahs.sim.HostedWebApp
16
+ import baaahs.ui.xComponent
17
+ import baaahs.util.JsClock
18
+ import kotlinx.js.jso
19
+ import mui.material.CssBaseline
20
+ import mui.material.Paper
21
+ import mui.material.styles.ThemeProvider
22
+ import react.*
23
+ import react.dom.div
24
+
25
+ class PatchEditorApp (
26
+ private val plugins : Plugins ,
27
+ private val toolchain : Toolchain ,
28
+ private val showManager : ShowManager ,
29
+ ) : HostedWebApp {
30
+ override fun render (): ReactElement <* > {
31
+ return createElement(PatchEditorAppIndexView , jso {
32
+ this .plugins = this @PatchEditorApp.plugins
33
+ this .toolchain = this @PatchEditorApp.toolchain
34
+ this .showManager = this @PatchEditorApp.showManager.facade
35
+ })
36
+ }
37
+
38
+ override fun onClose () {
39
+ }
40
+
41
+ }
42
+
43
+ val PatchEditorAppIndexView = xComponent<PatchEditorAppIndexProps >(" PatchEditorAppIndex" ) { props ->
44
+ val showManager = props.showManager
45
+ observe(showManager)
46
+
47
+ val darkMode = true
48
+ val theme = if (darkMode) Themes .Dark else Themes .Light
49
+ val allStyles = memo(theme) { AllStyles (theme) }
50
+
51
+ val show = memo { SampleData .sampleShow }
52
+ val editableManager by state {
53
+ ShowEditableManager { newShow -> showManager.onEdit(newShow) }
54
+ .also {
55
+ var controlId = " none"
56
+ show.controls.forEach { (k, v) ->
57
+ if (v.title == " Wobble" ) controlId = k
58
+ }
59
+ it.openEditor(show, ControlEditIntent (controlId), props.toolchain)
60
+ }
61
+ }
62
+ val sceneMonitor = memo {
63
+ SceneMonitor (OpenScene (Model (" Empty model" , emptyList())))
64
+ }
65
+
66
+ val myAppContext = memo(allStyles) {
67
+ jso<AppContext > {
68
+ this .plugins = props.plugins
69
+ this .toolchain = props.toolchain
70
+ this .allStyles = allStyles
71
+ this .clock = JsClock
72
+ this .showManager = showManager
73
+ this .sceneProvider = sceneMonitor
74
+
75
+ this .openEditor = { editIntent ->
76
+ editableManager.openEditor(
77
+ show, editIntent, props.toolchain.withCache(" Edit Session" )
78
+ )
79
+ }
80
+ }
81
+ }
82
+
83
+ val myAppGlContext = memo { jso<AppGlContext > { this .sharedGlContext = null } }
84
+
85
+ appContext.Provider {
86
+ attrs.value = myAppContext
87
+
88
+ appGlContext.Provider {
89
+ attrs.value = myAppGlContext
90
+
91
+ ThemeProvider {
92
+ attrs.theme = theme
93
+ CssBaseline {}
94
+
95
+ Paper {
96
+ div {
97
+ editableManagerUi {
98
+ attrs.editableManager = editableManager
99
+ }
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ external interface PatchEditorAppIndexProps : Props {
108
+ var webClient: WebClient .Facade
109
+ var plugins: Plugins
110
+ var toolchain: Toolchain
111
+ var showManager: ShowManager .Facade
112
+ }
113
+
114
+ fun RBuilder.patchEditorAppIndex (handler : RHandler <PatchEditorAppIndexProps >) =
115
+ child(PatchEditorAppIndexView , handler = handler)
0 commit comments