summaryrefslogtreecommitdiffhomepage
path: root/src/features/computer/logic/view-model.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-26 22:21:55 +0900
committerAdam Malczewski <[email protected]>2026-06-26 22:23:39 +0900
commitc333fcec32b1f90bf0da6bb14d2609c20e38a74f (patch)
tree0db3ec77a6838c4f800c362df0de3c6cd8544431 /src/features/computer/logic/view-model.ts
parent1285564f12238b22f6b39b9f3fbcecaca8456911 (diff)
downloaddispatch-web-c333fcec32b1f90bf0da6bb14d2609c20e38a74f.tar.gz
dispatch-web-c333fcec32b1f90bf0da6bb14d2609c20e38a74f.zip
style: switch from tabs to 2-space indentation (incl. svelte)
Diffstat (limited to 'src/features/computer/logic/view-model.ts')
-rw-r--r--src/features/computer/logic/view-model.ts170
1 files changed, 85 insertions, 85 deletions
diff --git a/src/features/computer/logic/view-model.ts b/src/features/computer/logic/view-model.ts
index 944456b..d489fb5 100644
--- a/src/features/computer/logic/view-model.ts
+++ b/src/features/computer/logic/view-model.ts
@@ -24,29 +24,29 @@ import type { Computer, ComputerEntry } from "@dispatch/wire";
/** Outcome of `PUT /conversations/:id/computer`; `null` when no real conversation is focused. */
export type ComputerSaveResult =
- | { readonly ok: true; readonly computerId: string | null }
- | { readonly ok: false; readonly error: string };
+ | { readonly ok: true; readonly computerId: string | null }
+ | { readonly ok: false; readonly error: string };
export type SaveComputer = (computerId: string | null) => Promise<ComputerSaveResult | null>;
/** Outcome of `GET /computers`; `null` when the list couldn't be loaded. */
export type ComputerListResult =
- | { readonly ok: true; readonly computers: readonly ComputerEntry[] }
- | { readonly ok: false; readonly error: string };
+ | { readonly ok: true; readonly computers: readonly ComputerEntry[] }
+ | { readonly ok: false; readonly error: string };
export type LoadComputers = () => Promise<ComputerListResult | null>;
/** Outcome of `GET /computers/:alias/status`; `null` when no alias / not loaded. */
export type ComputerStatusResult =
- | { readonly ok: true; readonly status: ComputerStatusResponse }
- | { readonly ok: false; readonly error: string };
+ | { readonly ok: true; readonly status: ComputerStatusResponse }
+ | { readonly ok: false; readonly error: string };
export type LoadComputerStatus = (alias: string) => Promise<ComputerStatusResult | null>;
/** Outcome of `POST /computers/:alias/test`. */
export type TestComputerResult =
- | { readonly ok: true; readonly response: TestComputerResponse }
- | { readonly ok: false; readonly error: string };
+ | { readonly ok: true; readonly response: TestComputerResponse }
+ | { readonly ok: false; readonly error: string };
export type TestComputer = (alias: string) => Promise<TestComputerResult | null>;
@@ -55,16 +55,16 @@ export type TestComputer = (alias: string) => Promise<TestComputerResult | null>
export type Badge = "success" | "warning" | "error" | "neutral";
export interface ComputerView {
- /** The SSH config `Host` alias — also the `computerId` users select. */
- readonly alias: string;
- /** A compact `user@host:port` connection string (the resolved config values). */
- readonly hostSummary: string;
- /** The resolved `IdentityFile`, or `null` = default `~/.ssh/id_*`. */
- readonly identityFile: string | null;
- /** Short label for the known-host indicator, e.g. "known host" / "new host". */
- readonly knownHostLabel: string;
- /** Whether the host's key is already in `~/.ssh/known_hosts`. */
- readonly knownHost: boolean;
+ /** The SSH config `Host` alias — also the `computerId` users select. */
+ readonly alias: string;
+ /** A compact `user@host:port` connection string (the resolved config values). */
+ readonly hostSummary: string;
+ /** The resolved `IdentityFile`, or `null` = default `~/.ssh/id_*`. */
+ readonly identityFile: string | null;
+ /** Short label for the known-host indicator, e.g. "known host" / "new host". */
+ readonly knownHostLabel: string;
+ /** Whether the host's key is already in `~/.ssh/known_hosts`. */
+ readonly knownHost: boolean;
}
/**
@@ -74,28 +74,28 @@ export interface ComputerView {
* (the backend resolves this, but this is defensive).
*/
export function formatHost(computer: Computer): string {
- const host = computer.hostName || computer.alias;
- const port = computer.port === 22 ? "" : `:${computer.port}`;
- return `${computer.user}@${host}${port}`;
+ const host = computer.hostName || computer.alias;
+ const port = computer.port === 22 ? "" : `:${computer.port}`;
+ return `${computer.user}@${host}${port}`;
}
/** The display label for the known-host indicator. */
export function knownHostLabel(knownHost: boolean): string {
- return knownHost ? "known host" : "new host";
+ return knownHost ? "known host" : "new host";
}
export function viewComputer(computer: Computer): ComputerView {
- return {
- alias: computer.alias,
- hostSummary: formatHost(computer),
- identityFile: computer.identityFile,
- knownHostLabel: knownHostLabel(computer.knownHost),
- knownHost: computer.knownHost,
- };
+ return {
+ alias: computer.alias,
+ hostSummary: formatHost(computer),
+ identityFile: computer.identityFile,
+ knownHostLabel: knownHostLabel(computer.knownHost),
+ knownHost: computer.knownHost,
+ };
}
export function viewComputers(computers: readonly ComputerEntry[]): readonly ComputerView[] {
- return computers.map(viewComputer);
+ return computers.map(viewComputer);
}
/**
@@ -103,23 +103,23 @@ export function viewComputers(computers: readonly ComputerEntry[]): readonly Com
* discovered" (the latter is the expected state until the `ssh` extension lands).
*/
export function summarizeComputers(computers: readonly ComputerEntry[]): string {
- if (computers.length === 0) return "No computers discovered";
- return `${computers.length} computer${computers.length === 1 ? "" : "s"}`;
+ if (computers.length === 0) return "No computers discovered";
+ return `${computers.length} computer${computers.length === 1 ? "" : "s"}`;
}
// ── Connection status → display view ──────────────────────────────────────────
export interface ComputerStatusView {
- readonly alias: string;
- readonly state: ComputerStatusResponse["state"];
- readonly statusLabel: string;
- readonly badge: Badge;
- /** True while the state is transient (show a spinner). */
- readonly busy: boolean;
- /** The error reason when `state === "error"`, else null. */
- readonly error: string | null;
- /** Whether the host's key is already in `~/.ssh/known_hosts`. */
- readonly knownHost: boolean;
+ readonly alias: string;
+ readonly state: ComputerStatusResponse["state"];
+ readonly statusLabel: string;
+ readonly badge: Badge;
+ /** True while the state is transient (show a spinner). */
+ readonly busy: boolean;
+ /** The error reason when `state === "error"`, else null. */
+ readonly error: string | null;
+ /** Whether the host's key is already in `~/.ssh/known_hosts`. */
+ readonly knownHost: boolean;
}
/**
@@ -130,55 +130,55 @@ export interface ComputerStatusView {
* idle state, NOT busy), `error`→error.
*/
export function viewComputerStatus(status: ComputerStatusResponse): ComputerStatusView {
- let statusLabel: string;
- let badge: Badge;
- let busy = false;
- switch (status.state) {
- case "connected":
- statusLabel = "Connected";
- badge = "success";
- break;
- case "connecting":
- statusLabel = "Connecting…";
- badge = "warning";
- busy = true;
- break;
- case "disconnected":
- statusLabel = "Disconnected";
- badge = "neutral";
- break;
- case "error":
- statusLabel = "Error";
- badge = "error";
- break;
- }
- return {
- alias: status.alias,
- state: status.state,
- statusLabel,
- badge,
- busy,
- error: status.state === "error" ? (status.error ?? "Connection failed") : null,
- knownHost: status.knownHost,
- };
+ let statusLabel: string;
+ let badge: Badge;
+ let busy = false;
+ switch (status.state) {
+ case "connected":
+ statusLabel = "Connected";
+ badge = "success";
+ break;
+ case "connecting":
+ statusLabel = "Connecting…";
+ badge = "warning";
+ busy = true;
+ break;
+ case "disconnected":
+ statusLabel = "Disconnected";
+ badge = "neutral";
+ break;
+ case "error":
+ statusLabel = "Error";
+ badge = "error";
+ break;
+ }
+ return {
+ alias: status.alias,
+ state: status.state,
+ statusLabel,
+ badge,
+ busy,
+ error: status.state === "error" ? (status.error ?? "Connection failed") : null,
+ knownHost: status.knownHost,
+ };
}
// ── Test-connection result → display view ───────────────────────────────────
export interface TestResultView {
- readonly alias: string;
- readonly ok: boolean;
- /** The failure reason when `ok` is false, else null. */
- readonly error: string | null;
- /** A short result label, e.g. "Connection OK" / "Failed". */
- readonly label: string;
+ readonly alias: string;
+ readonly ok: boolean;
+ /** The failure reason when `ok` is false, else null. */
+ readonly error: string | null;
+ /** A short result label, e.g. "Connection OK" / "Failed". */
+ readonly label: string;
}
export function viewTestResult(response: TestComputerResponse): TestResultView {
- return {
- alias: response.alias,
- ok: response.ok,
- error: response.ok ? null : (response.error ?? "Connection failed"),
- label: response.ok ? "Connection OK" : "Failed",
- };
+ return {
+ alias: response.alias,
+ ok: response.ok,
+ error: response.ok ? null : (response.error ?? "Connection failed"),
+ label: response.ok ? "Connection OK" : "Failed",
+ };
}