Fix tests and add changelog

This commit is contained in:
2026-01-04 21:33:10 +01:00
parent f0b41572bc
commit a154192410
56 changed files with 4464 additions and 236 deletions

View File

@@ -21,6 +21,7 @@ export async function getNotes(includeArchived = false) {
where: includeArchived ? {} : { isArchived: false },
orderBy: [
{ isPinned: 'desc' },
{ order: 'asc' },
{ updatedAt: 'desc' }
]
})
@@ -245,30 +246,56 @@ export async function getAllLabels() {
// Reorder notes (drag and drop)
export async function reorderNotes(draggedId: string, targetId: string) {
console.log('[REORDER-DEBUG] reorderNotes called:', { draggedId, targetId })
try {
const draggedNote = await prisma.note.findUnique({ where: { id: draggedId } })
const targetNote = await prisma.note.findUnique({ where: { id: targetId } })
console.log('[REORDER-DEBUG] Notes found:', {
draggedNote: draggedNote ? { id: draggedNote.id, title: draggedNote.title, isPinned: draggedNote.isPinned, order: draggedNote.order } : null,
targetNote: targetNote ? { id: targetNote.id, title: targetNote.title, isPinned: targetNote.isPinned, order: targetNote.order } : null
})
if (!draggedNote || !targetNote) {
console.error('[REORDER-DEBUG] Notes not found')
throw new Error('Notes not found')
}
// Swap the order values
await prisma.$transaction([
// Get all notes in the same category (pinned or unpinned)
const allNotes = await prisma.note.findMany({
where: {
isPinned: draggedNote.isPinned,
isArchived: false
},
orderBy: { order: 'asc' }
})
console.log('[REORDER-DEBUG] All notes in category:', allNotes.map(n => ({ id: n.id, title: n.title, order: n.order })))
// Create new order array
const reorderedNotes = allNotes.filter(n => n.id !== draggedId)
const targetIndex = reorderedNotes.findIndex(n => n.id === targetId)
reorderedNotes.splice(targetIndex, 0, draggedNote)
console.log('[REORDER-DEBUG] New order:', reorderedNotes.map((n, i) => ({ id: n.id, title: n.title, newOrder: i })))
// Update all notes with new order
const updates = reorderedNotes.map((note, index) =>
prisma.note.update({
where: { id: draggedId },
data: { order: targetNote.order }
}),
prisma.note.update({
where: { id: targetId },
data: { order: draggedNote.order }
where: { id: note.id },
data: { order: index }
})
])
)
console.log('[REORDER-DEBUG] Executing transaction with', updates.length, 'updates')
await prisma.$transaction(updates)
console.log('[REORDER-DEBUG] Transaction completed successfully')
revalidatePath('/')
return { success: true }
} catch (error) {
console.error('Error reordering notes:', error)
console.error('[REORDER-DEBUG] Error reordering notes:', error)
throw new Error('Failed to reorder notes')
}
}

View File

@@ -1,7 +1,7 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { Header } from "@/components/header";
import { HeaderWrapper } from "@/components/header-wrapper";
import { ToastProvider } from "@/components/ui/toast";
const inter = Inter({
@@ -22,7 +22,7 @@ export default function RootLayout({
<html lang="en" suppressHydrationWarning>
<body className={inter.className}>
<ToastProvider>
<Header />
<HeaderWrapper />
{children}
</ToastProvider>
</body>

View File

@@ -1,23 +1,47 @@
'use client'
import { useState, useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
import { Note } from '@/lib/types'
import { getNotes, searchNotes } from '@/app/actions/notes'
import { NoteInput } from '@/components/note-input'
import { NoteGrid } from '@/components/note-grid'
export const dynamic = 'force-dynamic'
export default function HomePage() {
const searchParams = useSearchParams()
const [notes, setNotes] = useState<Note[]>([])
const [isLoading, setIsLoading] = useState(true)
export default async function HomePage({
searchParams,
}: {
searchParams: Promise<{ search?: string }>
}) {
const params = await searchParams
const notes = params.search
? await searchNotes(params.search)
: await getNotes()
useEffect(() => {
const loadNotes = async () => {
setIsLoading(true)
const search = searchParams.get('search')
const labelFilter = searchParams.get('labels')?.split(',').filter(Boolean) || []
let allNotes = search ? await searchNotes(search) : await getNotes()
// Filter by selected labels
if (labelFilter.length > 0) {
allNotes = allNotes.filter(note =>
note.labels?.some(label => labelFilter.includes(label))
)
}
setNotes(allNotes)
setIsLoading(false)
}
loadNotes()
}, [searchParams])
return (
<main className="container mx-auto px-4 py-8 max-w-7xl">
<NoteInput />
<NoteGrid notes={notes} />
{isLoading ? (
<div className="text-center py-8 text-gray-500">Loading...</div>
) : (
<NoteGrid notes={notes} />
)}
</main>
)
}