Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadSync.ts

39 lines1.1 KB

1import type { EnvironmentThreadStatus } from "@t3tools/client-runtime/state/threads";
2import { msg } from "gt-react";
3​
4import { m, type MessageResolver } from "./i18n/messages";
5​
6export type ThreadSyncPhase = "loading" | "syncing" | "failed";
7​
8export function resolveThreadSyncPhase(input: {
9 readonly detailExists: boolean;
10 readonly shellExists: boolean;
11 readonly status: EnvironmentThreadStatus;
12 readonly hasError: boolean;
13}): ThreadSyncPhase | null {
14 if (!input.shellExists) {
15 return null;
16 }
17​
18 switch (input.status) {
19 case "empty":
20 case "cached":
21 case "synchronizing":
22 if (!input.detailExists) return "loading";
23 return input.hasError ? "failed" : "syncing";
24 case "deleted":
25 case "live":
26 return null;
27 }
29​
30export function threadSyncLabel(phase: ThreadSyncPhase, resolve: MessageResolver = m): string {
31 switch (phase) {
32 case "loading":
33 return resolve(msg("Loading messages..."));
34 case "syncing":
35 return resolve(msg("Syncing messages..."));
36 case "failed":
37 return resolve(msg("Could not sync messages"));
38 }