ui/routing: re-route on changes not only on page load
This commit is contained in:
@@ -22,7 +22,7 @@ import {
|
|||||||
useMachinesQuery,
|
useMachinesQuery,
|
||||||
} from "@/src/hooks/queries";
|
} from "@/src/hooks/queries";
|
||||||
import { callApi } from "@/src/hooks/api";
|
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 { produce } from "solid-js/store";
|
||||||
import { Button } from "@/src/components/Button/Button";
|
import { Button } from "@/src/components/Button/Button";
|
||||||
import { Splash } from "@/src/scene/splash";
|
import { Splash } from "@/src/scene/splash";
|
||||||
@@ -164,6 +164,10 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
|
|
||||||
const machine = createMemo(() => maybeUseMachineName());
|
const machine = createMemo(() => maybeUseMachineName());
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
console.log("Selected clan:", clanURI);
|
||||||
|
});
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
on(machine, (machineId) => {
|
on(machine, (machineId) => {
|
||||||
if (machineId) {
|
if (machineId) {
|
||||||
@@ -220,6 +224,13 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
|
<Button
|
||||||
|
onClick={() => setActiveClanURI(undefined)}
|
||||||
|
hierarchy="primary"
|
||||||
|
class="absolute bottom-4 right-4"
|
||||||
|
>
|
||||||
|
close this clan
|
||||||
|
</Button>
|
||||||
<div
|
<div
|
||||||
class={cx({
|
class={cx({
|
||||||
"fade-out": !machinesQuery.isLoading && loadingCooldown(),
|
"fade-out": !machinesQuery.isLoading && loadingCooldown(),
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
import { Component } from "solid-js";
|
import { Component, createEffect, on } from "solid-js";
|
||||||
import { RouteSectionProps, useNavigate } from "@solidjs/router";
|
import { RouteSectionProps, useNavigate } from "@solidjs/router";
|
||||||
import { activeClanURI } from "@/src/stores/clan";
|
import { activeClanURI, setActiveClanURI } from "@/src/stores/clan";
|
||||||
import { navigateToClan } from "@/src/hooks/clan";
|
import { navigateToClan } from "@/src/hooks/clan";
|
||||||
|
import { Button } from "../components/Button/Button";
|
||||||
|
|
||||||
export const Layout: Component<RouteSectionProps> = (props) => {
|
export const Layout: Component<RouteSectionProps> = (props) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
// check for an active clan uri and redirect to it on first load
|
// check for an active clan uri and redirect if no clan is active
|
||||||
const activeURI = activeClanURI();
|
createEffect(
|
||||||
if (!props.location.pathname.startsWith("/clans/") && activeURI) {
|
on(activeClanURI, (activeURI) => {
|
||||||
navigateToClan(navigate, activeURI);
|
console.debug("Active Clan URI changed:", activeURI);
|
||||||
} else {
|
if (activeURI && !props.location.pathname.startsWith("/clans/")) {
|
||||||
navigate("/");
|
navigateToClan(navigate, activeURI);
|
||||||
}
|
} else {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
return <div class="size-full h-screen">{props.children}</div>;
|
return <div class="size-full h-screen">{props.children}</div>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ class RenderLoop {
|
|||||||
|
|
||||||
this.renderRequested = true;
|
this.renderRequested = true;
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
|
if (!this.initialized) {
|
||||||
|
console.log("RenderLoop not initialized, skipping render.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.updateTweens();
|
this.updateTweens();
|
||||||
|
|
||||||
const needsUpdate = this.controls.update(); // returns true if damping is ongoing
|
const needsUpdate = this.controls.update(); // returns true if damping is ongoing
|
||||||
@@ -69,6 +74,7 @@ class RenderLoop {
|
|||||||
this.render();
|
this.render();
|
||||||
this.renderRequested = false;
|
this.renderRequested = false;
|
||||||
|
|
||||||
|
// Controls smoothing may require another render
|
||||||
if (needsUpdate) {
|
if (needsUpdate) {
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ const activeClanURI = () => store.activeClanURI;
|
|||||||
*
|
*
|
||||||
* @param {string} uri - The URI to be set as the active Clan URI.
|
* @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.
|
* Retrieves the current list of clan URIs from the store.
|
||||||
|
|||||||
Reference in New Issue
Block a user