From 40d35d37e24cf05e40fe705e3e7be06fb4ff2407 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 19 Aug 2025 12:10:04 +0200 Subject: [PATCH] ui/routing: re-route on changes not only on page load --- pkgs/clan-app/ui/src/routes/Clan/Clan.tsx | 13 ++++++++++++- pkgs/clan-app/ui/src/routes/Layout.tsx | 23 ++++++++++++++--------- pkgs/clan-app/ui/src/scene/RenderLoop.ts | 6 ++++++ pkgs/clan-app/ui/src/stores/clan.ts | 3 ++- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/pkgs/clan-app/ui/src/routes/Clan/Clan.tsx b/pkgs/clan-app/ui/src/routes/Clan/Clan.tsx index 0c5b2bb55..01fe7e4d5 100644 --- a/pkgs/clan-app/ui/src/routes/Clan/Clan.tsx +++ b/pkgs/clan-app/ui/src/routes/Clan/Clan.tsx @@ -22,7 +22,7 @@ import { useMachinesQuery, } from "@/src/hooks/queries"; import { callApi } from "@/src/hooks/api"; -import { store, setStore, clanURIs } from "@/src/stores/clan"; +import { store, setStore, clanURIs, setActiveClanURI } from "@/src/stores/clan"; import { produce } from "solid-js/store"; import { Button } from "@/src/components/Button/Button"; import { Splash } from "@/src/scene/splash"; @@ -164,6 +164,10 @@ const ClanSceneController = (props: RouteSectionProps) => { const machine = createMemo(() => maybeUseMachineName()); + createEffect(() => { + console.log("Selected clan:", clanURI); + }); + createEffect( on(machine, (machineId) => { if (machineId) { @@ -220,6 +224,13 @@ const ClanSceneController = (props: RouteSectionProps) => { }} /> +
= (props) => { const navigate = useNavigate(); - // check for an active clan uri and redirect to it on first load - const activeURI = activeClanURI(); - if (!props.location.pathname.startsWith("/clans/") && activeURI) { - navigateToClan(navigate, activeURI); - } else { - navigate("/"); - } + // check for an active clan uri and redirect if no clan is active + createEffect( + on(activeClanURI, (activeURI) => { + console.debug("Active Clan URI changed:", activeURI); + if (activeURI && !props.location.pathname.startsWith("/clans/")) { + navigateToClan(navigate, activeURI); + } else { + navigate("/"); + } + }), + ); return
{props.children}
; }; diff --git a/pkgs/clan-app/ui/src/scene/RenderLoop.ts b/pkgs/clan-app/ui/src/scene/RenderLoop.ts index 4046ad2a9..746e95ecd 100644 --- a/pkgs/clan-app/ui/src/scene/RenderLoop.ts +++ b/pkgs/clan-app/ui/src/scene/RenderLoop.ts @@ -62,6 +62,11 @@ class RenderLoop { this.renderRequested = true; requestAnimationFrame(() => { + if (!this.initialized) { + console.log("RenderLoop not initialized, skipping render."); + return; + } + this.updateTweens(); const needsUpdate = this.controls.update(); // returns true if damping is ongoing @@ -69,6 +74,7 @@ class RenderLoop { this.render(); this.renderRequested = false; + // Controls smoothing may require another render if (needsUpdate) { this.requestRender(); } diff --git a/pkgs/clan-app/ui/src/stores/clan.ts b/pkgs/clan-app/ui/src/stores/clan.ts index c9cb52264..658df6dbc 100644 --- a/pkgs/clan-app/ui/src/stores/clan.ts +++ b/pkgs/clan-app/ui/src/stores/clan.ts @@ -41,7 +41,8 @@ const activeClanURI = () => store.activeClanURI; * * @param {string} uri - The URI to be set as the active Clan URI. */ -const setActiveClanURI = (uri: string) => setStore("activeClanURI", uri); +const setActiveClanURI = (uri: string | undefined) => + setStore("activeClanURI", uri); /** * Retrieves the current list of clan URIs from the store.