The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { mFallback, msg } from "gt-i18n"; |
| 3 | import type { MFunctionType } from "gt-i18n/types"; |
| 4 | |
| 5 | export const SAVED_VIEW_NAME_MAX_LENGTH = 80; |
| 6 | |
| 7 | export const SavedViewIdentity = Schema.Struct({ |
| 8 | id: Schema.String.check(Schema.isMinLength(1)), |
| 9 | name: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(SAVED_VIEW_NAME_MAX_LENGTH)), |
| 10 | }); |
| 11 | |
| 12 | export function savedViewNameError( |
| 13 | name: string, |
| 14 | views: ReadonlyArray<typeof SavedViewIdentity.Type>, |
| 15 | editingId?: string, |
| 16 | resolve: MFunctionType = mFallback, |
| 17 | ): string | null { |
| 18 | const trimmed = name.trim(); |
| 19 | if (!trimmed) return resolve(msg("Enter a name for this view.")); |
| 20 | if (trimmed.length > SAVED_VIEW_NAME_MAX_LENGTH) { |
| 21 | return resolve(msg("Use {max} characters or fewer.", { max: SAVED_VIEW_NAME_MAX_LENGTH })); |
| 22 | } |
| 23 | return views.some( |
| 24 | (view) => view.id !== editingId && view.name.toLowerCase() === trimmed.toLowerCase(), |
| 25 | ) |
| 26 | ? resolve(msg("A view with this name already exists.")) |
| 27 | : null; |
| 28 | } |