Files
Keep/keep-notes/hooks/use-reminder-check.ts
Sepehr Ramezani 39671c6472 fix(keep-notes): sidebar chevron, labels sync, batch org errors, perf guards
- Notebooks: chevron visible when expanded (remove overflow clip), functional expand state
- Labels: sync/cleanup by notebookId, reconcile after note move
- Settings: refresh notebooks after cleanup; label dialog routing
- ConnectionsBadge lazy-load; reminder check persistence; i18n keys

Made-with: Cursor
2026-04-13 22:07:09 +02:00

54 lines
1.4 KiB
TypeScript

'use client';
import { useEffect, useRef } from 'react';
import { Note } from '@/lib/types';
import { toast } from 'sonner';
const STORAGE_KEY = 'memento-notified-reminders';
function getNotifiedFromStorage(): Set<string> {
try {
const raw = sessionStorage.getItem(STORAGE_KEY);
return raw ? new Set(JSON.parse(raw)) : new Set();
} catch {
return new Set();
}
}
function persistNotified(ids: Set<string>) {
try {
sessionStorage.setItem(STORAGE_KEY, JSON.stringify([...ids]));
} catch { /* quota exceeded — non-critical */ }
}
export function useReminderCheck(notes: Note[]) {
const notifiedRef = useRef<Set<string>>(getNotifiedFromStorage());
useEffect(() => {
const checkReminders = () => {
const now = new Date();
const newIds: string[] = [];
for (const note of notes) {
if (!note.reminder || note.isReminderDone) continue;
if (notifiedRef.current.has(note.id)) continue;
const reminderDate = new Date(note.reminder);
if (reminderDate <= now) {
newIds.push(note.id);
toast.info(`🔔 ${note.title || 'Untitled Note'}`, { id: `reminder-${note.id}` });
}
}
if (newIds.length > 0) {
for (const id of newIds) notifiedRef.current.add(id);
persistNotified(notifiedRef.current);
}
};
checkReminders();
const interval = setInterval(checkReminders, 30_000);
return () => clearInterval(interval);
}, [notes]);
}