'use client' import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import Link from 'next/link' import './note-library.css' import { FileDown, Layers, X } from 'lucide-react' import { exportNoteFlashcards, noteRequest } from '@/lib/notes-api' import PickerShell from '@/components/common/PickerShell' interface Card { page_id: string page_title: string block_id: string card_id: string front: string back: string } export default function NoteReview() { const { t } = useTranslation() const [cards, setCards] = useState([]) const [open, setOpen] = useState(false) const [revealed, setRevealed] = useState(false) const [error, setError] = useState('') const [busy, setBusy] = useState(false) useEffect(() => { void noteRequest<{ cards: Card[] }>('/review/due') .then(r => setCards(r.cards)) .catch(e => setError(String(e))) }, []) const card = cards[0] const exportAll = async () => { setBusy(true) try { const blob = await exportNoteFlashcards() const url = URL.createObjectURL(blob) const link = document.createElement('a') link.href = url link.download = 'deeptutor-flashcards.txt' link.click() setTimeout(() => URL.revokeObjectURL(url), 1000) } catch (err) { setError(String(err)) } finally { setBusy(false) } } const grade = async (remembered: boolean) => { setBusy(true) try { await noteRequest(`/${card.page_id}/review`, { card_id: card.card_id, remembered }) setCards(c => c.slice(1)) setRevealed(false) } catch (err) { setError(String(err)) } finally { setBusy(false) } } if (!cards.length && !open) return null return ( <> setOpen(false)} ariaLabel={t('Review flashcards')}>
{t('Review flashcards')} {card && {t('{{count}} left', { count: cards.length })}}
{card ? ( <>

{card.front}

{revealed &&

{card.back}

}
{t('From “{{page}}”', { page: card.page_title || t('Untitled') })} ↗
{revealed ? ( <> ) : ( )}
) : (
🎉

{t('All caught up')}

)} {error && (

{error}

)}
) }