import React, { useEffect, useRef, useState } from "react"; import { api } from "./api.js"; import { Spinner } from "./ui.jsx"; export default function Library({ onOpen }) { const [books, setBooks] = useState(null); const [uploading, setUploading] = useState(false); const [error, setError] = useState(null); const fileRef = useRef(); const refresh = () => api.listBooks().then(setBooks).catch((e) => setError(String(e))); useEffect(() => { refresh(); }, []); const upload = async (file) => { if (!file) return; setUploading(true); setError(null); try { const { slug } = await api.uploadBook(file); await refresh(); onOpen(slug); } catch (e) { setError("Échec de l'import : " + e); } finally { setUploading(false); } }; return (
Déposez un fichier EPUB
ou
upload(e.target.files[0])} />{error}
}Aucun livre pour l'instant.
) : (