Files
orca/mobile/src/components/load-error-description.ts
Kelvin Amoaba 563ada1343 feat(mobile): polish press feedback, sheet motion, states, spacing and layout jumps (#36713)
* feat(mobile): polish press feedback, sheet motion, states, spacing and layout jumps

Every control presses and disables the same way, with one haptic rule.
Sheets follow the finger and settle without bounce, pickers stack instead of
swapping, and screens slide over a dimmed, shifted parent. Loading, empty,
error and offline states share one view with plain-language errors, rows and
labels line up on one grid, and screens stop jumping as data arrives.

* fix(mobile): settle voice, tasks and accounts states; keep host snapshot current

Voice settings with no paired desktop shows the connect state instead of
loading forever. A failed task settings read after a successful probe retries
hydration. The shared host-list snapshot drops on invalidation and ignores
stale passes. Accounts shows a re-pair state on auth failure, and busy
action-sheet rows keep their disabled state for screen readers.
2026-11-01 02:45:03 +00:00

35 lines
1.3 KiB
TypeScript

import type { Translate } from '../i18n/mobile-i18n'
export type LoadErrorDescription = {
message: string
/** Raw host or transport text, shown only behind a Details disclosure. */
details: string | null
}
const TRANSPORT_FAILURE =
/\bE(CONNRESET|CONNREFUSED|TIMEDOUT|PIPE|NOTFOUND|HOSTUNREACH)\b|socket|connection (closed|lost|reset)|timed out/i
// Stack frames, Node error tags, RPC codes and method names are not sentences a person can act on.
const RAW_TEXT =
/\n|\bat \S+ \(|\(node:|\b[a-z]+_(error|not_found|failed)\b|\b[a-z]+\.[a-zA-Z]+ failed\b/
/** Turns a load failure into one translated sentence, keeping raw text for Details. */
export function describeLoadError(error: unknown, t: Translate): LoadErrorDescription {
const raw = (
error instanceof Error ? error.message : typeof error === 'string' ? error : ''
).trim()
const generic = t('common.loadError.generic', 'Something went wrong. Try again.')
if (!raw) {
return { message: generic, details: null }
}
if (TRANSPORT_FAILURE.test(raw)) {
return {
message: t('common.loadError.unreachable', "Couldn't reach the desktop. Try again."),
details: raw
}
}
if (RAW_TEXT.test(raw) || raw.length > 160) {
return { message: generic, details: raw }
}
return { message: raw, details: null }
}