chore: clean up repo for public release
- Remove BMAD framework, IDE configs, dev screenshots, test files, internal docs, and backup files - Rename keep-notes/ to memento-note/ - Update all references from keep-notes to memento-note - Add Apache 2.0 license with Commons Clause (non-commercial restriction) - Add clean .gitignore and .env.docker.example
This commit is contained in:
53
memento-note/hooks/use-reminder-check.ts
Normal file
53
memento-note/hooks/use-reminder-check.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
'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]);
|
||||
}
|
||||
Reference in New Issue
Block a user