From 3ebee252aa322ea2ab73de6d584cee53fb5a5d16 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 15 Jun 2024 11:35:15 +0200 Subject: [PATCH] Webview: init machine details --- .../app/src/components/MachineListItem.tsx | 83 +++++++++++++++++++ .../app/src/routes/machines/view.tsx | 33 +------- 2 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 pkgs/webview-ui/app/src/components/MachineListItem.tsx diff --git a/pkgs/webview-ui/app/src/components/MachineListItem.tsx b/pkgs/webview-ui/app/src/components/MachineListItem.tsx new file mode 100644 index 00000000..9bddf0dc --- /dev/null +++ b/pkgs/webview-ui/app/src/components/MachineListItem.tsx @@ -0,0 +1,83 @@ +import { For, Show, createSignal } from "solid-js"; +import { ErrorData, SuccessData, pyApi } from "../api"; +import { currClanURI } from "../App"; + +interface MachineListItemProps { + name: string; +} + +type MachineDetails = Record["data"]>; + +type MachineErrors = Record["errors"]>; + +const [details, setDetails] = createSignal({}); +const [errors, setErrors] = createSignal({}); + +pyApi.show_machine.receive((r) => { + if (r.status === "error") { + const { op_key } = r; + if (op_key) { + setErrors((e) => ({ ...e, [op_key]: r.errors })); + } + console.error(r.errors); + } + if (r.status === "success") { + setDetails((d) => ({ ...d, [r.data.machine_name]: r.data })); + } +}); + +export const MachineListItem = (props: MachineListItemProps) => { + const { name } = props; + + pyApi.show_machine.dispatch({ + op_key: name, + machine_name: name, + debug: false, + flake_url: currClanURI(), + }); + + return ( +
  • +
    +
    + + devices_other + +
    +
    +
    +

    {name}

    + + {(errors) => ( + + {(error) => ( +

    + {error.message}: {error.description} +

    + )} +
    + )} +
    + + {(details) => ( +

    + {details().machine_description || "No description"} +

    + )} +
    +
    +
    + +
    +
    +
    +
  • + ); +}; diff --git a/pkgs/webview-ui/app/src/routes/machines/view.tsx b/pkgs/webview-ui/app/src/routes/machines/view.tsx index 0606093e..342dbdfc 100644 --- a/pkgs/webview-ui/app/src/routes/machines/view.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/view.tsx @@ -10,6 +10,7 @@ import { useMachineContext } from "../../Config"; import { route } from "@/src/App"; import { OperationResponse, pyApi } from "@/src/api"; import toast from "solid-toast"; +import { MachineListItem } from "@/src/components/MachineListItem"; type FilesModel = Extract< OperationResponse<"get_directory">, @@ -99,37 +100,7 @@ export const MachineListView: Component = () => {
      - {(entry) => ( -
    • -
      -
      - - devices_other - -
      -
      -
      -

      {entry}

      - {/* -

      - {entry.machine_description || "No description"} -

      - */} -
      -
      - -
      -
      -
      -
    • - )} + {(entry) => }