UI: fix type breakages

This commit is contained in:
Johannes Kirschbauer
2024-12-06 19:53:03 +01:00
parent 0c47a29f38
commit 11ba85eedd
3 changed files with 22 additions and 22 deletions

View File

@@ -29,7 +29,7 @@ export const MachineListItem = (props: MachineListItemProps) => {
const navigate = useNavigate(); const navigate = useNavigate();
const handleInstall = async () => { const handleInstall = async () => {
if (!info?.deploy.targetHost || installing()) { if (!info?.deploy?.targetHost || installing()) {
return; return;
} }
@@ -38,9 +38,9 @@ export const MachineListItem = (props: MachineListItemProps) => {
toast.error("No active clan selected"); toast.error("No active clan selected");
return; return;
} }
if (!info?.deploy.targetHost) { if (!info?.deploy?.targetHost) {
toast.error( toast.error(
"Machine does not have a target host. Specify where the machine should be deployed.", "Machine does not have a target host. Specify where the machine should be deployed."
); );
return; return;
} }
@@ -63,13 +63,13 @@ export const MachineListItem = (props: MachineListItemProps) => {
loading: "Installing...", loading: "Installing...",
success: "Installed", success: "Installed",
error: "Failed to install", error: "Failed to install",
}, }
); );
setInstalling(false); setInstalling(false);
}; };
const handleUpdate = async () => { const handleUpdate = async () => {
if (!info?.deploy.targetHost || installing()) { if (!info?.deploy?.targetHost || installing()) {
return; return;
} }
@@ -80,7 +80,7 @@ export const MachineListItem = (props: MachineListItemProps) => {
} }
if (!info?.deploy.targetHost) { if (!info?.deploy.targetHost) {
toast.error( toast.error(
"Machine does not have a target host. Specify where the machine should be deployed.", "Machine does not have a target host. Specify where the machine should be deployed."
); );
return; return;
} }
@@ -101,7 +101,7 @@ export const MachineListItem = (props: MachineListItemProps) => {
loading: "Updating...", loading: "Updating...",
success: "Updated", success: "Updated",
error: "Failed to update", error: "Failed to update",
}, }
); );
setUpdating(false); setUpdating(false);
}; };
@@ -158,7 +158,7 @@ export const MachineListItem = (props: MachineListItemProps) => {
</span> </span>
)} )}
</Show> </Show>
{d()?.deploy.targetHost} {d()?.deploy?.targetHost}
</> </>
)} )}
</Show> </Show>
@@ -182,24 +182,24 @@ export const MachineListItem = (props: MachineListItemProps) => {
</li> </li>
<li <li
classList={{ classList={{
disabled: !info?.deploy.targetHost || installing(), disabled: !info?.deploy?.targetHost || installing(),
}} }}
onClick={handleInstall} onClick={handleInstall}
> >
<a> <a>
<Show when={info?.deploy.targetHost} fallback={"Deploy"}> <Show when={info?.deploy?.targetHost} fallback={"Deploy"}>
{(d) => `Install to ${d()}`} {(d) => `Install to ${d()}`}
</Show> </Show>
</a> </a>
</li> </li>
<li <li
classList={{ classList={{
disabled: !info?.deploy.targetHost || updating(), disabled: !info?.deploy?.targetHost || updating(),
}} }}
onClick={handleUpdate} onClick={handleUpdate}
> >
<a> <a>
<Show when={info?.deploy.targetHost} fallback={"Deploy"}> <Show when={info?.deploy?.targetHost} fallback={"Deploy"}>
{(d) => `Update (${d()})`} {(d) => `Update (${d()})`}
</Show> </Show>
</a> </a>

View File

@@ -65,7 +65,7 @@ const InstallMachine = (props: InstallMachineProps) => {
} }
const loading_toast = toast.loading( const loading_toast = toast.loading(
"Installing machine. Grab coffee (15min)...", "Installing machine. Grab coffee (15min)..."
); );
const r = await callApi("install_machine", { const r = await callApi("install_machine", {
opts: { opts: {
@@ -243,18 +243,18 @@ const MachineForm = (props: MachineDetailsProps) => {
const machine_response = await callApi("set_machine", { const machine_response = await callApi("set_machine", {
flake_url: curr_uri, flake_url: curr_uri,
machine_name: props.initialData.machine.name, machine_name: props.initialData.machine.name || "My machine",
machine: { machine: {
...values.machine, ...values.machine,
// TODO: Remove this workaround // TODO: Remove this workaround
tags: Array.from( tags: Array.from(
values.machine.tags || props.initialData.machine.tags || [], values.machine.tags || props.initialData.machine.tags || []
), ),
}, },
}); });
if (machine_response.status === "error") { if (machine_response.status === "error") {
toast.error( toast.error(
`Failed to set machine: ${machine_response.errors[0].message}`, `Failed to set machine: ${machine_response.errors[0].message}`
); );
} }
if (machine_response.status === "success") { if (machine_response.status === "success") {
@@ -316,7 +316,7 @@ const MachineForm = (props: MachineDetailsProps) => {
} }
> >
<div class="w-32 rounded-lg border p-2 bg-def-4 border-inv-3"> <div class="w-32 rounded-lg border p-2 bg-def-4 border-inv-3">
<RndThumbnail name={machineName()} /> <RndThumbnail name={machineName() || "M"} />
</div> </div>
</div> </div>
</figure> </figure>
@@ -342,7 +342,7 @@ const MachineForm = (props: MachineDetailsProps) => {
{(tag) => ( {(tag) => (
<label class="p-1"> <label class="p-1">
Tags Tags
<span class="mx-2 rounded-full px-3 py-1 bg-inv-4 fg-inv-1 w-fit"> <span class="mx-2 w-fit rounded-full px-3 py-1 bg-inv-4 fg-inv-1">
{tag} {tag}
</span> </span>
</label> </label>
@@ -455,7 +455,7 @@ const MachineForm = (props: MachineDetailsProps) => {
// disabled={!online()} // disabled={!online()}
onClick={() => { onClick={() => {
const modal = document.getElementById( const modal = document.getElementById(
"install_modal", "install_modal"
) as HTMLDialogElement | null; ) as HTMLDialogElement | null;
modal?.showModal(); modal?.showModal();
}} }}
@@ -561,7 +561,7 @@ function WifiModule(props: MachineWifiProps) {
}); });
const [nets, setNets] = createSignal<1[]>( const [nets, setNets] = createSignal<1[]>(
new Array(props.initialData.length || 1).fill(1), new Array(props.initialData.length || 1).fill(1)
); );
const handleSubmit = async (values: WifiForm) => { const handleSubmit = async (values: WifiForm) => {
@@ -572,7 +572,7 @@ function WifiModule(props: MachineWifiProps) {
...acc, ...acc,
[curr.ssid || ""]: { ssid: curr.ssid, password: curr.password }, [curr.ssid || ""]: { ssid: curr.ssid, password: curr.password },
}), }),
{}, {}
); );
console.log("submitting", values, networks); console.log("submitting", values, networks);

View File

@@ -84,7 +84,7 @@ export const MachineListView: Component = () => {
</div> </div>
{/* <Show when={filter()}> */} {/* <Show when={filter()}> */}
<div class="my-1 flex w-full gap-2 p-2"> <div class="my-1 flex w-full gap-2 p-2">
<div class="h-6 w-6 p-1"> <div class="size-6 p-1">
<Icon icon="Filter" /> <Icon icon="Filter" />
</div> </div>
<For each={filter().tags.sort()}> <For each={filter().tags.sort()}>