Pages corrections journal
This commit is contained in:
parent
6c7719f764
commit
3bfd1a99e4
@ -12,6 +12,7 @@ import { ContactsView } from '@/components/carnet/contacts-view';
|
|||||||
import { X, Menu } from "lucide-react";
|
import { X, Menu } from "lucide-react";
|
||||||
import { ContactDetails } from '@/components/carnet/contact-details';
|
import { ContactDetails } from '@/components/carnet/contact-details';
|
||||||
import { parse as parseVCard, format as formatVCard } from 'vcard-parser';
|
import { parse as parseVCard, format as formatVCard } from 'vcard-parser';
|
||||||
|
import { format } from 'date-fns';
|
||||||
import { PaneLayout } from './pane-layout';
|
import { PaneLayout } from './pane-layout';
|
||||||
import { notesCache, noteContentCache, foldersCache, invalidateFolderCache, invalidateNoteCache } from '@/lib/cache-utils';
|
import { notesCache, noteContentCache, foldersCache, invalidateFolderCache, invalidateNoteCache } from '@/lib/cache-utils';
|
||||||
|
|
||||||
@ -469,8 +470,29 @@ export default function CarnetPage() {
|
|||||||
const handleSaveNote = async (note: Note) => {
|
const handleSaveNote = async (note: Note) => {
|
||||||
try {
|
try {
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
|
|
||||||
|
// For Diary and Health, ensure title is formatted with date
|
||||||
|
let noteTitle = note.title || 'Untitled';
|
||||||
|
if ((selectedFolder === 'Diary' || selectedFolder === 'Health') && !note.id) {
|
||||||
|
// For new notes in Diary/Health, use today's date as title
|
||||||
|
const today = new Date();
|
||||||
|
const dateStr = format(today, 'yyyy-MM-dd');
|
||||||
|
noteTitle = dateStr;
|
||||||
|
|
||||||
|
// Check if a note with this date already exists
|
||||||
|
const existingNote = notes.find(n => {
|
||||||
|
return n.title?.startsWith(dateStr) || n.id?.includes(dateStr);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existingNote) {
|
||||||
|
// Update the existing note instead of creating a new one
|
||||||
|
console.log(`[handleSaveNote] Found existing note for today, updating: ${existingNote.id}`);
|
||||||
|
note.id = existingNote.id;
|
||||||
|
noteTitle = existingNote.title; // Keep the existing title format
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Construct API payload with lowercase folder name
|
// Construct API payload with lowercase folder name
|
||||||
const noteTitle = note.title || 'Untitled';
|
|
||||||
const payload = {
|
const payload = {
|
||||||
id: note.id || `user-${session?.user?.id}/${selectedFolder.toLowerCase()}/${noteTitle}${noteTitle.endsWith('.md') ? '' : '.md'}`,
|
id: note.id || `user-${session?.user?.id}/${selectedFolder.toLowerCase()}/${noteTitle}${noteTitle.endsWith('.md') ? '' : '.md'}`,
|
||||||
title: noteTitle,
|
title: noteTitle,
|
||||||
@ -483,7 +505,7 @@ export default function CarnetPage() {
|
|||||||
const endpoint = '/api/storage/files';
|
const endpoint = '/api/storage/files';
|
||||||
const method = note.id ? 'PUT' : 'POST';
|
const method = note.id ? 'PUT' : 'POST';
|
||||||
|
|
||||||
console.log(`Saving note to ${selectedFolder.toLowerCase()} using ${method}`);
|
console.log(`Saving note to ${selectedFolder.toLowerCase()} using ${method}, title: ${noteTitle}`);
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
const response = await fetch(endpoint, {
|
||||||
method,
|
method,
|
||||||
@ -617,18 +639,55 @@ export default function CarnetPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNewNote = () => {
|
const handleNewNote = async () => {
|
||||||
setSelectedNote({
|
// For Diary and Health folders, check if a note exists for today
|
||||||
id: '',
|
if (selectedFolder === 'Diary' || selectedFolder === 'Health') {
|
||||||
title: '',
|
const today = new Date();
|
||||||
content: '',
|
const dateStr = format(today, 'yyyy-MM-dd');
|
||||||
lastModified: new Date().toISOString(),
|
const dateTitle = `${dateStr}`;
|
||||||
type: 'file',
|
|
||||||
mime: 'text/markdown',
|
// Check if a note with this date already exists
|
||||||
etag: ''
|
const existingNote = notes.find(note => {
|
||||||
});
|
// Check if note title starts with today's date
|
||||||
if (isMobile) {
|
return note.title?.startsWith(dateStr);
|
||||||
setShowNotes(false);
|
});
|
||||||
|
|
||||||
|
if (existingNote) {
|
||||||
|
// Open the existing note for today
|
||||||
|
console.log(`[handleNewNote] Found existing note for today: ${existingNote.title}`);
|
||||||
|
handleNoteSelect(existingNote);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new note with today's date as title
|
||||||
|
const newNote: Note = {
|
||||||
|
id: '',
|
||||||
|
title: dateStr, // Use date as title for Diary/Health
|
||||||
|
content: '',
|
||||||
|
lastModified: today.toISOString(),
|
||||||
|
type: 'file',
|
||||||
|
mime: 'text/markdown',
|
||||||
|
etag: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
setSelectedNote(newNote);
|
||||||
|
if (isMobile) {
|
||||||
|
setShowNotes(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For other folders, create a blank note
|
||||||
|
setSelectedNote({
|
||||||
|
id: '',
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
lastModified: new Date().toISOString(),
|
||||||
|
type: 'file',
|
||||||
|
mime: 'text/markdown',
|
||||||
|
etag: ''
|
||||||
|
});
|
||||||
|
if (isMobile) {
|
||||||
|
setShowNotes(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -84,7 +84,14 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
setTitle(note.title || '');
|
// For Diary and Health, if it's a new note (no id), set title to today's date
|
||||||
|
if ((currentFolder === 'Diary' || currentFolder === 'Health') && !note.id) {
|
||||||
|
const today = new Date();
|
||||||
|
const dateStr = today.toISOString().split('T')[0]; // YYYY-MM-DD format
|
||||||
|
setTitle(dateStr);
|
||||||
|
} else {
|
||||||
|
setTitle(note.title || '');
|
||||||
|
}
|
||||||
if (note.id) {
|
if (note.id) {
|
||||||
fetchNoteContent();
|
fetchNoteContent();
|
||||||
} else {
|
} else {
|
||||||
@ -94,7 +101,7 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
setTitle('');
|
setTitle('');
|
||||||
setContent('');
|
setContent('');
|
||||||
}
|
}
|
||||||
}, [note, router]);
|
}, [note, router, currentFolder]);
|
||||||
|
|
||||||
const handleTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setTitle(e.target.value);
|
setTitle(e.target.value);
|
||||||
@ -236,7 +243,11 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
value={title ?? ''}
|
value={title ?? ''}
|
||||||
onChange={handleTitleChange}
|
onChange={handleTitleChange}
|
||||||
placeholder="Titre"
|
placeholder="Titre"
|
||||||
className="w-full text-xl font-semibold text-carnet-text-primary placeholder-carnet-text-muted focus:outline-none bg-transparent"
|
disabled={currentFolder === 'Diary' || currentFolder === 'Health'}
|
||||||
|
className={`w-full text-xl font-semibold text-carnet-text-primary placeholder-carnet-text-muted focus:outline-none bg-transparent ${
|
||||||
|
(currentFolder === 'Diary' || currentFolder === 'Health') ? 'opacity-60 cursor-not-allowed' : ''
|
||||||
|
}`}
|
||||||
|
title={currentFolder === 'Diary' || currentFolder === 'Health' ? 'Le titre est automatiquement la date du jour pour les journaux' : ''}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user