feat: MVP-4 P2 - Preload notes on hover
- Add prefetchNote function in useNoteListKeyboard hook - Prefetch note pages when navigating with arrow keys - Add hover prefetch in NoteCard using router.prefetch - Update KeyboardNavigableNoteList to use prefetchNote
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Note } from '@/types/note'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
@@ -16,12 +17,21 @@ const typeColors: Record<string, string> = {
|
||||
}
|
||||
|
||||
export function NoteCard({ note }: { note: Note }) {
|
||||
const router = useRouter()
|
||||
const preview = note.content.slice(0, 100) + (note.content.length > 100 ? '...' : '')
|
||||
const typeColor = typeColors[note.type] || typeColors.note
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
// Prefetch on hover for faster navigation
|
||||
router.prefetch(`/notes/${note.id}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<Link href={`/notes/${note.id}`}>
|
||||
<Card className="hover:shadow-md transition-shadow cursor-pointer h-full">
|
||||
<Link href={`/notes/${note.id}`} prefetch={true}>
|
||||
<Card
|
||||
className="hover:shadow-md transition-shadow cursor-pointer h-full"
|
||||
onMouseEnter={handleMouseEnter}
|
||||
>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start justify-between gap-2 mb-2">
|
||||
<h3 className="font-semibold text-lg line-clamp-1">{note.title}</h3>
|
||||
|
||||
Reference in New Issue
Block a user