Pages corrections pages health

This commit is contained in:
alma 2026-01-16 16:52:32 +01:00
parent 850cae5aa0
commit e5254c8bc8

View File

@ -691,6 +691,10 @@ export default function CarnetPage() {
};
console.log(`[handleSaveNote] File key for ${selectedFolder}: ${fileKey}`);
console.log(`[handleSaveNote] Payload content length: ${payload.content.length} chars`);
if (selectedFolder === 'Health') {
console.log(`[handleSaveNote] Health payload content preview:`, payload.content.substring(0, 200));
}
// Use direct storage API endpoint
const endpoint = '/api/storage/files';
@ -710,7 +714,10 @@ export default function CarnetPage() {
body: JSON.stringify(payload)
});
console.log(`[handleSaveNote] Response status: ${response.status}, ok: ${response.ok}`);
if (response.ok) {
console.log(`[handleSaveNote] Save successful for ${selectedFolder}`);
// If we renamed a note from Untitled to a title, delete the old Untitled file
const oldUntitledId = (note as any)._oldUntitledId;
if (oldUntitledId && oldUntitledId !== fileKey) {
@ -751,11 +758,32 @@ export default function CarnetPage() {
// Health folder updates are handled by the form itself and don't need immediate list refresh
if (selectedFolder !== 'Health') {
fetchNotes(true);
} else {
console.log(`[handleSaveNote] Health folder - skipping fetchNotes to avoid flickering`);
}
// Log success for debugging - try to read response but don't fail if it's empty
try {
const responseText = await response.text();
if (responseText) {
const responseData = JSON.parse(responseText);
console.log(`[handleSaveNote] Save successful, response:`, responseData);
} else {
console.log(`[handleSaveNote] Save successful (empty response)`);
}
} catch (parseError) {
console.log(`[handleSaveNote] Save successful (could not parse response)`);
}
} else {
const errorData = await response.json().catch(() => ({}));
const errorMessage = errorData.message || errorData.error || 'Failed to save note';
console.error('Error saving note:', errorMessage);
const errorText = await response.text().catch(() => '');
let errorData = {};
try {
errorData = errorText ? JSON.parse(errorText) : {};
} catch {
// Not JSON, use as plain text
}
const errorMessage = errorData.message || errorData.error || errorText || `Failed to save note: ${response.status} ${response.statusText}`;
console.error(`[handleSaveNote] Error saving note (${response.status}):`, errorMessage);
throw new Error(errorMessage);
}
} catch (error) {