Enables marking scheduled events as complete

Implements a feature to mark scheduled events as complete, replacing the checkbox with a button for improved UX.

This commit enhances the Scheduled Events functionality by allowing users to mark events as complete. It also includes:

- Replaces the checkbox with a "Mark Complete" button for better usability.
- Adds logging for debugging purposes during event completion toggling.
- Routes completion events (kind 31925) to the ScheduledEventService.
- Optimistically updates the local state after publishing completion events.
This commit is contained in:
padreug 2025-10-21 22:31:35 +02:00
parent f60ed472c5
commit 484e39eba8
5 changed files with 91 additions and 60 deletions

View file

@ -113,6 +113,8 @@ export class ScheduledEventService extends BaseService {
* Made public so FeedService can route kind 31925 events to this service
*/
public handleCompletionEvent(event: NostrEvent): void {
console.log('🔔 ScheduledEventService: Received completion event (kind 31925)', event.id)
try {
// Find the event being responded to
const aTag = event.tags.find(tag => tag[0] === 'a')?.[1]
@ -125,6 +127,13 @@ export class ScheduledEventService extends BaseService {
const completedAtTag = event.tags.find(tag => tag[0] === 'completed_at')?.[1]
const completedAt = completedAtTag ? parseInt(completedAtTag) : undefined
console.log('📋 Completion details:', {
aTag,
completed,
pubkey: event.pubkey,
eventId: event.id
})
const completion: EventCompletion = {
id: event.id,
eventAddress: aTag,
@ -139,6 +148,9 @@ export class ScheduledEventService extends BaseService {
const existing = this._completions.get(aTag)
if (!existing || event.created_at > existing.created_at) {
this._completions.set(aTag, completion)
console.log('✅ Stored completion for:', aTag, '- completed:', completed)
} else {
console.log('⏭️ Skipped older completion for:', aTag)
}
} catch (error) {
@ -228,9 +240,12 @@ export class ScheduledEventService extends BaseService {
const signedEvent = finalizeEvent(eventTemplate, privkeyBytes)
// Publish the completion
await this.relayHub.publishEvent(signedEvent)
console.log('📤 Publishing completion event (kind 31925) for:', eventAddress)
const result = await this.relayHub.publishEvent(signedEvent)
console.log('✅ Completion event published to', result.success, '/', result.total, 'relays')
// Optimistically update local state
console.log('🔄 Optimistically updating local state')
this.handleCompletionEvent(signedEvent)
} catch (error) {