- Change project title from "Atitlán Directory" to "Ariège Hub" in index.html - Update app title in meta tags for PWA support - Add @tanstack/vue-table dependency for enhanced table management - Refactor ConnectionStatus component to improve status variant logic - Enhance useEvents composable for better error handling and sorting - Add 'events' translation to Spanish and French locales - Create a new Pinia store for Nostr state management
55 lines
1.2 KiB
TypeScript
55 lines
1.2 KiB
TypeScript
import { computed } from 'vue'
|
|
import { useAsyncState } from '@vueuse/core'
|
|
import type { Event } from '@/lib/types/event'
|
|
import { fetchEvents } from '@/lib/api/events'
|
|
|
|
export function useEvents() {
|
|
const { state: events, isLoading, error: asyncError, execute: refresh } = useAsyncState(
|
|
fetchEvents,
|
|
[] as Event[],
|
|
{
|
|
immediate: true,
|
|
resetOnExecute: false,
|
|
}
|
|
)
|
|
|
|
const error = computed(() => {
|
|
if (asyncError.value) {
|
|
return {
|
|
message: asyncError.value instanceof Error
|
|
? asyncError.value.message
|
|
: 'An error occurred while fetching events'
|
|
}
|
|
}
|
|
return null
|
|
})
|
|
|
|
const sortedEvents = computed(() => {
|
|
return [...events.value].sort((a, b) =>
|
|
new Date(b.time).getTime() - new Date(a.time).getTime()
|
|
)
|
|
})
|
|
|
|
const upcomingEvents = computed(() => {
|
|
const now = new Date()
|
|
return sortedEvents.value.filter(event =>
|
|
new Date(event.event_start_date) > now
|
|
)
|
|
})
|
|
|
|
const pastEvents = computed(() => {
|
|
const now = new Date()
|
|
return sortedEvents.value.filter(event =>
|
|
new Date(event.event_end_date) < now
|
|
)
|
|
})
|
|
|
|
return {
|
|
events: sortedEvents,
|
|
upcomingEvents,
|
|
pastEvents,
|
|
isLoading,
|
|
error,
|
|
refresh,
|
|
}
|
|
}
|