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:
clan-bot
2024-07-15 17:53:54 +00:00
6 changed files with 74 additions and 75 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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);
// },
// },
// },
// };
} }
render(
() => (
<QueryClientProvider client={client}>
<App />
</QueryClientProvider>
),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
render(() => <App />, root!); root!
);

View File

@@ -1,46 +1,44 @@
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 ? (
<span class="loading loading-bars"></span>
) : (
<Show when={devices}>
{(devices) => ( {(devices) => (
<For each={devices()}> <For each={devices().blockdevices}>
{(device) => ( {(device) => (
<div class="stats shadow"> <div class="stats shadow">
<div class="stat w-28 py-8"> <div class="stat w-28 py-8">
<div class="stat-title">Name</div> <div class="stat-title">Name</div>
<div class="stat-value"> <div class="stat-value">
{" "} {" "}
<span class="material-icons">storage</span> {device.name} <span class="material-icons">storage</span>{" "}
{device.name}
</div> </div>
<div class="stat-desc"></div> <div class="stat-desc"></div>
</div> </div>
@@ -55,6 +53,7 @@ export const BlockDevicesView: Component = () => {
</For> </For>
)} )}
</Show> </Show>
)}
</div> </div>
</div> </div>
); );

View File

@@ -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>

View File

@@ -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" ];