pages
This commit is contained in:
parent
92da9196c6
commit
05d97e2c50
@ -180,6 +180,35 @@ export default function CarnetPage() {
|
|||||||
}
|
}
|
||||||
}, [selectedFolder, session?.user?.id]);
|
}, [selectedFolder, session?.user?.id]);
|
||||||
|
|
||||||
|
// Listen for note-saved events to refresh the list
|
||||||
|
useEffect(() => {
|
||||||
|
const handleNoteSaved = (event: CustomEvent) => {
|
||||||
|
const folder = event.detail?.folder;
|
||||||
|
if (folder && selectedFolder.toLowerCase() === folder.toLowerCase()) {
|
||||||
|
console.log('Note saved event received, refreshing notes list');
|
||||||
|
// Clear cache and fetch fresh notes
|
||||||
|
const cacheKey = `${session?.user?.id}-${folder}`;
|
||||||
|
if (notesCache.current[cacheKey]) {
|
||||||
|
delete notesCache.current[cacheKey];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
localStorage.removeItem(`notes-cache-${cacheKey}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error removing cache:', error);
|
||||||
|
}
|
||||||
|
// Fetch notes will be called by the existing useEffect when selectedFolder changes
|
||||||
|
// But we can also call it directly here
|
||||||
|
fetchNotes();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('note-saved', handleNoteSaved as EventListener);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('note-saved', handleNoteSaved as EventListener);
|
||||||
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [selectedFolder, session?.user?.id]);
|
||||||
|
|
||||||
const parseVCardContent = (content: string): Contact[] => {
|
const parseVCardContent = (content: string): Contact[] => {
|
||||||
try {
|
try {
|
||||||
// Split the content into individual vCards
|
// Split the content into individual vCards
|
||||||
|
|||||||
@ -55,11 +55,11 @@ export function NotesDialog({ open, onOpenChange }: NotesDialogProps) {
|
|||||||
setError("");
|
setError("");
|
||||||
|
|
||||||
// Construct API payload with lowercase folder name (always "notes" for quick notes)
|
// Construct API payload with lowercase folder name (always "notes" for quick notes)
|
||||||
|
// Note: The API will construct the full path from folder and title
|
||||||
const payload = {
|
const payload = {
|
||||||
id: `user-${session?.user?.id}/notes/${title}${title.endsWith('.md') ? '' : '.md'}`,
|
|
||||||
title: title,
|
title: title,
|
||||||
content: content,
|
content: content,
|
||||||
folder: "notes", // Always save to Notes folder
|
folder: "notes", // Always save to Notes folder (lowercase for consistency)
|
||||||
mime: "text/markdown"
|
mime: "text/markdown"
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,9 +73,28 @@ export function NotesDialog({ open, onOpenChange }: NotesDialogProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
console.error('Failed to save note:', errorText);
|
||||||
throw new Error('Failed to save note');
|
throw new Error('Failed to save note');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invalidate cache and trigger refresh
|
||||||
|
try {
|
||||||
|
// Clear localStorage cache for notes
|
||||||
|
const userId = session?.user?.id;
|
||||||
|
if (userId) {
|
||||||
|
const cacheKey = `${userId}-notes`;
|
||||||
|
localStorage.removeItem(`notes-cache-${cacheKey}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dispatch custom event to notify pages to refresh
|
||||||
|
window.dispatchEvent(new CustomEvent('note-saved', {
|
||||||
|
detail: { folder: 'notes' }
|
||||||
|
}));
|
||||||
|
} catch (cacheError) {
|
||||||
|
console.error('Error clearing cache:', cacheError);
|
||||||
|
}
|
||||||
|
|
||||||
// Reset form and close dialog
|
// Reset form and close dialog
|
||||||
setTitle("");
|
setTitle("");
|
||||||
setContent("");
|
setContent("");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user