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
| 1 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import type { TimestampFormat } from "@t3tools/contracts/settings"; |
| 3 | import { msg } from "gt-react"; |
| 4 | import { |
| 5 | pickSnoozePreset as pickSharedSnoozePreset, |
| 6 | resolveSnoozePresets as resolveSharedSnoozePresets, |
| 7 | snoozeWakeLabel, |
| 8 | type SnoozePreset, |
| 9 | } from "@t3tools/client-runtime/state/thread-settled"; |
| 10 | |
| 11 | import { m, type MessageResolver } from "../i18n/messages"; |
| 12 | import { appAtomRegistry } from "../rpc/atomRegistry"; |
| 13 | import { serverEnvironment } from "../state/server"; |
| 14 | import { formatShortTimestamp } from "../timestampFormat"; |
| 15 | import { toastManager } from "./ui/toast"; |
| 16 | |
| 17 | export { snoozeWakeLabel, type SnoozePreset }; |
| 18 | |
| 19 | /** The snooze menu for a thread, from its environment's presets, read when the menu opens. */ |
| 20 | export function resolveSnoozePresets( |
| 21 | now: Date, |
| 22 | timestampFormat: TimestampFormat, |
| 23 | environmentId: EnvironmentId, |
| 24 | resolve: MessageResolver = m, |
| 25 | ): ReadonlyArray<SnoozePreset> { |
| 26 | return resolveSharedSnoozePresets(now, snoozeOptions(timestampFormat, environmentId), resolve); |
| 27 | } |
| 28 | |
| 29 | /** A shown menu choice as picked; see the shared `pickSnoozePreset`. */ |
| 30 | export function pickSnoozePreset( |
| 31 | shown: ReadonlyArray<SnoozePreset>, |
| 32 | id: string, |
| 33 | timestampFormat: TimestampFormat, |
| 34 | environmentId: EnvironmentId, |
| 35 | resolve: MessageResolver = m, |
| 36 | ): SnoozePreset | undefined { |
| 37 | const picked = pickSharedSnoozePreset({ |
| 38 | shown, |
| 39 | id, |
| 40 | now: new Date(), |
| 41 | ...snoozeOptions(timestampFormat, environmentId), |
| 42 | resolve, |
| 43 | }); |
| 44 | if (!picked) { |
| 45 | toastManager.add({ |
| 46 | type: "warning", |
| 47 | title: resolve(msg("Could not snooze thread")), |
| 48 | description: resolve(msg("That snooze time has passed. Choose another time.")), |
| 49 | }); |
| 50 | } |
| 51 | return picked; |
| 52 | } |
| 53 | |
| 54 | function snoozeOptions(timestampFormat: TimestampFormat, environmentId: EnvironmentId) { |
| 55 | const presets = appAtomRegistry.get( |
| 56 | serverEnvironment.settingsValueAtom(environmentId), |
| 57 | )?.snoozePresets; |
| 58 | return { |
| 59 | ...(presets ? { presets } : {}), |
| 60 | formatTime: (date: Date) => formatShortTimestamp(date.toISOString(), timestampFormat), |
| 61 | }; |
| 62 | } |