The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { T, useGT, Var } from "gt-react-native"; |
| 2 | import { NativeScrollView } from "../../native/NativeScrollViewMarker"; |
| 3 | import { LegendList } from "@legendapp/list/react-native"; |
| 4 | import { useAtomValue } from "@effect/atom-react"; |
| 5 | import type { StaticScreenProps } from "@react-navigation/native"; |
| 6 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 7 | import { AsyncResult } from "effect/reactivity"; |
| 8 | import { useState } from "react"; |
| 9 | import { Platform, View } from "react-native"; |
| 10 | |
| 11 | import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator"; |
| 12 | import { AppText as Text } from "../../components/ui/AppText"; |
| 13 | import { EmptyState } from "../../components/ui/EmptyState"; |
| 14 | import { cn } from "../../lib/cn"; |
| 15 | import { useEnvironments } from "../../state/environments"; |
| 16 | import { voiceSpeechBenchmarksAtom } from "../voice-input/voiceDestination"; |
| 17 | import { PullRequestSearchSheet } from "../pull-requests/PullRequestSearchSheet"; |
| 18 | import { useVoiceModels, VoiceModelRow } from "./VoiceModelSection"; |
| 19 | |
| 20 | export function SettingsVoiceModelsRouteScreen({ |
| 21 | route, |
| 22 | }: StaticScreenProps<{ readonly environmentId: EnvironmentId }>) { |
| 23 | const gt = useGT(); |
| 24 | const { environments } = useEnvironments(); |
| 25 | const label = |
| 26 | environments.find((environment) => environment.environmentId === route.params.environmentId) |
| 27 | ?.label ?? gt("This environment"); |
| 28 | const voice = useVoiceModels(route.params.environmentId, label); |
| 29 | const benchmarks = new Map( |
| 30 | ( |
| 31 | AsyncResult.getOrElse( |
| 32 | useAtomValue(voiceSpeechBenchmarksAtom(route.params.environmentId)), |
| 33 | () => null, |
| 34 | )?.models ?? [] |
| 35 | ).map((model) => [model.id, model.benchmark]), |
| 36 | ); |
| 37 | const language = new Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0]!.toLowerCase(); |
| 38 | const [query, setQuery] = useState(""); |
| 39 | const needle = query.trim().toLowerCase(); |
| 40 | // Catalog order, not state order: re-sorting when a download finishes would move rows under a tap. |
| 41 | const models = voice.models |
| 42 | .map((model) => { |
| 43 | const benchmark = benchmarks.get(model.id); |
| 44 | return benchmark ? { ...model, benchmark } : model; |
| 45 | }) |
| 46 | .filter((model) => |
| 47 | `${model.name} ${model.description} ${model.languages.join(" ")}` |
| 48 | .toLowerCase() |
| 49 | .includes(needle), |
| 50 | ); |
| 51 | return ( |
| 52 | <PullRequestSearchSheet |
| 53 | title={gt("Transcription models")} |
| 54 | placeholder={gt("Search models or languages")} |
| 55 | closeAccessibilityLabel={gt("Close transcription models")} |
| 56 | clearAccessibilityLabel={gt("Clear model search")} |
| 57 | query={query} |
| 58 | onQueryChange={setQuery} |
| 59 | > |
| 60 | {({ paddingBottom }) => ( |
| 61 | <LegendList |
| 62 | renderScrollComponent={NativeScrollView} |
| 63 | data={models} |
| 64 | keyExtractor={(model) => model.id} |
| 65 | extraData={{ voice, language, count: models.length }} |
| 66 | estimatedItemSize={72} |
| 67 | recycleItems |
| 68 | className="flex-1" |
| 69 | contentInsetAdjustmentBehavior="automatic" |
| 70 | automaticallyAdjustKeyboardInsets={Platform.OS === "ios"} |
| 71 | keyboardDismissMode={Platform.OS === "ios" ? "interactive" : "on-drag"} |
| 72 | keyboardShouldPersistTaps="handled" |
| 73 | showsVerticalScrollIndicator={false} |
| 74 | contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 16, paddingBottom }} |
| 75 | ListHeaderComponent={ |
| 76 | voice.canManage ? undefined : ( |
| 77 | <Text className="pb-3 text-xs text-foreground-muted"> |
| 78 | <T> |
| 79 | This connection can’t change settings on <Var>{label}</Var>. |
| 80 | </T> |
| 81 | </Text> |
| 82 | ) |
| 83 | } |
| 84 | renderItem={({ item, index }) => ( |
| 85 | <View |
| 86 | className={cn( |
| 87 | "overflow-hidden", |
| 88 | index === 0 && "rounded-t-2xl", |
| 89 | index === models.length - 1 && "rounded-b-2xl", |
| 90 | )} |
| 91 | > |
| 92 | <VoiceModelRow model={item} voice={voice} separated={index > 0} language={language} /> |
| 93 | </View> |
| 94 | )} |
| 95 | ListEmptyComponent={ |
| 96 | voice.loading ? ( |
| 97 | <AppActivityIndicator className="my-8" /> |
| 98 | ) : ( |
| 99 | <EmptyState |
| 100 | title={needle ? gt("No models match") : gt("No transcription models")} |
| 101 | detail={ |
| 102 | needle |
| 103 | ? gt("Try another name or language.") |
| 104 | : gt("{environment} has no models to list.", { environment: label }) |
| 105 | } |
| 106 | variant="plain" |
| 107 | /> |
| 108 | ) |
| 109 | } |
| 110 | /> |
| 111 | )} |
| 112 | </PullRequestSearchSheet> |
| 113 | ); |
| 114 | } |