The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection"; |
| 2 | import type { EnvironmentThreadStatus } from "@t3tools/client-runtime/state/threads"; |
| 3 | import { msg } from "gt-react-native"; |
| 4 | |
| 5 | import { m, type MessageResolver } from "../../i18n/messages"; |
| 6 | |
| 7 | export type ThreadContentPresentation = |
| 8 | | { readonly kind: "ready" } |
| 9 | | { readonly kind: "loading" } |
| 10 | | { |
| 11 | readonly kind: "unavailable"; |
| 12 | readonly title: string; |
| 13 | readonly detail: string; |
| 14 | }; |
| 15 | |
| 16 | export function projectThreadContentPresentation(input: { |
| 17 | readonly hasDetail: boolean; |
| 18 | readonly detailError: string | null; |
| 19 | readonly detailDeleted: boolean; |
| 20 | readonly connectionState: EnvironmentConnectionPhase; |
| 21 | readonly resolve?: MessageResolver; |
| 22 | }): ThreadContentPresentation { |
| 23 | const resolve = input.resolve ?? m; |
| 24 | if (input.hasDetail) { |
| 25 | return { kind: "ready" }; |
| 26 | } |
| 27 | if (input.detailDeleted) { |
| 28 | return { |
| 29 | kind: "unavailable", |
| 30 | title: resolve(msg("Thread unavailable")), |
| 31 | detail: resolve(msg("This thread was deleted or is no longer available.")), |
| 32 | }; |
| 33 | } |
| 34 | if (input.detailError !== null) { |
| 35 | return { |
| 36 | kind: "unavailable", |
| 37 | title: resolve(msg("Could not load conversation")), |
| 38 | detail: input.detailError, |
| 39 | }; |
| 40 | } |
| 41 | if ( |
| 42 | input.connectionState === "connected" || |
| 43 | input.connectionState === "connecting" || |
| 44 | input.connectionState === "reconnecting" |
| 45 | ) { |
| 46 | return { kind: "loading" }; |
| 47 | } |
| 48 | return { |
| 49 | kind: "unavailable", |
| 50 | title: resolve(msg("Messages not cached")), |
| 51 | detail: resolve(msg("Reconnect this environment to load the conversation.")), |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | export function threadSyncStatusLabel( |
| 56 | status: EnvironmentThreadStatus, |
| 57 | presentation: ThreadContentPresentation["kind"], |
| 58 | resolve: MessageResolver = m, |
| 59 | ): string | null { |
| 60 | if (status !== "empty" && status !== "cached" && status !== "synchronizing") return null; |
| 61 | if (presentation === "ready") return resolve(msg("Syncing messages…")); |
| 62 | return presentation === "loading" ? resolve(msg("Loading messages…")) : null; |
| 63 | } |