chore(lint): flatten nested ternaries in host-runtime/host-page/providers

This commit is contained in:
Mohamed Boudra
2026-04-24 01:52:34 +07:00
parent 89eac88888
commit f9a6287423
3 changed files with 69 additions and 50 deletions

View File

@@ -254,20 +254,26 @@ function nextConnectionMachineState(input: {
}
if (event.type === "connect_failed") {
let failedConnectionId: string | null;
if (state.tag === "connecting" || state.tag === "online") {
failedConnectionId = state.activeConnectionId;
} else if (state.tag === "offline" || state.tag === "error") {
failedConnectionId = state.activeConnectionId;
} else {
failedConnectionId = null;
}
let failedConnection: ActiveConnection | null;
if (state.tag === "connecting" || state.tag === "online") {
failedConnection = state.activeConnection;
} else if (state.tag === "offline" || state.tag === "error") {
failedConnection = state.activeConnection;
} else {
failedConnection = null;
}
return {
tag: "error",
activeConnectionId:
state.tag === "connecting" || state.tag === "online"
? state.activeConnectionId
: state.tag === "offline" || state.tag === "error"
? state.activeConnectionId
: null,
activeConnection:
state.tag === "connecting" || state.tag === "online"
? state.activeConnection
: state.tag === "offline" || state.tag === "error"
? state.activeConnection
: null,
activeConnectionId: failedConnectionId,
activeConnection: failedConnection,
message: event.message,
};
}
@@ -280,18 +286,22 @@ function nextConnectionMachineState(input: {
};
}
const previousActiveConnectionId =
state.tag === "connecting" || state.tag === "online"
? state.activeConnectionId
: state.tag === "offline" || state.tag === "error"
? state.activeConnectionId
: null;
const previousActiveConnection =
state.tag === "connecting" || state.tag === "online"
? state.activeConnection
: state.tag === "offline" || state.tag === "error"
? state.activeConnection
: null;
let previousActiveConnectionId: string | null;
if (state.tag === "connecting" || state.tag === "online") {
previousActiveConnectionId = state.activeConnectionId;
} else if (state.tag === "offline" || state.tag === "error") {
previousActiveConnectionId = state.activeConnectionId;
} else {
previousActiveConnectionId = null;
}
let previousActiveConnection: ActiveConnection | null;
if (state.tag === "connecting" || state.tag === "online") {
previousActiveConnection = state.activeConnection;
} else if (state.tag === "offline" || state.tag === "error") {
previousActiveConnection = state.activeConnection;
} else {
previousActiveConnection = null;
}
if (!previousActiveConnectionId || !previousActiveConnection) {
return state.tag === "booting"

View File

@@ -94,22 +94,26 @@ export function HostPage({ serverId, onHostRemoved }: HostPageProps) {
const lastError = snapshot?.lastError ?? null;
const statusLabel = formatConnectionStatus(connectionStatus);
const statusTone = getConnectionStatusTone(connectionStatus);
const statusColor =
statusTone === "success"
? theme.colors.palette.green[400]
: statusTone === "warning"
? theme.colors.palette.amber[500]
: statusTone === "error"
? theme.colors.destructive
: theme.colors.foregroundMuted;
const statusPillBg =
statusTone === "success"
? "rgba(74, 222, 128, 0.1)"
: statusTone === "warning"
? "rgba(245, 158, 11, 0.1)"
: statusTone === "error"
? "rgba(248, 113, 113, 0.1)"
: "rgba(161, 161, 170, 0.1)";
let statusColor: string;
if (statusTone === "success") {
statusColor = theme.colors.palette.green[400];
} else if (statusTone === "warning") {
statusColor = theme.colors.palette.amber[500];
} else if (statusTone === "error") {
statusColor = theme.colors.destructive;
} else {
statusColor = theme.colors.foregroundMuted;
}
let statusPillBg: string;
if (statusTone === "success") {
statusPillBg = "rgba(74, 222, 128, 0.1)";
} else if (statusTone === "warning") {
statusPillBg = "rgba(245, 158, 11, 0.1)";
} else if (statusTone === "error") {
statusPillBg = "rgba(248, 113, 113, 0.1)";
} else {
statusPillBg = "rgba(161, 161, 170, 0.1)";
}
const connectionBadge = formatActiveConnectionBadge(activeConnection, theme);
const versionBadgeText = formatDaemonVersionBadge(daemonVersion);
const connectionError =

View File

@@ -15,6 +15,19 @@ import { RotateCw } from "lucide-react-native";
type ProviderDefinition = ReturnType<typeof buildProviderDefinitions>[number];
type ProviderEntry = NonNullable<ReturnType<typeof useProvidersSnapshot>["entries"]>[number];
function getProviderStatusLabel(status: string): string {
if (status === "ready") return "Available";
if (status === "error") return "Error";
if (status === "loading") return "Loading...";
return "Not installed";
}
function getProviderStatusVariant(status: string): "success" | "error" | "muted" {
if (status === "ready") return "success";
if (status === "error") return "error";
return "muted";
}
interface ProviderRowProps {
def: ProviderDefinition;
entry: ProviderEntry | undefined;
@@ -57,16 +70,8 @@ function ProviderRow({ def, entry, isFirst, onPress }: ProviderRowProps) {
) : null}
</View>
<StatusBadge
label={
status === "ready"
? "Available"
: status === "error"
? "Error"
: status === "loading"
? "Loading..."
: "Not installed"
}
variant={status === "ready" ? "success" : status === "error" ? "error" : "muted"}
label={getProviderStatusLabel(status)}
variant={getProviderStatusVariant(status)}
/>
</Pressable>
);