v3: follows, notifications, invite-only registration, unread markers
This commit is contained in:
43
src/utils/visited.ts
Normal file
43
src/utils/visited.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
const DUMP_KEY = "visited_dumps";
|
||||
const PLAYLIST_KEY = "visited_playlists";
|
||||
const MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
||||
|
||||
function loadSet(key: string): Set<string> {
|
||||
try {
|
||||
const raw = localStorage.getItem(key);
|
||||
return raw ? new Set(JSON.parse(raw) as string[]) : new Set();
|
||||
} catch {
|
||||
return new Set();
|
||||
}
|
||||
}
|
||||
|
||||
function saveSet(key: string, set: Set<string>): void {
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify([...set]));
|
||||
} catch { /* quota exceeded — ignore */ }
|
||||
}
|
||||
|
||||
export function isDumpVisited(id: string): boolean {
|
||||
return loadSet(DUMP_KEY).has(id);
|
||||
}
|
||||
|
||||
export function isPlaylistVisited(id: string): boolean {
|
||||
return loadSet(PLAYLIST_KEY).has(id);
|
||||
}
|
||||
|
||||
export function markDumpVisited(id: string): void {
|
||||
const set = loadSet(DUMP_KEY);
|
||||
set.add(id);
|
||||
saveSet(DUMP_KEY, set);
|
||||
}
|
||||
|
||||
export function markPlaylistVisited(id: string): void {
|
||||
const set = loadSet(PLAYLIST_KEY);
|
||||
set.add(id);
|
||||
saveSet(PLAYLIST_KEY, set);
|
||||
}
|
||||
|
||||
/** Only items newer than MAX_AGE_MS are eligible to show the unread dot. */
|
||||
export function isRecent(createdAt: Date): boolean {
|
||||
return Date.now() - createdAt.getTime() < MAX_AGE_MS;
|
||||
}
|
||||
Reference in New Issue
Block a user