@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 55 lines 1.93 KB
Raw
1 import type { RelayClientDeviceRecord } from "@t3tools/contracts/relay";
2 import { msg } from "gt-react";
3
4 import { m, type MessageResolver } from "~/i18n/messages";
5
6 const mobileClientUpdatedAtFormatter = new Intl.DateTimeFormat(undefined, {
7 dateStyle: "medium",
8 timeStyle: "short",
9 });
10
11 const NOTIFICATION_PREFERENCES = [
12 ["notifyOnApproval", msg("approvals")],
13 ["notifyOnInput", msg("input requests")],
14 ["notifyOnCompletion", msg("completions")],
15 ["notifyOnFailure", msg("failures")],
16 ] as const satisfies ReadonlyArray<
17 readonly [keyof RelayClientDeviceRecord["notifications"], string]
18 >;
19
20 export function mobileClientPlatformLabel(device: RelayClientDeviceRecord): string {
21 const platform =
22 device.platform === "android"
23 ? "Android"
24 : device.iosMajorVersion === null
25 ? "iOS"
26 : `iOS ${device.iosMajorVersion}`;
27 return `${platform}${device.appVersion ? ` · T3 Code ${device.appVersion}` : ""}`;
28 }
29
30 /** Components pass `useMessages()` so the detail follows a language switch. */
31 export function mobileClientNotificationDetail(
32 device: RelayClientDeviceRecord,
33 resolve: MessageResolver = m,
34 ): string {
35 if (!device.notifications.enabled) {
36 return resolve(msg("Push notifications are disabled on this device."));
37 }
38
39 const enabledPreferences = NOTIFICATION_PREFERENCES.flatMap(([preference, label]) =>
40 device.notifications[preference] ? [resolve(label)] : [],
41 );
42 return enabledPreferences.length > 0
43 ? resolve(msg("Alerts enabled for {alerts}.", { alerts: enabledPreferences.join(", ") }))
44 : resolve(msg("Push notifications are enabled, but no alert types are selected."));
45 }
46
47 export function mobileClientUpdatedAtLabel(
48 updatedAt: string,
49 resolve: MessageResolver = m,
50 ): string {
51 const date = new Date(updatedAt);
52 return Number.isNaN(date.getTime())
53 ? resolve(msg("Update time unavailable"))
54 : resolve(msg("Updated {date}", { date: mobileClientUpdatedAtFormatter.format(date) }));
55 }