import { useState, useEffect, useCallback, type ReactNode } from "react"; import { View, Text, Image, FlatList, TouchableOpacity, StyleSheet, ActivityIndicator, RefreshControl, } from "react-native"; import { ebooksApi } from "../api/ebooks"; import type { EBookListItem } from "@cloud-reader/shared"; export default function LibraryScreen({ navigation, }: { navigation: any; }): ReactNode { const [books, setBooks] = useState([]); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const loadBooks = useCallback(async () => { try { const { data } = await ebooksApi.list(); setBooks(data.results); } catch { // Silent error for now; pull-to-refresh lets the user retry. } finally { setLoading(false); setRefreshing(false); } }, []); useEffect(() => { loadBooks(); }, [loadBooks]); const onRefresh = () => { setRefreshing(true); loadBooks(); }; const renderBook = ({ item }: { item: EBookListItem }) => { const progress = typeof item.progress === "number" ? Math.round(item.progress) : null; return ( navigation.navigate("BookDetail", { ebookId: item.id })} > {item.cover_image ? ( ) : ( {item.title.charAt(0).toUpperCase()} )} {item.title} {item.author || "Unknown author"} {item.format?.toUpperCase()} {progress !== null ? ` ยท ${progress}% read` : ""} ); }; if (loading && books.length === 0) { return ( ); } return ( String(item.id)} contentContainerStyle={styles.list} refreshControl={ } ListEmptyComponent={ Your library is empty Upload books from the web app to get started } /> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#0f0f23", }, centered: { flex: 1, justifyContent: "center", alignItems: "center", padding: 24, }, list: { padding: 16, flexGrow: 1, }, bookCard: { flexDirection: "row", backgroundColor: "#1a1a2e", borderRadius: 12, padding: 12, marginBottom: 12, borderWidth: 1, borderColor: "#333", }, bookCover: { width: 60, height: 80, backgroundColor: "#2a2a4e", borderRadius: 8, justifyContent: "center", alignItems: "center", }, coverText: { fontSize: 24, fontWeight: "bold", color: "#4f8ef7", }, bookInfo: { flex: 1, marginLeft: 12, justifyContent: "center", }, bookTitle: { fontSize: 16, fontWeight: "600", color: "#fff", marginBottom: 4, }, bookAuthor: { fontSize: 14, color: "#888", marginBottom: 4, }, bookMeta: { fontSize: 12, color: "#666", }, emptyText: { fontSize: 18, fontWeight: "600", color: "#888", marginBottom: 8, }, emptySubtext: { fontSize: 14, color: "#666", textAlign: "center", }, });