Adds scheduled events to the feed
Implements NIP-52 scheduled events, allowing users to view and interact with calendar events. A new `ScheduledEventService` is introduced to manage fetching, storing, and completing scheduled events. A new `ScheduledEventCard` component is introduced for displaying the scheduled events.
This commit is contained in:
parent
875bf50765
commit
b15a8c21c0
8 changed files with 716 additions and 1 deletions
143
src/modules/nostr-feed/composables/useScheduledEvents.ts
Normal file
143
src/modules/nostr-feed/composables/useScheduledEvents.ts
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
import { computed } from 'vue'
|
||||
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||
import type { ScheduledEventService, ScheduledEvent, EventCompletion } from '../services/ScheduledEventService'
|
||||
import { useToast } from '@/core/composables/useToast'
|
||||
|
||||
/**
|
||||
* Composable for managing scheduled events in the feed
|
||||
*/
|
||||
export function useScheduledEvents() {
|
||||
const scheduledEventService = injectService<ScheduledEventService>(SERVICE_TOKENS.SCHEDULED_EVENT_SERVICE)
|
||||
const toast = useToast()
|
||||
|
||||
/**
|
||||
* Get all scheduled events
|
||||
*/
|
||||
const getScheduledEvents = (): ScheduledEvent[] => {
|
||||
if (!scheduledEventService) return []
|
||||
return scheduledEventService.getScheduledEvents()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get events for a specific date (YYYY-MM-DD)
|
||||
*/
|
||||
const getEventsForDate = (date: string): ScheduledEvent[] => {
|
||||
if (!scheduledEventService) return []
|
||||
return scheduledEventService.getEventsForDate(date)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get today's scheduled events
|
||||
*/
|
||||
const getTodaysEvents = (): ScheduledEvent[] => {
|
||||
if (!scheduledEventService) return []
|
||||
return scheduledEventService.getTodaysEvents()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get completion status for an event
|
||||
*/
|
||||
const getCompletion = (eventAddress: string): EventCompletion | undefined => {
|
||||
if (!scheduledEventService) return undefined
|
||||
return scheduledEventService.getCompletion(eventAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an event is completed
|
||||
*/
|
||||
const isCompleted = (eventAddress: string): boolean => {
|
||||
if (!scheduledEventService) return false
|
||||
return scheduledEventService.isCompleted(eventAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle completion status of an event
|
||||
*/
|
||||
const toggleComplete = async (event: ScheduledEvent, notes: string = ''): Promise<void> => {
|
||||
if (!scheduledEventService) {
|
||||
toast.error('Scheduled event service not available')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const eventAddress = `31922:${event.pubkey}:${event.dTag}`
|
||||
const currentlyCompleted = scheduledEventService.isCompleted(eventAddress)
|
||||
|
||||
if (currentlyCompleted) {
|
||||
await scheduledEventService.uncompleteEvent(event)
|
||||
toast.success('Event marked as incomplete')
|
||||
} else {
|
||||
await scheduledEventService.completeEvent(event, notes)
|
||||
toast.success('Event completed!')
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to toggle completion'
|
||||
|
||||
if (message.includes('authenticated')) {
|
||||
toast.error('Please sign in to complete events')
|
||||
} else if (message.includes('Not connected')) {
|
||||
toast.error('Not connected to relays')
|
||||
} else {
|
||||
toast.error(message)
|
||||
}
|
||||
|
||||
console.error('Failed to toggle completion:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete an event with optional notes
|
||||
*/
|
||||
const completeEvent = async (event: ScheduledEvent, notes: string = ''): Promise<void> => {
|
||||
if (!scheduledEventService) {
|
||||
toast.error('Scheduled event service not available')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await scheduledEventService.completeEvent(event, notes)
|
||||
toast.success('Event completed!')
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to complete event'
|
||||
toast.error(message)
|
||||
console.error('Failed to complete event:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get loading state
|
||||
*/
|
||||
const isLoading = computed(() => {
|
||||
return scheduledEventService?.isLoading ?? false
|
||||
})
|
||||
|
||||
/**
|
||||
* Get all scheduled events (reactive)
|
||||
*/
|
||||
const allScheduledEvents = computed(() => {
|
||||
return scheduledEventService?.scheduledEvents ?? new Map()
|
||||
})
|
||||
|
||||
/**
|
||||
* Get all completions (reactive)
|
||||
*/
|
||||
const allCompletions = computed(() => {
|
||||
return scheduledEventService?.completions ?? new Map()
|
||||
})
|
||||
|
||||
return {
|
||||
// Methods
|
||||
getScheduledEvents,
|
||||
getEventsForDate,
|
||||
getTodaysEvents,
|
||||
getCompletion,
|
||||
isCompleted,
|
||||
toggleComplete,
|
||||
completeEvent,
|
||||
|
||||
// State
|
||||
isLoading,
|
||||
allScheduledEvents,
|
||||
allCompletions
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue