feat: mobile app complet + flashcards fixes + drag handle améliorations
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:
@@ -28,3 +28,60 @@ export async function GET(
|
||||
|
||||
return NextResponse.json({ note })
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { id } = await params
|
||||
const { title, content } = await req.json().catch(() => ({}))
|
||||
|
||||
const existing = await prisma.note.findFirst({ where: { id, userId, trashedAt: null } })
|
||||
if (!existing) return NextResponse.json({ error: 'Note introuvable' }, { status: 404 })
|
||||
|
||||
const htmlContent = content !== undefined ? buildHtmlContent(content) : existing.content
|
||||
|
||||
const note = await prisma.note.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...(title?.trim() ? { title: title.trim() } : {}),
|
||||
content: htmlContent,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
select: { id: true, title: true, updatedAt: true },
|
||||
})
|
||||
|
||||
return NextResponse.json({ note })
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { id } = await params
|
||||
const note = await prisma.note.findFirst({ where: { id, userId, trashedAt: null } })
|
||||
if (!note) return NextResponse.json({ error: 'Note introuvable' }, { status: 404 })
|
||||
|
||||
await prisma.note.update({ where: { id }, data: { trashedAt: new Date() } })
|
||||
return NextResponse.json({ ok: true })
|
||||
}
|
||||
|
||||
function buildHtmlContent(text: string): string {
|
||||
if (!text.trim()) return '<p></p>'
|
||||
if (text.trimStart().startsWith('<')) return text
|
||||
return text
|
||||
.split('\n')
|
||||
.map((line) => `<p>${line.trim() ? escapeHtml(line) : ''}</p>`)
|
||||
.join('')
|
||||
}
|
||||
|
||||
function escapeHtml(s: string) {
|
||||
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
}
|
||||
|
||||
|
||||
59
memento-note/app/api/mobile/notes/daily/route.ts
Normal file
59
memento-note/app/api/mobile/notes/daily/route.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
|
||||
function getTodayKey(): string {
|
||||
return new Date().toISOString().slice(0, 10) // YYYY-MM-DD — clé de recherche interne
|
||||
}
|
||||
|
||||
function getTodayTitle(): string {
|
||||
return new Date().toLocaleDateString('fr-FR', {
|
||||
weekday: 'long', year: 'numeric', month: 'long', day: 'numeric',
|
||||
})
|
||||
// ex : "vendredi 29 mai 2026"
|
||||
}
|
||||
|
||||
function getTodayContent(title: string): string {
|
||||
// HTML simple lisible par la WebView mobile
|
||||
return `<h1>📅 ${title}</h1><p></p>`
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const todayKey = getTodayKey()
|
||||
const todayTitle = getTodayTitle()
|
||||
|
||||
// Chercher par clé ISO (titre interne) ou par titre lisible (migration)
|
||||
let note = await prisma.note.findFirst({
|
||||
where: {
|
||||
userId,
|
||||
type: 'daily',
|
||||
trashedAt: null,
|
||||
title: { in: [todayKey, todayTitle] },
|
||||
},
|
||||
})
|
||||
|
||||
if (!note) {
|
||||
note = await prisma.note.create({
|
||||
data: {
|
||||
userId,
|
||||
title: todayTitle,
|
||||
content: getTodayContent(todayTitle),
|
||||
type: 'daily',
|
||||
color: '#FEF9C3',
|
||||
labels: JSON.stringify(['daily']),
|
||||
},
|
||||
})
|
||||
} else if (note.title === todayKey) {
|
||||
// Migrer l'ancien titre ISO → titre lisible
|
||||
const htmlContent = getTodayContent(todayTitle)
|
||||
note = await prisma.note.update({
|
||||
where: { id: note.id },
|
||||
data: { title: todayTitle, content: htmlContent },
|
||||
})
|
||||
}
|
||||
|
||||
return NextResponse.json({ id: note.id, note })
|
||||
}
|
||||
@@ -41,3 +41,43 @@ export async function GET(req: NextRequest) {
|
||||
...(notebookName ? { notebookName } : {}),
|
||||
})
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { title, content, notebookId } = await req.json().catch(() => ({}))
|
||||
if (!title?.trim()) return NextResponse.json({ error: 'Titre requis' }, { status: 400 })
|
||||
|
||||
// Convertir le texte brut en HTML TipTap simple si nécessaire
|
||||
const htmlContent = buildHtmlContent(content ?? '')
|
||||
|
||||
const note = await prisma.note.create({
|
||||
data: {
|
||||
userId,
|
||||
title: title.trim(),
|
||||
content: htmlContent,
|
||||
type: 'richtext',
|
||||
...(notebookId ? { notebookId } : {}),
|
||||
},
|
||||
select: { id: true, title: true, updatedAt: true },
|
||||
})
|
||||
|
||||
return NextResponse.json({ note }, { status: 201 })
|
||||
}
|
||||
|
||||
/** Convertit du texte brut multiligne en paragraphes HTML TipTap */
|
||||
function buildHtmlContent(text: string): string {
|
||||
if (!text.trim()) return '<p></p>'
|
||||
// Si déjà du HTML, retourner tel quel
|
||||
if (text.trimStart().startsWith('<')) return text
|
||||
return text
|
||||
.split('\n')
|
||||
.map((line) => `<p>${line.trim() ? escapeHtml(line) : ''}</p>`)
|
||||
.join('')
|
||||
}
|
||||
|
||||
function escapeHtml(s: string) {
|
||||
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user