fix: exclude trashed notes from notebook counts + wire up trash restore/delete
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 39s

- Add trashedAt: null filter to notebook note count queries in /api/notebooks
- Pass isTrashView, onRestore, onPermanentDelete from NoteCard to NoteActions
- Implement handleRestore and handlePermanentDelete in NoteCard

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 10:04:06 +02:00
parent e83f1d1e52
commit dc18dc3de4
2 changed files with 34 additions and 3 deletions

View File

@@ -24,7 +24,7 @@ import { Pin, Bell, GripVertical, X, Link2, FolderOpen, StickyNote, LucideIcon,
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 { deleteNote, toggleArchive, togglePin, updateColor, updateNote, updateSize, getNoteAllUsers, leaveSharedNote, removeFusedBadge, createNote, restoreNote, permanentDeleteNote } from '@/app/actions/notes'
import { cn } from '@/lib/utils'
import { formatDistanceToNow, Locale } from 'date-fns'
import { enUS } from 'date-fns/locale/en-US'
@@ -263,6 +263,34 @@ export const NoteCard = memo(function NoteCard({
}
}
const handleRestore = async () => {
setIsDeleting(true)
setIsHidden(true)
try {
await restoreNote(note.id)
triggerRefresh()
toast.success(t('trash.noteRestored'))
} catch (error) {
console.error('Failed to restore note:', error)
setIsHidden(false)
setIsDeleting(false)
}
}
const handlePermanentDelete = async () => {
setIsDeleting(true)
setIsHidden(true)
try {
await permanentDeleteNote(note.id)
triggerRefresh()
toast.success(t('trash.notePermanentlyDeleted'))
} catch (error) {
console.error('Failed to permanently delete note:', error)
setIsHidden(false)
setIsDeleting(false)
}
}
const handleTogglePin = async () => {
startTransition(async () => {
addOptimisticNote({ isPinned: !note.isPinned })
@@ -612,6 +640,9 @@ export const NoteCard = memo(function NoteCard({
onSizeChange={handleSizeChange}
onDelete={() => setShowDeleteDialog(true)}
onShareCollaborators={() => setShowCollaboratorDialog(true)}
isTrashView={isTrashView}
onRestore={handleRestore}
onPermanentDelete={handlePermanentDelete}
className="absolute bottom-0 left-0 right-0 p-2 opacity-100 md:opacity-0 group-hover:opacity-100 transition-opacity"
/>
)}