diff --git a/memento-note/components/note-card.tsx b/memento-note/components/note-card.tsx index cdc77a5..126ea2b 100644 --- a/memento-note/components/note-card.tsx +++ b/memento-note/components/note-card.tsx @@ -25,6 +25,7 @@ import { useState, useEffect, useTransition, useOptimistic, memo } from 'react' import { useSession } from 'next-auth/react' import { useRouter, useSearchParams } from 'next/navigation' import { deleteNote, toggleArchive, togglePin, updateColor, updateNote, updateSize, getNoteAllUsers, leaveSharedNote, removeFusedBadge, createNote } from '@/app/actions/notes' +import { useNoteRefreshOptional } from '@/context/NoteRefreshContext' import { cn } from '@/lib/utils' import { formatDistanceToNow, Locale } from 'date-fns' import { enUS } from 'date-fns/locale/en-US' @@ -164,6 +165,8 @@ export const NoteCard = memo(function NoteCard({ const { notebooks, moveNoteToNotebookOptimistic } = useNotebooks() const [, startTransition] = useTransition() const [isDeleting, setIsDeleting] = useState(false) + const [isHidden, setIsHidden] = useState(false) + const { triggerRefresh } = useNoteRefreshOptional() const [showDeleteDialog, setShowDeleteDialog] = useState(false) const [showCollaboratorDialog, setShowCollaboratorDialog] = useState(false) const [collaborators, setCollaborators] = useState([]) @@ -250,11 +253,14 @@ export const NoteCard = memo(function NoteCard({ const handleDelete = async () => { setIsDeleting(true) + setIsHidden(true) // masquage immédiat try { await deleteNote(note.id) await refreshLabels() + triggerRefresh() // met à jour la liste et le compteur du carnet } catch (error) { console.error('Failed to delete note:', error) + setIsHidden(false) setIsDeleting(false) } } @@ -354,6 +360,8 @@ export const NoteCard = memo(function NoteCard({ + if (isHidden) return null + return (