formatter.nix: Add prettier

This commit is contained in:
Qubasa
2024-08-02 18:56:53 +02:00
parent 3e9ebbc90f
commit fb4ceebccf
23 changed files with 272 additions and 252 deletions

View File

@@ -134,19 +134,21 @@ export const callApi = <K extends OperationNames>(
});
};
const deserialize = <T>(fn: (response: T) => void) => (str: string) => {
try {
const r = JSON.parse(str) as T;
console.log("Received: ", r);
fn(r);
} catch (e) {
console.log("Error parsing JSON: ", e);
window.localStorage.setItem("error", str);
console.error(str);
console.error("See localStorage 'error'");
alert(`Error parsing JSON: ${e}`);
}
};
const deserialize =
<T>(fn: (response: T) => void) =>
(str: string) => {
try {
const r = JSON.parse(str) as T;
console.log("Received: ", r);
fn(r);
} catch (e) {
console.log("Error parsing JSON: ", e);
window.localStorage.setItem("error", str);
console.error(str);
console.error("See localStorage 'error'");
alert(`Error parsing JSON: ${e}`);
}
};
// Create the API object

View File

@@ -94,18 +94,21 @@ export const MachineListItem = (props: MachineListItemProps) => {
<div class="flex flex-row flex-wrap gap-4 py-2">
<div class="badge badge-primary flex flex-row gap-1 py-4 align-middle">
<span>System:</span>
{hwInfo()[name]?.system
? <span class="text-primary">{hwInfo()[name]?.system}</span>
: <span class="text-warning">Not set</span>}
{hwInfo()[name]?.system ? (
<span class="text-primary">{hwInfo()[name]?.system}</span>
) : (
<span class="text-warning">Not set</span>
)}
</div>
<div class="badge badge-ghost flex flex-row gap-1 py-4 align-middle">
<span>Target Host:</span>
{deploymentInfo()[name]
? <span class="text-primary">{deploymentInfo()[name]}</span>
: <span class="text-warning">Not set</span>}
{
/* <Show
{deploymentInfo()[name] ? (
<span class="text-primary">{deploymentInfo()[name]}</span>
) : (
<span class="text-warning">Not set</span>
)}
{/* <Show
when={deploymentInfo()[name]}
fallback={
<Switch fallback={<div class="skeleton h-8 w-full"></div>}>
@@ -116,8 +119,7 @@ export const MachineListItem = (props: MachineListItemProps) => {
}
>
{(i) => + i()}
</Show> */
}
</Show> */}
</div>
</div>
{/* Show only the first error at the bottom */}

View File

@@ -1,10 +1,10 @@
@import 'material-icons/iconfont/filled.css';
@import "material-icons/iconfont/filled.css";
/* List of icons: https://marella.me/material-icons/demo/ */
@tailwind base;
@tailwind components;
@tailwind utilities;
html {
overflow-x: hidden;
overflow-y: scroll;
}
overflow-x: hidden;
overflow-y: scroll;
}

View File

@@ -32,8 +32,7 @@ export const Layout: Component<LayoutProps> = (props) => {
for="toplevel-drawer"
aria-label="close sidebar"
class="drawer-overlay"
>
</label>
></label>
<Sidebar route={route} setRoute={setRoute} />
</div>
</div>

View File

@@ -27,35 +27,35 @@ export const BlockDevicesView: Component = () => {
</button>
</div>
<div class="flex max-w-screen-lg flex-col gap-4">
{isFetching
? <span class="loading loading-bars"></span>
: (
<Show when={devices}>
{(devices) => (
<For each={devices().blockdevices}>
{(device) => (
<div class="stats shadow">
<div class="stat w-28 py-8">
<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 class="stat w-28">
<div class="stat-title">Size</div>
<div class="stat-value">{device.size}</div>
<div class="stat-desc"></div>
{isFetching ? (
<span class="loading loading-bars"></span>
) : (
<Show when={devices}>
{(devices) => (
<For each={devices().blockdevices}>
{(device) => (
<div class="stats shadow">
<div class="stat w-28 py-8">
<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>
)}
</For>
)}
</Show>
)}
<div class="stat w-28">
<div class="stat-title">Size</div>
<div class="stat-value">{device.size}</div>
<div class="stat-desc"></div>
</div>
</div>
)}
</For>
)}
</Show>
)}
</div>
</div>
);

View File

@@ -1,16 +1,14 @@
import { route } from "@/src/App";
import { callApi, OperationArgs, OperationResponse, pyApi } from "@/src/api";
import { callApi, OperationResponse } from "@/src/api";
import {
createForm,
required,
FieldValues,
setValue,
SubmitHandler,
} from "@modular-forms/solid";
import { createQuery } from "@tanstack/solid-query";
import { createEffect, createSignal, For } from "solid-js";
import { effect } from "solid-js/web";
type FlashFormValues = {
interface FlashFormValues extends FieldValues {
machine: {
devicePath: string;
flake: string;
@@ -19,7 +17,7 @@ type FlashFormValues = {
language: string;
keymap: string;
sshKeys: string[];
};
}
type BlockDevices = Extract<
OperationResponse<"show_block_devices">,
@@ -59,10 +57,7 @@ export const Flash = () => {
}
});
const {
data: devices,
isFetching,
} = createQuery(() => ({
const { data: devices, isFetching } = createQuery(() => ({
queryKey: ["block_devices"],
queryFn: async () => {
const result = await callApi("show_block_devices", {});
@@ -72,10 +67,7 @@ export const Flash = () => {
staleTime: 1000 * 60 * 2, // 1 minutes
}));
const {
data: keymaps,
isFetching: isFetchingKeymaps,
} = createQuery(() => ({
const { data: keymaps, isFetching: isFetchingKeymaps } = createQuery(() => ({
queryKey: ["list_keymaps"],
queryFn: async () => {
const result = await callApi("list_possible_keymaps", {});
@@ -85,18 +77,17 @@ export const Flash = () => {
staleTime: 1000 * 60 * 15, // 15 minutes
}));
const {
data: languages,
isFetching: isFetchingLanguages,
} = createQuery(() => ({
queryKey: ["list_languages"],
queryFn: async () => {
const result = await callApi("list_possible_languages", {});
if (result.status === "error") throw new Error("Failed to fetch data");
return result.data;
},
staleTime: 1000 * 60 * 15, // 15 minutes
}));
const { data: languages, isFetching: isFetchingLanguages } = createQuery(
() => ({
queryKey: ["list_languages"],
queryFn: async () => {
const result = await callApi("list_possible_languages", {});
if (result.status === "error") throw new Error("Failed to fetch data");
return result.data;
},
staleTime: 1000 * 60 * 15, // 15 minutes
}),
);
const handleSubmit = async (values: FlashFormValues) => {
setIsFlashing(true);
@@ -109,7 +100,7 @@ export const Flash = () => {
},
},
mode: "format",
disks: { "main": values.disk },
disks: { main: values.disk },
system_config: {
language: values.language,
keymap: values.keymap,
@@ -191,7 +182,9 @@ export const Flash = () => {
class="select select-bordered w-full"
{...props}
>
<option value="" disabled>Select a disk</option>
<option value="" disabled>
Select a disk
</option>
<For each={devices?.blockdevices}>
{(device) => (
<option value={device.path}>
@@ -227,11 +220,7 @@ export const Flash = () => {
>
<option>en_US.UTF-8</option>
<For each={languages}>
{(language) => (
<option value={language}>
{language}
</option>
)}
{(language) => <option value={language}>{language}</option>}
</For>
</select>
<div class="label">
@@ -261,17 +250,12 @@ export const Flash = () => {
>
<option>en</option>
<For each={keymaps}>
{(keymap) => (
<option value={keymap}>
{keymap}
</option>
)}
{(keymap) => <option value={keymap}>{keymap}</option>}
</For>
</select>
<div class="label">
{isFetchingKeymaps && (
<span class="label-text
-alt">
<span class="label-text-alt">
<span class="loading loading-bars"></span>
</span>
)}
@@ -312,9 +296,11 @@ export const Flash = () => {
)}
</Field>
<button class="btn btn-error" type="submit" disabled={isFlashing()}>
{isFlashing()
? <span class="loading loading-spinner"></span>
: <span class="material-icons">bolt</span>}
{isFlashing() ? (
<span class="loading loading-spinner"></span>
) : (
<span class="material-icons">bolt</span>
)}
{isFlashing() ? "Flashing..." : "Flash Installer"}
</button>
</Form>

View File

@@ -91,8 +91,7 @@ export const MachineListView: Component = () => {
<span class="material-icons ">add</span>
</button>
</div>
{
/* <Show when={services()}>
{/* <Show when={services()}>
{(services) => (
<For each={Object.values(services())}>
{(service) => (
@@ -138,8 +137,7 @@ export const MachineListView: Component = () => {
)}
</For>
)}
</Show> */
}
</Show> */}
<Switch>
<Match when={loading()}>
{/* Loading skeleton */}

View File

@@ -33,17 +33,17 @@ export const registerClan = async () => {
});
console.log({ loc }, loc.status);
if (loc.status === "success" && loc.data) {
// @ts-expect-error: data is a string
const data = loc.data[0];
setClanList((s) => {
const res = new Set([...s, loc.data]);
const res = new Set([...s, data]);
return Array.from(res);
});
setActiveURI(loc.data);
setActiveURI(data);
setRoute((r) => {
if (r === "welcome") return "machines";
return r;
});
return loc.data;
return data;
}
} catch (e) {
//
@@ -145,7 +145,7 @@ const ClanDetails = (props: ClanDetailsProps) => {
return false;
}
return true;
})
}),
);
}}
>