trixnity-messenger-playground

A playground for trixnity-messenger based on jetbrains compose-html
git clone git://archive.git.mtrnord.blog/MTRNord/trixnity-messenger-playground.git
Log | Files | Refs | README

commit f77cef7dc32faf86be6239d62ff09485b094f1f5
parent 41c105620946e095ddc45f7ce9c1233eb8bce8e3
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 26 Sep 2023 18:21:12 +0200

Feat: Add very early and basic state handling

Diffstat:
M.idea/workspace.xml | 40++++++++++++++++++++++++++++++++--------
Msrc/main/kotlin/main.kt | 66++++++++++++++++++++++++++++++++++++++++++++++--------------------
Asrc/main/kotlin/pages/Login.kt | 6++++++
3 files changed, 84 insertions(+), 28 deletions(-)

diff --git a/.idea/workspace.xml b/.idea/workspace.xml @@ -4,12 +4,12 @@ <option name="autoReloadType" value="SELECTIVE" /> </component> <component name="ChangeListManager"> - <list default="true" id="fc5af14b-7484-46dc-b4cb-0394f9dc3dda" name="Changes" comment="Fix: Make sure the artifact has the right name and also ensure we properly load the right things and use recent webpack"> + <list default="true" id="fc5af14b-7484-46dc-b4cb-0394f9dc3dda" name="Changes" comment="Fix: use correct github action"> + <change afterPath="$PROJECT_DIR$/src/main/kotlin/pages/Login.kt" afterDir="false" /> + <change afterPath="/var/home/marcel/IdeaProjects/MagicMatrix/src/main/kotlin/pages/Login.kt" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> - <change beforePath="/var/home/marcel/IdeaProjects/MagicMatrix/.github/workflows/deploy.yaml" beforeDir="false" afterPath="/var/home/marcel/IdeaProjects/MagicMatrix/.github/workflows/deploy.yaml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/kotlin/main.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/main.kt" afterDir="false" /> <change beforePath="/var/home/marcel/IdeaProjects/MagicMatrix/.idea/workspace.xml" beforeDir="false" afterPath="/var/home/marcel/IdeaProjects/MagicMatrix/.idea/workspace.xml" afterDir="false" /> - <change beforePath="/var/home/marcel/IdeaProjects/MagicMatrix/build.gradle.kts" beforeDir="false" afterPath="/var/home/marcel/IdeaProjects/MagicMatrix/build.gradle.kts" afterDir="false" /> - <change beforePath="/var/home/marcel/IdeaProjects/MagicMatrix/gradle/libs.versions.toml" beforeDir="false" afterPath="/var/home/marcel/IdeaProjects/MagicMatrix/gradle/libs.versions.toml" afterDir="false" /> <change beforePath="/var/home/marcel/IdeaProjects/MagicMatrix/src/main/kotlin/main.kt" beforeDir="false" afterPath="/var/home/marcel/IdeaProjects/MagicMatrix/src/main/kotlin/main.kt" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> @@ -40,6 +40,9 @@ </state> </system> </component> + <component name="FormatOnSaveOptions"> + <option name="myRunOnSave" value="true" /> + </component> <component name="Git.Settings"> <option name="RECENT_GIT_ROOT_PATH" value="/var/home/marcel/IdeaProjects/MagicMatrix" /> <option name="ROOT_SYNC" value="SYNC" /> @@ -58,6 +61,9 @@ </UrlAndAccount> </option> </component> + <component name="OptimizeOnSaveOptions"> + <option name="myRunOnSave" value="true" /> + </component> <component name="ProjectColorInfo"><![CDATA[{ "customColor": "", "associatedIndex": 4 @@ -79,7 +85,7 @@ "node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.tslint": "(autodetect)", "nodejs_package_manager_path": "npm", - "settings.editor.selected.configurable": "terminal", + "settings.editor.selected.configurable": "actions.on.save", "vue.rearranger.settings.migration": "true" } }]]></component> @@ -120,7 +126,7 @@ <option name="number" value="Default" /> <option name="presentableId" value="Default" /> <updated>1695740188018</updated> - <workItem from="1695740189223" duration="3203000" /> + <workItem from="1695740189223" duration="4352000" /> </task> <task id="LOCAL-00001" summary="Fix: Fix typo in workflow file"> <option name="closed" value="true" /> @@ -138,7 +144,23 @@ <option name="project" value="LOCAL" /> <updated>1695743685586</updated> </task> - <option name="localTasksCounter" value="3" /> + <task id="LOCAL-00003" summary="Feat: Add silk and make sure the right folder is packaged"> + <option name="closed" value="true" /> + <created>1695744067985</created> + <option name="number" value="00003" /> + <option name="presentableId" value="LOCAL-00003" /> + <option name="project" value="LOCAL" /> + <updated>1695744067985</updated> + </task> + <task id="LOCAL-00004" summary="Fix: use correct github action"> + <option name="closed" value="true" /> + <created>1695744650898</created> + <option name="number" value="00004" /> + <option name="presentableId" value="LOCAL-00004" /> + <option name="project" value="LOCAL" /> + <updated>1695744650898</updated> + </task> + <option name="localTasksCounter" value="5" /> <servers /> </component> <component name="TypeScriptGeneratedFilesManager"> @@ -160,6 +182,8 @@ <MESSAGE value="Feat: Readd Github deployment" /> <MESSAGE value="Fix: Fix typo in workflow file" /> <MESSAGE value="Fix: Make sure the artifact has the right name and also ensure we properly load the right things and use recent webpack" /> - <option name="LAST_COMMIT_MESSAGE" value="Fix: Make sure the artifact has the right name and also ensure we properly load the right things and use recent webpack" /> + <MESSAGE value="Feat: Add silk and make sure the right folder is packaged" /> + <MESSAGE value="Fix: use correct github action" /> + <option name="LAST_COMMIT_MESSAGE" value="Fix: use correct github action" /> </component> </project> \ No newline at end of file diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt @@ -1,4 +1,7 @@ -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import com.arkivanov.decompose.DefaultComponentContext import com.arkivanov.essenty.lifecycle.LifecycleRegistry import com.varabyte.kobweb.silk.SilkStyleSheet @@ -7,17 +10,22 @@ import com.varabyte.kobweb.silk.init.setSilkVariables import de.connect2x.trixnity.messenger.DefaultMatrixClientService import de.connect2x.trixnity.messenger.trixnityMessengerModule import de.connect2x.trixnity.messenger.viewmodel.RootRouter -import de.connect2x.trixnity.messenger.viewmodel.RootViewModel import de.connect2x.trixnity.messenger.viewmodel.RootViewModelImpl +import de.connect2x.trixnity.messenger.viewmodel.connecting.MatrixClientInitializationViewModel import de.connect2x.trixnity.messenger.viewmodel.util.toFlow import kotlinx.browser.document import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.mapLatest import org.jetbrains.compose.web.css.Style +import org.jetbrains.compose.web.css.padding +import org.jetbrains.compose.web.css.px +import org.jetbrains.compose.web.dom.Div +import org.jetbrains.compose.web.dom.Text import org.jetbrains.compose.web.renderComposable import org.koin.dsl.koinApplication import org.w3c.dom.HTMLElement +@OptIn(ExperimentalCoroutinesApi::class) fun main() { // Init Kobweb initSilk() @@ -36,32 +44,50 @@ fun main() { } ) - - - renderComposable(rootElementId = "root") { - // Further Init for kobweb - val root = remember { document.getElementById("root") as HTMLElement } - root.setSilkVariables() - Style(SilkStyleSheet) - - Base(rootViewModel) - } -} - -@OptIn(ExperimentalCoroutinesApi::class) -@Composable -fun Base(rootViewModel: RootViewModel) { suspend { rootViewModel.rootStack.toFlow() .mapLatest { it.active.instance } .collect { wrapper -> - when(wrapper) { + when (wrapper) { is RootRouter.RootWrapper.None -> { + renderComposable(rootElementId = "root") { + // Further Init for kobweb + val root = remember { document.getElementById("root") as HTMLElement } + root.setSilkVariables() + Style(SilkStyleSheet) + + None() + } + } - } // draw an empty UI - is RootRouter.RootWrapper.MatrixClientInitialization -> {} // show initialization of the MatrixClient (aka loading screen) + is RootRouter.RootWrapper.MatrixClientInitialization -> { + renderComposable(rootElementId = "root") { + // Further Init for kobweb + val root = remember { document.getElementById("root") as HTMLElement } + root.setSilkVariables() + Style(SilkStyleSheet) + + Init(wrapper.matrixClientInitializationViewModel) + } + } // show initialization of the MatrixClient (aka loading screen) else -> {} // add more cases } } } + +} + +@Composable +fun Init(matrixClientInitializationViewModel: MatrixClientInitializationViewModel) { + val initState by matrixClientInitializationViewModel.currentState.collectAsState(); + Div({ style { padding(25.px) } }) { + Text(initState) + } +} + +@Composable +fun None() { + Div({ style { padding(25.px) } }) { + Text("Initializing matrix") + } } \ No newline at end of file diff --git a/src/main/kotlin/pages/Login.kt b/src/main/kotlin/pages/Login.kt @@ -0,0 +1,5 @@ +import androidx.compose.runtime.Composable +import de.connect2x.trixnity.messenger.viewmodel.RootViewModel + +@Composable +fun Login() {} +\ No newline at end of file