feat(Notes): add folderId to note creation and update processes, enhance folder handling in NotesPageClient
This commit is contained in:
@@ -55,13 +55,6 @@ export async function PUT(
|
||||
const body = await request.json();
|
||||
const { title, content, taskId, folderId, tags } = body;
|
||||
|
||||
console.log(
|
||||
'[API PUT /notes/:id] Updating note:',
|
||||
resolvedParams.id,
|
||||
'with body:',
|
||||
body
|
||||
);
|
||||
|
||||
const note = await notesService.updateNote(
|
||||
resolvedParams.id,
|
||||
session.user.id,
|
||||
@@ -74,8 +67,6 @@ export async function PUT(
|
||||
}
|
||||
);
|
||||
|
||||
console.log('[API PUT /notes/:id] Note updated:', note);
|
||||
|
||||
return NextResponse.json({ note });
|
||||
} catch (error) {
|
||||
console.error('Error updating note:', error);
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { title, content, taskId, tags } = body;
|
||||
const { title, content, taskId, folderId, tags } = body;
|
||||
|
||||
if (!title || !content) {
|
||||
return NextResponse.json(
|
||||
@@ -60,6 +60,7 @@ export async function POST(request: Request) {
|
||||
content,
|
||||
userId: session.user.id,
|
||||
taskId,
|
||||
folderId,
|
||||
tags,
|
||||
});
|
||||
|
||||
|
||||
@@ -67,10 +67,23 @@ function NotesPageContent({
|
||||
|
||||
const handleCreateNote = useCallback(async () => {
|
||||
try {
|
||||
// Déterminer le folderId : null si "Toutes les notes" ou "Non classées", sinon le dossier actif
|
||||
const targetFolderId =
|
||||
!selectedFolderId || selectedFolderId === '__uncategorized__'
|
||||
? undefined
|
||||
: selectedFolderId;
|
||||
|
||||
console.log(
|
||||
'[handleCreateNote] selectedFolderId:',
|
||||
selectedFolderId,
|
||||
'targetFolderId:',
|
||||
targetFolderId
|
||||
);
|
||||
|
||||
const newNote = await notesClient.createNote({
|
||||
title: 'Nouvelle note',
|
||||
content: '# Nouvelle note\n\nCommencez à écrire...',
|
||||
folderId: selectedFolderId || undefined,
|
||||
folderId: targetFolderId,
|
||||
});
|
||||
|
||||
setNotes((prev) => [newNote, ...prev]);
|
||||
@@ -132,12 +145,29 @@ function NotesPageContent({
|
||||
// setIsSaving(true);
|
||||
setError(null);
|
||||
|
||||
const updatedNote = await notesClient.updateNote(selectedNote.id, {
|
||||
// Construire l'objet de mise à jour en incluant explicitement les champs
|
||||
const updateData: {
|
||||
content: string;
|
||||
tags?: string[];
|
||||
taskId?: string;
|
||||
folderId?: string | null;
|
||||
} = {
|
||||
content: selectedNote.content,
|
||||
tags: selectedNote.tags,
|
||||
taskId: selectedNote.taskId,
|
||||
folderId: selectedNote.folderId,
|
||||
});
|
||||
};
|
||||
|
||||
// Ajouter taskId et folderId seulement s'ils sont définis
|
||||
if (selectedNote.taskId !== undefined) {
|
||||
updateData.taskId = selectedNote.taskId;
|
||||
}
|
||||
if (selectedNote.folderId !== undefined) {
|
||||
updateData.folderId = selectedNote.folderId;
|
||||
}
|
||||
|
||||
const updatedNote = await notesClient.updateNote(
|
||||
selectedNote.id,
|
||||
updateData
|
||||
);
|
||||
|
||||
// Mettre à jour la liste des notes mais pas selectedNote pour éviter la perte de focus
|
||||
setNotes((prev) =>
|
||||
@@ -180,13 +210,6 @@ function NotesPageContent({
|
||||
async (folderId: string | null) => {
|
||||
if (!selectedNote) return;
|
||||
|
||||
console.log(
|
||||
'[handleFolderChange] Changing folder for note:',
|
||||
selectedNote.id,
|
||||
'to folder:',
|
||||
folderId
|
||||
);
|
||||
|
||||
try {
|
||||
// Sauvegarder immédiatement
|
||||
const updateData: { folderId: string | null } = {
|
||||
@@ -197,8 +220,6 @@ function NotesPageContent({
|
||||
updateData
|
||||
);
|
||||
|
||||
console.log('[handleFolderChange] Note updated:', updatedNote);
|
||||
|
||||
// Mettre à jour la liste des notes
|
||||
setNotes((prev) =>
|
||||
prev.map((note) => (note.id === selectedNote.id ? updatedNote : note))
|
||||
@@ -207,7 +228,7 @@ function NotesPageContent({
|
||||
// Mettre à jour la note sélectionnée
|
||||
setSelectedNote(updatedNote);
|
||||
} catch (err) {
|
||||
console.error('[handleFolderChange] Error:', err);
|
||||
console.error('Error changing folder:', err);
|
||||
setError('Erreur lors du changement de dossier');
|
||||
}
|
||||
},
|
||||
@@ -270,21 +291,12 @@ function NotesPageContent({
|
||||
// Gérer le drop d'une note sur un dossier
|
||||
const handleNoteDrop = useCallback(
|
||||
async (noteId: string, folderId: string | null) => {
|
||||
console.log(
|
||||
'[handleNoteDrop] Dropping note:',
|
||||
noteId,
|
||||
'to folder:',
|
||||
folderId
|
||||
);
|
||||
|
||||
try {
|
||||
const updateData: { folderId: string | null } = {
|
||||
folderId: folderId,
|
||||
};
|
||||
const updatedNote = await notesClient.updateNote(noteId, updateData);
|
||||
|
||||
console.log('[handleNoteDrop] Note updated:', updatedNote);
|
||||
|
||||
// Mettre à jour la liste des notes
|
||||
setNotes((prev) =>
|
||||
prev.map((note) => (note.id === noteId ? updatedNote : note))
|
||||
@@ -298,7 +310,7 @@ function NotesPageContent({
|
||||
// Recharger les dossiers pour mettre à jour les compteurs
|
||||
handleFoldersChange();
|
||||
} catch (err) {
|
||||
console.error('[handleNoteDrop] Error:', err);
|
||||
console.error('Error moving note:', err);
|
||||
setError('Erreur lors du déplacement de la note');
|
||||
}
|
||||
},
|
||||
|
||||
@@ -68,14 +68,7 @@ export class NotesClient extends HttpClient {
|
||||
* Met à jour une note existante
|
||||
*/
|
||||
async updateNote(id: string, data: UpdateNoteData): Promise<Note> {
|
||||
console.log(
|
||||
'[notesClient.updateNote] Updating note:',
|
||||
id,
|
||||
'with data:',
|
||||
data
|
||||
);
|
||||
const response = await this.put<NoteResponse>(`/${id}`, data);
|
||||
console.log('[notesClient.updateNote] Response:', response);
|
||||
return response.note;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user