From f7e0345ab3cd9e2de648d040fa77689b32c10dd8 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 30 Apr 2025 14:36:47 +0700 Subject: [PATCH] app: open welcome page if clan doesn't exist Previously if a user started the app and the last opened clan directory does not exist anymore, it would still show the clan screen but without any machines. This changes catches this case and throws the user back to the clan selection page --- pkgs/clan-cli/clan_cli/clan/show.py | 5 ++++- pkgs/webview-ui/app/src/App.tsx | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/clan/show.py b/pkgs/clan-cli/clan_cli/clan/show.py index 281f8f744..e08dc5562 100644 --- a/pkgs/clan-cli/clan_cli/clan/show.py +++ b/pkgs/clan-cli/clan_cli/clan/show.py @@ -15,7 +15,10 @@ log = logging.getLogger(__name__) @API.register -def show_clan_meta(uri: str | Path) -> Meta: +def show_clan_meta(uri: str) -> Meta: + if uri.startswith("/") and not Path(uri).exists(): + msg = f"Path {uri} does not exist" + raise ClanError(msg, description="clan directory does not exist") cmd = nix_eval( [ f"{uri}#clanInternals.inventory.meta", diff --git a/pkgs/webview-ui/app/src/App.tsx b/pkgs/webview-ui/app/src/App.tsx index d5ad8b40e..a6117cf9d 100644 --- a/pkgs/webview-ui/app/src/App.tsx +++ b/pkgs/webview-ui/app/src/App.tsx @@ -1,5 +1,6 @@ import { createSignal } from "solid-js"; import { makePersisted } from "@solid-primitives/storage"; +import { callApi } from "./api"; const [activeURI, setActiveURI] = makePersisted( createSignal(null), @@ -17,3 +18,22 @@ const [clanList, setClanList] = makePersisted(createSignal([]), { }); export { clanList, setClanList }; + +(async function () { + const curr = activeURI(); + if (curr) { + const result = await callApi("show_clan_meta", { uri: curr }); + console.log("refetched meta for ", curr); + if (result.status === "error") { + result.errors.forEach((error) => { + if (error.description === "clan directory does not exist") { + setActiveURI(null); + setClanList((clans) => clans.filter((clan) => clan !== curr)); + } + }); + } + } +})(); + +// ensure to null out activeURI on startup if the clan was deleted +// => throws user back to the view for selecting a clan