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 body = await request.json();
|
||||||
const { title, content, taskId, folderId, tags } = body;
|
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(
|
const note = await notesService.updateNote(
|
||||||
resolvedParams.id,
|
resolvedParams.id,
|
||||||
session.user.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 });
|
return NextResponse.json({ note });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating note:', error);
|
console.error('Error updating note:', error);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { title, content, taskId, tags } = body;
|
const { title, content, taskId, folderId, tags } = body;
|
||||||
|
|
||||||
if (!title || !content) {
|
if (!title || !content) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -60,6 +60,7 @@ export async function POST(request: Request) {
|
|||||||
content,
|
content,
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
taskId,
|
taskId,
|
||||||
|
folderId,
|
||||||
tags,
|
tags,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -67,10 +67,23 @@ function NotesPageContent({
|
|||||||
|
|
||||||
const handleCreateNote = useCallback(async () => {
|
const handleCreateNote = useCallback(async () => {
|
||||||
try {
|
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({
|
const newNote = await notesClient.createNote({
|
||||||
title: 'Nouvelle note',
|
title: 'Nouvelle note',
|
||||||
content: '# Nouvelle note\n\nCommencez à écrire...',
|
content: '# Nouvelle note\n\nCommencez à écrire...',
|
||||||
folderId: selectedFolderId || undefined,
|
folderId: targetFolderId,
|
||||||
});
|
});
|
||||||
|
|
||||||
setNotes((prev) => [newNote, ...prev]);
|
setNotes((prev) => [newNote, ...prev]);
|
||||||
@@ -132,12 +145,29 @@ function NotesPageContent({
|
|||||||
// setIsSaving(true);
|
// setIsSaving(true);
|
||||||
setError(null);
|
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,
|
content: selectedNote.content,
|
||||||
tags: selectedNote.tags,
|
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
|
// Mettre à jour la liste des notes mais pas selectedNote pour éviter la perte de focus
|
||||||
setNotes((prev) =>
|
setNotes((prev) =>
|
||||||
@@ -180,13 +210,6 @@ function NotesPageContent({
|
|||||||
async (folderId: string | null) => {
|
async (folderId: string | null) => {
|
||||||
if (!selectedNote) return;
|
if (!selectedNote) return;
|
||||||
|
|
||||||
console.log(
|
|
||||||
'[handleFolderChange] Changing folder for note:',
|
|
||||||
selectedNote.id,
|
|
||||||
'to folder:',
|
|
||||||
folderId
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Sauvegarder immédiatement
|
// Sauvegarder immédiatement
|
||||||
const updateData: { folderId: string | null } = {
|
const updateData: { folderId: string | null } = {
|
||||||
@@ -197,8 +220,6 @@ function NotesPageContent({
|
|||||||
updateData
|
updateData
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('[handleFolderChange] Note updated:', updatedNote);
|
|
||||||
|
|
||||||
// Mettre à jour la liste des notes
|
// Mettre à jour la liste des notes
|
||||||
setNotes((prev) =>
|
setNotes((prev) =>
|
||||||
prev.map((note) => (note.id === selectedNote.id ? updatedNote : note))
|
prev.map((note) => (note.id === selectedNote.id ? updatedNote : note))
|
||||||
@@ -207,7 +228,7 @@ function NotesPageContent({
|
|||||||
// Mettre à jour la note sélectionnée
|
// Mettre à jour la note sélectionnée
|
||||||
setSelectedNote(updatedNote);
|
setSelectedNote(updatedNote);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[handleFolderChange] Error:', err);
|
console.error('Error changing folder:', err);
|
||||||
setError('Erreur lors du changement de dossier');
|
setError('Erreur lors du changement de dossier');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -270,21 +291,12 @@ function NotesPageContent({
|
|||||||
// Gérer le drop d'une note sur un dossier
|
// Gérer le drop d'une note sur un dossier
|
||||||
const handleNoteDrop = useCallback(
|
const handleNoteDrop = useCallback(
|
||||||
async (noteId: string, folderId: string | null) => {
|
async (noteId: string, folderId: string | null) => {
|
||||||
console.log(
|
|
||||||
'[handleNoteDrop] Dropping note:',
|
|
||||||
noteId,
|
|
||||||
'to folder:',
|
|
||||||
folderId
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updateData: { folderId: string | null } = {
|
const updateData: { folderId: string | null } = {
|
||||||
folderId: folderId,
|
folderId: folderId,
|
||||||
};
|
};
|
||||||
const updatedNote = await notesClient.updateNote(noteId, updateData);
|
const updatedNote = await notesClient.updateNote(noteId, updateData);
|
||||||
|
|
||||||
console.log('[handleNoteDrop] Note updated:', updatedNote);
|
|
||||||
|
|
||||||
// Mettre à jour la liste des notes
|
// Mettre à jour la liste des notes
|
||||||
setNotes((prev) =>
|
setNotes((prev) =>
|
||||||
prev.map((note) => (note.id === noteId ? updatedNote : note))
|
prev.map((note) => (note.id === noteId ? updatedNote : note))
|
||||||
@@ -298,7 +310,7 @@ function NotesPageContent({
|
|||||||
// Recharger les dossiers pour mettre à jour les compteurs
|
// Recharger les dossiers pour mettre à jour les compteurs
|
||||||
handleFoldersChange();
|
handleFoldersChange();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[handleNoteDrop] Error:', err);
|
console.error('Error moving note:', err);
|
||||||
setError('Erreur lors du déplacement de la note');
|
setError('Erreur lors du déplacement de la note');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -68,14 +68,7 @@ export class NotesClient extends HttpClient {
|
|||||||
* Met à jour une note existante
|
* Met à jour une note existante
|
||||||
*/
|
*/
|
||||||
async updateNote(id: string, data: UpdateNoteData): Promise<Note> {
|
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);
|
const response = await this.put<NoteResponse>(`/${id}`, data);
|
||||||
console.log('[notesClient.updateNote] Response:', response);
|
|
||||||
return response.note;
|
return response.note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user