Keep/keep-notes/hooks/use-reminder-check.ts
sepehr 640fcb26f7 fix: improve note interactions and markdown LaTeX support
## Bug Fixes

### Note Card Actions
- Fix broken size change functionality (missing state declaration)
- Implement React 19 useOptimistic for instant UI feedback
- Add startTransition for non-blocking updates
- Ensure smooth animations without page refresh
- All note actions now work: pin, archive, color, size, checklist

### Markdown LaTeX Rendering
- Add remark-math and rehype-katex plugins
- Support inline equations with dollar sign syntax
- Support block equations with double dollar sign syntax
- Import KaTeX CSS for proper styling
- Equations now render correctly instead of showing raw LaTeX

## Technical Details

- Replace undefined currentNote references with optimistic state
- Add optimistic updates before server actions for instant feedback
- Use router.refresh() in transitions for smart cache invalidation
- Install remark-math, rehype-katex, and katex packages

## Testing

- Build passes successfully with no TypeScript errors
- Dev server hot-reloads changes correctly
2026-01-09 22:13:49 +01:00

45 lines
1.4 KiB
TypeScript

'use client';
import { useState, useEffect } from 'react';
import { Note } from '@/lib/types';
import { toast } from 'sonner';
export function useReminderCheck(notes: Note[]) {
const [notifiedReminders, setNotifiedReminders] = useState<Set<string>>(new Set());
useEffect(() => {
const checkReminders = () => {
const now = new Date();
notes.forEach(note => {
if (!note.reminder) return;
const reminderDate = new Date(note.reminder);
// Check if reminder is due (within last minute or future)
// We only notify if it's due now or just passed, not old overdue ones (unless we want to catch up)
// Let's say: notify if reminder time is passed AND we haven't notified yet.
if (reminderDate <= now && !notifiedReminders.has(note.id)) {
// Play sound (optional)
// const audio = new Audio('/notification.mp3');
// audio.play().catch(e => console.log('Audio play failed', e));
toast.info("🔔 Reminder: " + (note.title || "Untitled Note"));
// Mark as notified in local state
setNotifiedReminders(prev => new Set(prev).add(note.id));
}
});
};
// Check immediately
checkReminders();
// Then check every 30 seconds
const interval = setInterval(checkReminders, 30000);
return () => clearInterval(interval);
}, [notes, notifiedReminders]);
}