fix: optimistic note removal on delete + triggerRefresh for count update
Some checks failed
Deploy to Production / Build and Deploy (push) Has been cancelled

Made-with: Cursor
This commit is contained in:
2026-04-26 00:01:32 +02:00
parent ffd6fb9373
commit 1164a4a30e

View File

@@ -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<any[]>([])
@@ -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 (
<Card
data-testid="note-card"