feat: mobile app complet + flashcards fixes + drag handle améliorations
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m32s
CI / Deploy production (on server) (push) Has been skipped

Mobile app:
- Révision flashcards : liste decks, session flip-card SM-2, couleurs harmonisées web
- Génération flashcards depuis note (FlashcardSheet + route /api/mobile/flashcards/generate)
- Audio Whisper : hook useAudioRecorder reécrit, MicButton avec erreurs
- IA : AISheet (améliorer/clarifier/résumer), TitleSheet (titre automatique)
- Suppression note (soft delete + confirmation Alert)
- Note du jour : titre lisible + HTML (plus JSON TipTap brut)
- Parser TipTap→HTML côté mobile (tipTapToHtml)
- Icône 🎓 dans header note → génération flashcards
- Endpoint flashcardGenerate dans config.ts

Web fixes:
- Bug flashcards groupées par carnet → deck par note (migration + schema)
- Bug filtre 'cartes dues' ignoré (suppression fallback buildSessionQueue)
- Suppression UI création deck manuelle (inutile)
- Fix setViewType is not defined dans home-client.tsx

Drag handle menu:
- Fix : clearNodes() avant transformation (heading→liste/code/citation)
- Ajout : option 'Texte' (paragraphe) dans Transformer en
- Ajout : Monter / Descendre le bloc
- Ajout : Copier le contenu du bloc
- Fix : sous-menu hover stable (délai 200ms)
- Fix : Supprimer en rouge via classe --danger (plus :first-child)
- i18n : nouvelles clés dans 15 locales

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Antigravity
2026-05-29 18:49:40 +00:00
parent 1121b8c345
commit 0fa8978395
54 changed files with 2648 additions and 245 deletions

View File

@@ -0,0 +1,37 @@
import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { getMobileUserId } from '@/lib/mobile-auth'
export async function GET(req: NextRequest) {
const userId = getMobileUserId(req)
if (!userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const now = new Date()
const decks = await prisma.flashcardDeck.findMany({
where: { userId },
include: {
notebook: { select: { name: true } },
flashcards: {
select: {
id: true,
interval: true,
nextReviewAt: true,
front: true,
},
},
},
orderBy: { updatedAt: 'desc' },
})
const result = decks.map((deck) => ({
id: deck.id,
name: deck.name,
notebookId: deck.notebookId,
notebookName: deck.notebook?.name ?? null,
totalCards: deck.flashcards.length,
dueCount: deck.flashcards.filter((c) => c.nextReviewAt <= now).length,
masteredCount: deck.flashcards.filter((c) => c.interval >= 7).length,
}))
return NextResponse.json({ decks: result })
}

View File

@@ -0,0 +1,84 @@
import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { getMobileUserId } from '@/lib/mobile-auth'
import { generateFlashcardsFromNote, type FlashcardStyle } from '@/lib/flashcards/generate-flashcards'
import { stripHtmlToText } from '@/lib/flashcards/deck-utils'
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
export async function POST(req: NextRequest) {
const userId = getMobileUserId(req)
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
const body = await req.json().catch(() => ({}))
const noteId = typeof body.noteId === 'string' ? body.noteId : null
const count = typeof body.count === 'number' ? Math.min(body.count, 20) : 10
const styleRaw = typeof body.style === 'string' ? body.style : 'qa'
const style: FlashcardStyle = ['qa', 'cloze', 'concept'].includes(styleRaw) ? (styleRaw as FlashcardStyle) : 'qa'
if (!noteId) return NextResponse.json({ error: 'noteId requis' }, { status: 400 })
const note = await prisma.note.findFirst({
where: { id: noteId, userId, trashedAt: null },
select: { id: true, title: true, content: true, notebookId: true, language: true },
})
if (!note) return NextResponse.json({ error: 'Note introuvable' }, { status: 404 })
const textContent = stripHtmlToText(note.content)
if (textContent.length < 80) {
return NextResponse.json({ error: 'Contenu insuffisant pour générer des flashcards (minimum 80 caractères)' }, { status: 400 })
}
try {
await checkEntitlementOrThrow(userId, 'ai_flashcard')
} catch (err) {
if (err instanceof QuotaExceededError) {
return NextResponse.json({ error: err.currentQuota === 0 ? 'Fonctionnalité non disponible sur votre abonnement' : 'Quota IA atteint' }, { status: 402 })
}
throw err
}
const cards = await generateFlashcardsFromNote({
title: note.title || 'Sans titre',
textContent,
count,
style,
language: note.language || undefined,
})
if (cards.length === 0) {
return NextResponse.json({ error: 'Génération échouée — aucune carte produite' }, { status: 500 })
}
// Chercher un deck existant pour cette note, ou en créer un
const existing = await prisma.flashcard.findFirst({
where: { noteId: note.id, deck: { userId } },
select: { deckId: true },
})
let deckId: string
if (existing) {
deckId = existing.deckId
// Supprimer les anciennes cartes pour les remplacer
await prisma.flashcard.deleteMany({ where: { noteId: note.id, deckId } })
} else {
const deck = await prisma.flashcardDeck.create({
data: { userId, notebookId: note.notebookId, name: note.title || 'Sans titre' },
})
deckId = deck.id
}
await prisma.flashcard.createMany({
data: cards.map((c) => ({
deckId,
noteId: note.id,
front: c.front,
back: c.back,
type: c.type,
})),
})
await prisma.flashcardDeck.update({ where: { id: deckId }, data: { updatedAt: new Date() } })
incrementUsageAsync(userId, 'ai_flashcard')
return NextResponse.json({ deckId, count: cards.length, cards })
}

View File

@@ -0,0 +1,40 @@
import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { getMobileUserId } from '@/lib/mobile-auth'
import { computeSm2Update } from '@/lib/flashcards/sm2'
export async function POST(req: NextRequest) {
const userId = getMobileUserId(req)
if (!userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const body = await req.json()
const cardId = typeof body.cardId === 'string' ? body.cardId : null
const grade = typeof body.grade === 'number' ? body.grade : null
if (!cardId || grade === null || grade < 1 || grade > 4) {
return NextResponse.json({ error: 'cardId and grade (14) required' }, { status: 400 })
}
const card = await prisma.flashcard.findFirst({
where: { id: cardId, deck: { userId } },
select: { id: true, interval: true, easinessFactor: true },
})
if (!card) return NextResponse.json({ error: 'Card not found' }, { status: 404 })
const { easinessFactor, interval, nextReviewAt } = computeSm2Update(grade, {
easinessFactor: card.easinessFactor,
interval: card.interval,
})
await prisma.$transaction([
prisma.flashcard.update({
where: { id: cardId },
data: { easinessFactor, interval, nextReviewAt },
}),
prisma.flashcardReview.create({
data: { cardId, grade, reviewedAt: new Date() },
}),
])
return NextResponse.json({ ok: true, nextReviewAt, interval })
}

View File

@@ -0,0 +1,38 @@
import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { getMobileUserId } from '@/lib/mobile-auth'
export async function GET(req: NextRequest) {
const userId = getMobileUserId(req)
if (!userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const { searchParams } = new URL(req.url)
const deckId = searchParams.get('deckId')
const limit = Math.min(parseInt(searchParams.get('limit') ?? '20', 10), 50)
if (!deckId) return NextResponse.json({ error: 'deckId required' }, { status: 400 })
// Vérifier ownership
const deck = await prisma.flashcardDeck.findFirst({
where: { id: deckId, userId },
select: { id: true, name: true },
})
if (!deck) return NextResponse.json({ error: 'Deck not found' }, { status: 404 })
const now = new Date()
const cards = await prisma.flashcard.findMany({
where: { deckId, nextReviewAt: { lte: now } },
select: {
id: true,
front: true,
back: true,
interval: true,
easinessFactor: true,
type: true,
},
orderBy: { nextReviewAt: 'asc' },
take: limit,
})
return NextResponse.json({ deck: { id: deck.id, name: deck.name }, cards })
}