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
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:
@@ -21,7 +21,7 @@ export async function GET(request: NextRequest) {
|
|||||||
orderBy: { name: 'asc' }
|
orderBy: { name: 'asc' }
|
||||||
},
|
},
|
||||||
_count: {
|
_count: {
|
||||||
select: { notes: { where: { isArchived: false } } }
|
select: { notes: { where: { isArchived: false, trashedAt: null } } }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderBy: { order: 'asc' }
|
orderBy: { order: 'asc' }
|
||||||
@@ -82,7 +82,7 @@ export async function POST(request: NextRequest) {
|
|||||||
include: {
|
include: {
|
||||||
labels: true,
|
labels: true,
|
||||||
_count: {
|
_count: {
|
||||||
select: { notes: { where: { isArchived: false } } }
|
select: { notes: { where: { isArchived: false, trashedAt: null } } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import { Pin, Bell, GripVertical, X, Link2, FolderOpen, StickyNote, LucideIcon,
|
|||||||
import { useState, useEffect, useTransition, useOptimistic, memo } from 'react'
|
import { useState, useEffect, useTransition, useOptimistic, memo } from 'react'
|
||||||
import { useSession } from 'next-auth/react'
|
import { useSession } from 'next-auth/react'
|
||||||
import { useRouter, useSearchParams } from 'next/navigation'
|
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 { cn } from '@/lib/utils'
|
||||||
import { formatDistanceToNow, Locale } from 'date-fns'
|
import { formatDistanceToNow, Locale } from 'date-fns'
|
||||||
import { enUS } from 'date-fns/locale/en-US'
|
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 () => {
|
const handleTogglePin = async () => {
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
addOptimisticNote({ isPinned: !note.isPinned })
|
addOptimisticNote({ isPinned: !note.isPinned })
|
||||||
@@ -612,6 +640,9 @@ export const NoteCard = memo(function NoteCard({
|
|||||||
onSizeChange={handleSizeChange}
|
onSizeChange={handleSizeChange}
|
||||||
onDelete={() => setShowDeleteDialog(true)}
|
onDelete={() => setShowDeleteDialog(true)}
|
||||||
onShareCollaborators={() => setShowCollaboratorDialog(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"
|
className="absolute bottom-0 left-0 right-0 p-2 opacity-100 md:opacity-0 group-hover:opacity-100 transition-opacity"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user