import { useState, type ReactNode } from "react"; import { View, Text, TextInput, FlatList, TouchableOpacity, StyleSheet, ActivityIndicator, } from "react-native"; import { searchBooks } from "../api/books"; import type { Book, PaginatedResponse } from "@cloud-reader/shared"; export default function SearchScreen(): ReactNode { const [query, setQuery] = useState(""); const [results, setResults] = useState([]); const [loading, setLoading] = useState(false); const [searched, setSearched] = useState(false); const handleSearch = async () => { if (!query.trim()) return; setLoading(true); setSearched(true); try { const data: PaginatedResponse = await searchBooks(query.trim()); setResults(data.results); } catch { setResults([]); } finally { setLoading(false); } }; const renderBook = ({ item }: { item: Book }) => ( {item.title} {item.author} ); return ( {loading && ( )} {!loading && searched && results.length === 0 && ( No books found for "{query}" )} item.id} contentContainerStyle={styles.list} /> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#0f0f23", }, searchBar: { padding: 16, borderBottomWidth: 1, borderBottomColor: "#333", }, input: { backgroundColor: "#1a1a2e", borderRadius: 8, padding: 14, fontSize: 16, color: "#fff", borderWidth: 1, borderColor: "#333", }, centered: { flex: 1, justifyContent: "center", alignItems: "center", padding: 24, }, list: { padding: 16, }, resultCard: { backgroundColor: "#1a1a2e", borderRadius: 12, padding: 16, marginBottom: 8, borderWidth: 1, borderColor: "#333", }, resultTitle: { fontSize: 16, fontWeight: "600", color: "#fff", marginBottom: 4, }, resultAuthor: { fontSize: 14, color: "#888", }, noResults: { fontSize: 16, color: "#888", textAlign: "center", }, });