Merge pull request 'Webview: add solid-query for improved resource fetching & caching' (#1755) from hsjobeki/clan-core:hsjobeki-main into main
This commit is contained in:
17
pkgs/webview-ui/app/package-lock.json
generated
17
pkgs/webview-ui/app/package-lock.json
generated
@@ -11,7 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modular-forms/solid": "^0.21.0",
|
"@modular-forms/solid": "^0.21.0",
|
||||||
"@solid-primitives/storage": "^3.7.1",
|
"@solid-primitives/storage": "^3.7.1",
|
||||||
"@tanstack/solid-query": "^5.44.0",
|
"@tanstack/solid-query": "^5.51.2",
|
||||||
"material-icons": "^1.13.12",
|
"material-icons": "^1.13.12",
|
||||||
"nanoid": "^5.0.7",
|
"nanoid": "^5.0.7",
|
||||||
"solid-js": "^1.8.11",
|
"solid-js": "^1.8.11",
|
||||||
@@ -1570,21 +1570,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tanstack/query-core": {
|
"node_modules/@tanstack/query-core": {
|
||||||
"version": "5.44.0",
|
"version": "5.51.1",
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.44.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.51.1.tgz",
|
||||||
"integrity": "sha512-Fa1J7iEEyJnjXG1N4+Fz4OXNH/INve3XSn0Htms3X4wgRsXHxMDwqBE2XtDCts7swkwSIs4izEtaFqWVFr/eLQ==",
|
"integrity": "sha512-fJBMQMpo8/KSsWW5ratJR5+IFr7YNJ3K2kfP9l5XObYHsgfVy1w3FJUWU4FT2fj7+JMaEg33zOcNDBo0LMwHnw==",
|
||||||
"funding": {
|
"funding": {
|
||||||
"type": "github",
|
"type": "github",
|
||||||
"url": "https://github.com/sponsors/tannerlinsley"
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tanstack/solid-query": {
|
"node_modules/@tanstack/solid-query": {
|
||||||
"version": "5.44.0",
|
"version": "5.51.2",
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/solid-query/-/solid-query-5.44.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tanstack/solid-query/-/solid-query-5.51.2.tgz",
|
||||||
"integrity": "sha512-fxsSFGbaHknL1zuymEZqrSRFk0wI3/RVDInlQJS3jZevnKJBAlDohIis6MZdm3EOFRTq+sfaMTNXZTu2B5MpOw==",
|
"integrity": "sha512-mFW9u6MeH72OYRg2dr4lEBrWiqnhG3aTq7PkKBfZ7BDAvOfox/tqOt3TYOKQZja3Y8XZqz5pMumsKKofYHMIQA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/query-core": "5.44.0",
|
"@tanstack/query-core": "5.51.1"
|
||||||
"solid-js": "^1.8.17"
|
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"type": "github",
|
"type": "github",
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modular-forms/solid": "^0.21.0",
|
"@modular-forms/solid": "^0.21.0",
|
||||||
"@solid-primitives/storage": "^3.7.1",
|
"@solid-primitives/storage": "^3.7.1",
|
||||||
"@tanstack/solid-query": "^5.44.0",
|
"@tanstack/solid-query": "^5.51.2",
|
||||||
"material-icons": "^1.13.12",
|
"material-icons": "^1.13.12",
|
||||||
"nanoid": "^5.0.7",
|
"nanoid": "^5.0.7",
|
||||||
"solid-js": "^1.8.11",
|
"solid-js": "^1.8.11",
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import { render } from "solid-js/web";
|
|||||||
|
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
import { getFakeResponse } from "../mock";
|
import { QueryClient, QueryClientProvider } from "@tanstack/solid-query";
|
||||||
|
|
||||||
|
const client = new QueryClient();
|
||||||
|
|
||||||
const root = document.getElementById("app");
|
const root = document.getElementById("app");
|
||||||
|
|
||||||
window.clan = window.clan || {};
|
window.clan = window.clan || {};
|
||||||
@@ -18,24 +21,14 @@ if (import.meta.env.DEV) {
|
|||||||
console.log("Development mode");
|
console.log("Development mode");
|
||||||
// Load the debugger in development mode
|
// Load the debugger in development mode
|
||||||
await import("solid-devtools");
|
await import("solid-devtools");
|
||||||
|
|
||||||
// Uncomment this block to use the Mock API
|
|
||||||
// window.webkit = window.webkit || {
|
|
||||||
// messageHandlers: {
|
|
||||||
// gtk: {
|
|
||||||
// postMessage: (postMessage) => {
|
|
||||||
// const { method, data } = postMessage;
|
|
||||||
// console.debug("Python API call", { method, data });
|
|
||||||
// setTimeout(() => {
|
|
||||||
// const mock = getFakeResponse(method, data);
|
|
||||||
// console.log("Returning mock-data: ", { mock });
|
|
||||||
|
|
||||||
// window.clan[method](JSON.stringify(mock));
|
|
||||||
// }, 200);
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
render(() => <App />, root!);
|
render(
|
||||||
|
() => (
|
||||||
|
<QueryClientProvider client={client}>
|
||||||
|
<App />
|
||||||
|
</QueryClientProvider>
|
||||||
|
),
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
root!
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,60 +1,59 @@
|
|||||||
import { route } from "@/src/App";
|
import { callApi } from "@/src/api";
|
||||||
import { OperationResponse, pyApi } from "@/src/api";
|
import { Component, For, Show } from "solid-js";
|
||||||
import { Component, For, Show, createEffect, createSignal } from "solid-js";
|
|
||||||
|
|
||||||
type DevicesModel = Extract<
|
import { createQuery } from "@tanstack/solid-query";
|
||||||
OperationResponse<"show_block_devices">,
|
|
||||||
{ status: "success" }
|
|
||||||
>["data"]["blockdevices"];
|
|
||||||
|
|
||||||
export const BlockDevicesView: Component = () => {
|
export const BlockDevicesView: Component = () => {
|
||||||
const [devices, setDevices] = createSignal<DevicesModel>();
|
const {
|
||||||
|
data: devices,
|
||||||
// pyApi.show_block_devices.receive((r) => {
|
refetch: loadDevices,
|
||||||
// const { status } = r;
|
isFetching,
|
||||||
// if (status === "error") return console.error(r.errors);
|
} = createQuery(() => ({
|
||||||
// setServices(r.data.blockdevices);
|
queryKey: ["TanStack Query"],
|
||||||
// });
|
queryFn: async () => {
|
||||||
|
const result = await callApi("show_block_devices", {});
|
||||||
// createEffect(() => {
|
if (result.status === "error") throw new Error("Failed to fetch data");
|
||||||
// if (route() === "blockdevices") pyApi.show_block_devices.dispatch({});
|
return result.data;
|
||||||
// });
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div class="tooltip tooltip-bottom" data-tip="Refresh">
|
<div class="tooltip tooltip-bottom" data-tip="Refresh">
|
||||||
<button
|
<button class="btn btn-ghost" onClick={() => loadDevices()}>
|
||||||
class="btn btn-ghost"
|
|
||||||
// onClick={() => pyApi.show_block_devices.dispatch({})}
|
|
||||||
>
|
|
||||||
<span class="material-icons ">refresh</span>
|
<span class="material-icons ">refresh</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex max-w-screen-lg flex-col gap-4">
|
<div class="flex max-w-screen-lg flex-col gap-4">
|
||||||
<Show when={devices()}>
|
{isFetching ? (
|
||||||
{(devices) => (
|
<span class="loading loading-bars"></span>
|
||||||
<For each={devices()}>
|
) : (
|
||||||
{(device) => (
|
<Show when={devices}>
|
||||||
<div class="stats shadow">
|
{(devices) => (
|
||||||
<div class="stat w-28 py-8">
|
<For each={devices().blockdevices}>
|
||||||
<div class="stat-title">Name</div>
|
{(device) => (
|
||||||
<div class="stat-value">
|
<div class="stats shadow">
|
||||||
{" "}
|
<div class="stat w-28 py-8">
|
||||||
<span class="material-icons">storage</span> {device.name}
|
<div class="stat-title">Name</div>
|
||||||
|
<div class="stat-value">
|
||||||
|
{" "}
|
||||||
|
<span class="material-icons">storage</span>{" "}
|
||||||
|
{device.name}
|
||||||
|
</div>
|
||||||
|
<div class="stat-desc"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-desc"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="stat w-28">
|
<div class="stat w-28">
|
||||||
<div class="stat-title">Size</div>
|
<div class="stat-title">Size</div>
|
||||||
<div class="stat-value">{device.size}</div>
|
<div class="stat-value">{device.size}</div>
|
||||||
<div class="stat-desc"></div>
|
<div class="stat-desc"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
</For>
|
||||||
</For>
|
)}
|
||||||
)}
|
</Show>
|
||||||
</Show>
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ export const Welcome = () => {
|
|||||||
>
|
>
|
||||||
Or select folder
|
Or select folder
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
class="link w-full text-right text-secondary"
|
||||||
|
onClick={async () => {
|
||||||
|
setRoute("machines");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Skip (Debug)
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
npmDeps = pkgs.fetchNpmDeps {
|
npmDeps = pkgs.fetchNpmDeps {
|
||||||
src = ./app;
|
src = ./app;
|
||||||
hash = "sha256-U8FwGL0FelUZwa8NjitfsFNDSofUPbp+nHrypeDj2Po=";
|
hash = "sha256-/PFSBAIodZjInElYoNsDQUV4isxmcvL3YM1hzAmdDWA=";
|
||||||
};
|
};
|
||||||
# The prepack script runs the build script, which we'd rather do in the build phase.
|
# The prepack script runs the build script, which we'd rather do in the build phase.
|
||||||
npmPackFlags = [ "--ignore-scripts" ];
|
npmPackFlags = [ "--ignore-scripts" ];
|
||||||
|
|||||||
Reference in New Issue
Block a user