You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
3.5 KiB
140 lines
3.5 KiB
/** |
|
* User actions service - manages pinned, bookmarked, and highlighted events |
|
* Stores in localStorage for persistence |
|
*/ |
|
|
|
const STORAGE_KEY_PINNED = 'aitherboard_pinned_events'; |
|
const STORAGE_KEY_BOOKMARKED = 'aitherboard_bookmarked_events'; |
|
const STORAGE_KEY_HIGHLIGHTED = 'aitherboard_highlighted_events'; |
|
|
|
/** |
|
* Get all pinned event IDs |
|
*/ |
|
export function getPinnedEvents(): Set<string> { |
|
if (typeof window === 'undefined') return new Set(); |
|
try { |
|
const stored = localStorage.getItem(STORAGE_KEY_PINNED); |
|
if (!stored) return new Set(); |
|
const ids = JSON.parse(stored) as string[]; |
|
return new Set(ids); |
|
} catch { |
|
return new Set(); |
|
} |
|
} |
|
|
|
/** |
|
* Get all bookmarked event IDs |
|
*/ |
|
export function getBookmarkedEvents(): Set<string> { |
|
if (typeof window === 'undefined') return new Set(); |
|
try { |
|
const stored = localStorage.getItem(STORAGE_KEY_BOOKMARKED); |
|
if (!stored) return new Set(); |
|
const ids = JSON.parse(stored) as string[]; |
|
return new Set(ids); |
|
} catch { |
|
return new Set(); |
|
} |
|
} |
|
|
|
/** |
|
* Get all highlighted event IDs |
|
*/ |
|
export function getHighlightedEvents(): Set<string> { |
|
if (typeof window === 'undefined') return new Set(); |
|
try { |
|
const stored = localStorage.getItem(STORAGE_KEY_HIGHLIGHTED); |
|
if (!stored) return new Set(); |
|
const ids = JSON.parse(stored) as string[]; |
|
return new Set(ids); |
|
} catch { |
|
return new Set(); |
|
} |
|
} |
|
|
|
/** |
|
* Check if an event is pinned |
|
*/ |
|
export function isPinned(eventId: string): boolean { |
|
return getPinnedEvents().has(eventId); |
|
} |
|
|
|
/** |
|
* Check if an event is bookmarked |
|
*/ |
|
export function isBookmarked(eventId: string): boolean { |
|
return getBookmarkedEvents().has(eventId); |
|
} |
|
|
|
/** |
|
* Check if an event is highlighted |
|
*/ |
|
export function isHighlighted(eventId: string): boolean { |
|
return getHighlightedEvents().has(eventId); |
|
} |
|
|
|
/** |
|
* Toggle pin status of an event |
|
*/ |
|
export function togglePin(eventId: string): boolean { |
|
const pinned = getPinnedEvents(); |
|
const isCurrentlyPinned = pinned.has(eventId); |
|
|
|
if (isCurrentlyPinned) { |
|
pinned.delete(eventId); |
|
} else { |
|
pinned.add(eventId); |
|
} |
|
|
|
try { |
|
localStorage.setItem(STORAGE_KEY_PINNED, JSON.stringify(Array.from(pinned))); |
|
return !isCurrentlyPinned; |
|
} catch (error) { |
|
console.error('Failed to save pinned events:', error); |
|
return isCurrentlyPinned; |
|
} |
|
} |
|
|
|
/** |
|
* Toggle bookmark status of an event |
|
*/ |
|
export function toggleBookmark(eventId: string): boolean { |
|
const bookmarked = getBookmarkedEvents(); |
|
const isCurrentlyBookmarked = bookmarked.has(eventId); |
|
|
|
if (isCurrentlyBookmarked) { |
|
bookmarked.delete(eventId); |
|
} else { |
|
bookmarked.add(eventId); |
|
} |
|
|
|
try { |
|
localStorage.setItem(STORAGE_KEY_BOOKMARKED, JSON.stringify(Array.from(bookmarked))); |
|
return !isCurrentlyBookmarked; |
|
} catch (error) { |
|
console.error('Failed to save bookmarked events:', error); |
|
return isCurrentlyBookmarked; |
|
} |
|
} |
|
|
|
/** |
|
* Toggle highlight status of an event |
|
*/ |
|
export function toggleHighlight(eventId: string): boolean { |
|
const highlighted = getHighlightedEvents(); |
|
const isCurrentlyHighlighted = highlighted.has(eventId); |
|
|
|
if (isCurrentlyHighlighted) { |
|
highlighted.delete(eventId); |
|
} else { |
|
highlighted.add(eventId); |
|
} |
|
|
|
try { |
|
localStorage.setItem(STORAGE_KEY_HIGHLIGHTED, JSON.stringify(Array.from(highlighted))); |
|
return !isCurrentlyHighlighted; |
|
} catch (error) { |
|
console.error('Failed to save highlighted events:', error); |
|
return isCurrentlyHighlighted; |
|
} |
|
}
|
|
|