From 56b2347a30f3aa0b509f947c2e3dde2aa51134d1 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 19 Jun 2024 11:07:34 +0200 Subject: [PATCH] UI: display known network hosts --- pkgs/webview-ui/app/src/Routes.tsx | 6 ++ pkgs/webview-ui/app/src/routes/hosts/view.tsx | 98 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 pkgs/webview-ui/app/src/routes/hosts/view.tsx diff --git a/pkgs/webview-ui/app/src/Routes.tsx b/pkgs/webview-ui/app/src/Routes.tsx index feee4144..38b69179 100644 --- a/pkgs/webview-ui/app/src/Routes.tsx +++ b/pkgs/webview-ui/app/src/Routes.tsx @@ -2,6 +2,7 @@ import { Accessor, For, Match, Switch } from "solid-js"; import { MachineListView } from "./routes/machines/view"; import { colors } from "./routes/colors/view"; import { clan } from "./routes/clan/view"; +import { HostList } from "./routes/hosts/view"; export type Route = keyof typeof routes; @@ -16,6 +17,11 @@ export const routes = { label: "Machines", icon: "devices_other", }, + hosts: { + child: HostList, + label: "hosts", + icon: "devices_other", + }, colors: { child: colors, label: "Colors", diff --git a/pkgs/webview-ui/app/src/routes/hosts/view.tsx b/pkgs/webview-ui/app/src/routes/hosts/view.tsx new file mode 100644 index 00000000..c12f234b --- /dev/null +++ b/pkgs/webview-ui/app/src/routes/hosts/view.tsx @@ -0,0 +1,98 @@ +import { + For, + Match, + Show, + Switch, + createEffect, + createSignal, + type Component, +} from "solid-js"; +import { useMachineContext } from "../../Config"; +import { route } from "@/src/App"; +import { OperationResponse, pyApi } from "@/src/api"; +import toast from "solid-toast"; + +type ServiceModel = Extract< + OperationResponse<"show_mdns">, + { status: "success" } +>["data"]["services"]; + +export const HostList: Component = () => { + const [services, setServices] = createSignal(); + + pyApi.show_mdns.receive((r) => { + const { status } = r; + if (status === "error") return console.error(r.errors); + setServices(r.data.services); + }); + + createEffect(() => { + if (route() === "hosts") pyApi.show_mdns.dispatch({}); + }); + + return ( +
+
+ +
+
+ + {(services) => ( + + {(service) => ( +
+
+
+
Host
+
{service.host}
+
+
+ +
+
IP
+
{service.ip}
+
+
+
+ +
+
+ +
+ Details +
+
+

+ Interface + {service.interface} +

+

+ Protocol + {service.protocol} +

+ +

+ Type + {service.type_} +

+

+ Domain + {service.domain} +

+
+
+
+
+ )} +
+ )} +
+
+
+ ); +};