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