Pages corrections pages missions

This commit is contained in:
alma 2026-01-16 15:46:03 +01:00
parent 41731dae73
commit bad4aca1dd

View File

@ -551,8 +551,26 @@ export default function CarnetPage() {
// Refresh notes list to ensure we have the latest data
await fetchNotes(true);
// If note has a valid id (not temp), use it directly
if (note.id && !note.id.startsWith('temp-') && note.id.includes(`user-${session?.user?.id}/`)) {
// Check if the current note.id corresponds to an "Untitled" note
// and if we're giving it a new title (renaming scenario)
const isRenamingUntitled = note.id &&
!note.id.startsWith('temp-') &&
note.id.includes(`user-${session?.user?.id}/`) &&
note.id.includes('/Untitled.md') &&
noteTitle &&
noteTitle.trim() !== '' &&
noteTitle !== 'Untitled';
if (isRenamingUntitled) {
// We're renaming an Untitled note to a new title
const sanitizedTitle = noteTitle.replace(/[^a-zA-Z0-9._-]/g, '_');
fileKey = `user-${session?.user?.id}/${selectedFolder.toLowerCase()}/${sanitizedTitle}.md`;
console.log(`[handleSaveNote] Renaming Untitled note to "${noteTitle}": ${note.id} -> ${fileKey}`);
// Store the old id to delete it later
(note as any)._oldUntitledId = note.id;
note.id = fileKey; // Update note.id to the new fileKey
} else if (note.id && !note.id.startsWith('temp-') && note.id.includes(`user-${session?.user?.id}/`)) {
// Note has a valid id and we're not renaming, use it directly
fileKey = note.id;
console.log(`[handleSaveNote] Using existing note id: ${fileKey}`);
} else {