feat(activities): merge own events into the feed
When authenticated, parallel-fetch the caller's own events (any status) alongside the public approved feed and merge with public-wins dedup. Without this, an event that drops to `proposed` after a non-admin edit disappears from the user's view — they couldn't find it to make a follow-up edit or watch for re-approval. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3047565920
commit
01b871e7fa
1 changed files with 30 additions and 1 deletions
|
|
@ -1,14 +1,43 @@
|
|||
import { computed } from 'vue'
|
||||
import { useAsyncState } from '@vueuse/core'
|
||||
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||
import { useAuth } from '@/composables/useAuthService'
|
||||
import type { TicketApiService } from '../services/TicketApiService'
|
||||
import type { TicketedEvent } from '../types/ticket'
|
||||
|
||||
export function useEvents() {
|
||||
const ticketApi = injectService(SERVICE_TOKENS.TICKET_API) as TicketApiService
|
||||
const { isAuthenticated, currentUser } = useAuth()
|
||||
|
||||
// When authenticated, also fetch the user's own events (any status)
|
||||
// and merge them into the feed. Otherwise an event that drops to
|
||||
// `proposed` after a non-admin edit disappears from the user's view
|
||||
// entirely — they'd be unable to find it to make a follow-up edit or
|
||||
// monitor its approval status. Public approved events from other
|
||||
// users take precedence on dedup (server is the source of truth for
|
||||
// the public view).
|
||||
const fetchAll = async (): Promise<TicketedEvent[]> => {
|
||||
const publicEvents = (await ticketApi.fetchTicketedEvents()) as TicketedEvent[]
|
||||
|
||||
if (!isAuthenticated.value) return publicEvents
|
||||
|
||||
const invoiceKey = currentUser.value?.wallets?.[0]?.inkey
|
||||
if (!invoiceKey) return publicEvents
|
||||
|
||||
try {
|
||||
const myEvents = (await ticketApi.fetchMyEvents(invoiceKey)) as TicketedEvent[]
|
||||
const seen = new Set(publicEvents.map((e) => e.id))
|
||||
const own = myEvents.filter((e) => !seen.has(e.id))
|
||||
return [...publicEvents, ...own]
|
||||
} catch {
|
||||
// Falling back to just the public feed is acceptable — the user
|
||||
// can still browse, they just won't see their own pending events.
|
||||
return publicEvents
|
||||
}
|
||||
}
|
||||
|
||||
const { state: events, isLoading, error: asyncError, execute: refresh } = useAsyncState(
|
||||
() => ticketApi.fetchTicketedEvents() as Promise<TicketedEvent[]>,
|
||||
fetchAll,
|
||||
[] as TicketedEvent[],
|
||||
{
|
||||
immediate: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue