From b89500a2f8ff91a3a6088f68683208a402c7dd06 Mon Sep 17 00:00:00 2001 From: CEbbinghaus Date: Tue, 17 Dec 2024 23:56:12 +1100 Subject: [PATCH] Cleaned up empty card display --- .mise.toml | 2 +- build.sh | 1 - docs/index.mdx | 2 +- src/index.tsx | 68 +++++++++++++++++++++++++++++++------------------- util/build.mjs | 12 ++++++--- 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/.mise.toml b/.mise.toml index 8732691..f8253a5 100644 --- a/.mise.toml +++ b/.mise.toml @@ -18,7 +18,7 @@ outputs = ['build/bin/backend'] [tasks."build:frontend"] description = 'Build the Frontend' run = "node --no-warnings=ExperimentalWarning 'util/build.mjs' -q -o frontend" -sources = ['package.json', 'lib/package.json', '{src,lib}/**/*.{ts,tsx,codegen}'] +sources = ['package.json', 'lib/package.json', '{src,lib,docs}/**/*.{ts,tsx,codegen}'] outputs = ['dist/index.js'] [tasks."build:collect"] diff --git a/build.sh b/build.sh index feb075f..0c1cd2c 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,2 @@ #!/bin/bash exec node "--no-warnings=ExperimentalWarning" "util/build.mjs" "$@" - diff --git a/docs/index.mdx b/docs/index.mdx index a165898..1dd5d1f 100644 --- a/docs/index.mdx +++ b/docs/index.mdx @@ -1,4 +1,4 @@ -import { Navigation, SideMenu } from "decky-frontend-lib"; +import { Navigation, SideMenu } from "@decky/ui"; import { CurrentCard } from "./components/CurrentCard"; import { CheckList, CheckListItem } from "./components/QuickStart/CheckList"; import { FaPlug } from "react-icons/fa" diff --git a/src/index.tsx b/src/index.tsx index b9065dc..cb33ede 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -51,14 +51,18 @@ function EditCardButton(props: EditCardButtonProps) { ) } -function Content() { - const { currentCardAndGames, cardsAndGames, microSDeck } = useMicroSDeckContext(); +function CardsList({ cardsAndGames, currentCardAndGames, microSDeck }: { cardsAndGames: CardAndGames[], currentCardAndGames: CardAndGames | undefined, microSDeck: MicroSDeck }) { const [currentCard] = currentCardAndGames || [undefined]; - const isLoaded = !!cardsAndGames; + function CardInteractables({ entry }: { + entry: ReorderableEntry + }) { + const cardAndGames = cardsAndGames.find(([card]) => card.uid == entry.data!.uid)!; + return (); + } - const entries = cardsAndGames?.sort(([a], [b]) => a.position - b.position).map(([card], index) => { + const entries = cardsAndGames.sort(([a], [b]) => a.position - b.position).map(([card], index) => { const currentCardMark = card.uid === currentCard?.uid ? () : ""; return { @@ -76,42 +80,56 @@ function Content() { }; }); - function CardInteractables({ entry }: { - entry: ReorderableEntry - }) { - const cardAndGames = cardsAndGames!.find(([card]) => card.uid == entry.data!.uid)!; - return (); + if (entries.length == 0) { + return ( +
+ No Cards (yet) +
+ ); } + return ( + + entries={entries!} + interactables={CardInteractables} + onSave={async (entries: ReorderableEntry[]) => { + await backend.fetchUpdateCards({ + url: API_URL, logger: Logger, cards: entries.map(v => { + v.data!.position = v.position; + return v.data!; + }) + }); + + Logger.Log(`Reordered Tabs`) + }} + /> + ); +} + +function Content() { + const { currentCardAndGames, cardsAndGames, microSDeck } = useMicroSDeckContext(); + + const isLoaded = !!cardsAndGames; + + //TODO: Add docs card + return ( <> { Navigation.CloseSideMenus(); Navigation.Navigate(DOCUMENTATION_PATH); }}>
Edit MicroSD Cards
+ {isLoaded ? ( - - entries={entries!} - interactables={CardInteractables} - onSave={async (entries: ReorderableEntry[]) => { - await backend.fetchUpdateCards({ - url: API_URL, logger: Logger, cards: entries.map(v => { - v.data!.position = v.position; - return v.data!; - }) - }); - - Logger.Log(`Reordered Tabs`) - }} - /> + ) : (
Loading...
)}
-
+ ); }; @@ -128,7 +146,7 @@ export default definePlugin(() => { const patch = PatchAppScreen(window.MicroSDeck); routerHook.addRoute(DOCUMENTATION_PATH, () => ( - {throw "MicroSDeck not initialized";})()}> + { throw "MicroSDeck not initialized"; })()}> )); diff --git a/util/build.mjs b/util/build.mjs index 29aa3fe..076e233 100644 --- a/util/build.mjs +++ b/util/build.mjs @@ -155,14 +155,20 @@ if (is_local && tasks.includes('copy')) { if (tasks.includes('upload')) { Logger.Log("Uploading plugin to SteamDeck"); + var deployJsonPath = join(basePath, 'deploy.json'); try { - statfsSync(join(basePath, 'deploy.json')) + statfsSync(deployJsonPath) } catch (e) { - Logger.Error("deploy.json not found. Cannot deploy without it"); + Logger.Error(`deploy.json not found under \"${basePath}\" Cannot deploy without it`); exit(1); } - const { host, user, keyfile } = importJson('deploy.json'); + const { host, user, keyfile } = await importJson(deployJsonPath); + + if (!host || !user) { + Logger.Error('malformed deploy.json. missing host and user fields'); + exit(1); + } // ping host to make sure its avaliable try {