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 71f8d234eefe9aa930f8c9207d95a652ee0042a7
parent f77cef7dc32faf86be6239d62ff09485b094f1f5
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 26 Sep 2023 18:36:41 +0200

Cleanup

Diffstat:
M.idea/workspace.xml | 20+++++++++++++-------
Msrc/main/kotlin/main.kt | 54++++++++++++++++++++++++++----------------------------
2 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/.idea/workspace.xml b/.idea/workspace.xml @@ -4,11 +4,8 @@ <option name="autoReloadType" value="SELECTIVE" /> </component> <component name="ChangeListManager"> - <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" /> + <list default="true" id="fc5af14b-7484-46dc-b4cb-0394f9dc3dda" name="Changes" comment="Feat: Add very early and basic state handling"> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/src/main/kotlin/main.kt" beforeDir="false" afterPath="/var/home/marcel/IdeaProjects/MagicMatrix/src/main/kotlin/main.kt" afterDir="false" /> </list> @@ -126,7 +123,7 @@ <option name="number" value="Default" /> <option name="presentableId" value="Default" /> <updated>1695740188018</updated> - <workItem from="1695740189223" duration="4352000" /> + <workItem from="1695740189223" duration="5352000" /> </task> <task id="LOCAL-00001" summary="Fix: Fix typo in workflow file"> <option name="closed" value="true" /> @@ -160,7 +157,15 @@ <option name="project" value="LOCAL" /> <updated>1695744650898</updated> </task> - <option name="localTasksCounter" value="5" /> + <task id="LOCAL-00005" summary="Feat: Add very early and basic state handling"> + <option name="closed" value="true" /> + <created>1695745278124</created> + <option name="number" value="00005" /> + <option name="presentableId" value="LOCAL-00005" /> + <option name="project" value="LOCAL" /> + <updated>1695745278124</updated> + </task> + <option name="localTasksCounter" value="6" /> <servers /> </component> <component name="TypeScriptGeneratedFilesManager"> @@ -184,6 +189,7 @@ <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" /> + <MESSAGE value="Feat: Add very early and basic state handling" /> + <option name="LAST_COMMIT_MESSAGE" value="Feat: Add very early and basic state handling" /> </component> </project> \ No newline at end of file diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt @@ -10,6 +10,7 @@ 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 @@ -25,7 +26,6 @@ import org.jetbrains.compose.web.renderComposable import org.koin.dsl.koinApplication import org.w3c.dom.HTMLElement -@OptIn(ExperimentalCoroutinesApi::class) fun main() { // Init Kobweb initSilk() @@ -44,37 +44,35 @@ fun main() { } ) - suspend { - rootViewModel.rootStack.toFlow() - .mapLatest { it.active.instance } - .collect { 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) + renderComposable(rootElementId = "root") { + // Further Init for kobweb + val root = remember { document.getElementById("root") as HTMLElement } + root.setSilkVariables() + Style(SilkStyleSheet) - None() - } - } + Base(rootViewModel) + } - 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 - } - } - } +@OptIn(ExperimentalCoroutinesApi::class) +@Composable +fun Base(rootViewModel: RootViewModel) { + // Trixnity messenger router + // FIXME: This seems to loose type info? + val routerState by rootViewModel.rootStack.toFlow() + .mapLatest { it.active.instance }.collectAsState(RootRouter.RootWrapper.None) + + when (routerState) { + is RootRouter.RootWrapper.None -> { + None() + } + is RootRouter.RootWrapper.MatrixClientInitialization -> { + Init((routerState as RootRouter.RootWrapper.MatrixClientInitialization).matrixClientInitializationViewModel) + } // show initialization of the MatrixClient (aka loading screen) + else -> {} // add more cases + } } @Composable