// Shared outcome handling for inline save statuses: the caller shows the // returned string next to the control, and screen readers hear it too. import type { ResultAsync } from 'neverthrow'; import { announce } from '@design-system'; import { m } from '@web/paraglide/messages'; import type { ApiError } from './api'; // The shared failure path: error line + assertive announcement. export function errorStatus(e: ApiError): string { const message = m.common_error({ message: e.message }); announce(message, 'assertive'); return message; } // Awaits a save, applies the value, announces the outcome and returns the // status line to display. export async function saveStatus( result: ResultAsync, okMessage: string, apply?: (value: T) => void, ): Promise { return result.match((value) => { apply?.(value); announce(okMessage); return okMessage; }, errorStatus); }