()
| 12 | type RegistryEntry = { key: string; model: CactusModel }; |
| 13 | |
| 14 | const ModelBrowserScreen = () => { |
| 15 | const [entries, setEntries] = useState<RegistryEntry[]>([]); |
| 16 | const [filtered, setFiltered] = useState<RegistryEntry[]>([]); |
| 17 | const [search, setSearch] = useState(''); |
| 18 | const [loading, setLoading] = useState(true); |
| 19 | const [error, setError] = useState<string | null>(null); |
| 20 | |
| 21 | useEffect(() => { |
| 22 | getRegistry() |
| 23 | .then((registry) => { |
| 24 | const list = Object.entries(registry).map(([key, model]) => ({ |
| 25 | key, |
| 26 | model, |
| 27 | })); |
| 28 | list.sort((a, b) => a.key.localeCompare(b.key)); |
| 29 | setEntries(list); |
| 30 | setFiltered(list); |
| 31 | }) |
| 32 | .catch((e: unknown) => |
| 33 | setError(e instanceof Error ? e.message : String(e)) |
| 34 | ) |
| 35 | .finally(() => setLoading(false)); |
| 36 | }, []); |
| 37 | |
| 38 | useEffect(() => { |
| 39 | const q = search.trim().toLowerCase(); |
| 40 | setFiltered(q ? entries.filter((e) => e.key.includes(q)) : entries); |
| 41 | }, [search, entries]); |
| 42 | |
| 43 | if (loading) { |
| 44 | return ( |
| 45 | <View style={styles.center}> |
| 46 | <ActivityIndicator size="large" /> |
| 47 | <Text style={styles.loadingText}>Loading model registry...</Text> |
| 48 | </View> |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | if (error) { |
| 53 | return ( |
| 54 | <View style={styles.center}> |
| 55 | <Text style={styles.errorText}>{error}</Text> |
| 56 | </View> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | return ( |
| 61 | <View style={styles.container}> |
| 62 | <TextInput |
| 63 | style={styles.search} |
| 64 | value={search} |
| 65 | onChangeText={setSearch} |
| 66 | placeholder="Search models..." |
| 67 | placeholderTextColor="#666" |
| 68 | clearButtonMode="while-editing" |
| 69 | /> |
| 70 | <Text style={styles.count}> |
| 71 | {filtered.length} of {entries.length} models |
nothing calls this directly
no test coverage detected