Files
vuelato/app/composables/useRecentSearches.ts
Alejandro Martinez b8906efc80
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
Initial commit: Vuelato - buscador de vuelos
Nuxt 4 + Supabase + Flightics API. Incluye búsqueda de vuelos,
inspiraciones, watchlist, tracking de precios y mapa interactivo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 23:37:06 +02:00

45 lines
1.1 KiB
TypeScript

interface RecentSearch {
id: string
search_params: Record<string, any>
route_summary: string
search_mode: string
created_at: string
}
export function useRecentSearches() {
const supabase = useSupabaseClient()
const user = useSupabaseUser()
const searches = ref<RecentSearch[]>([])
const loading = ref(false)
async function fetchRecent(limit = 10) {
if (!user.value) return
loading.value = true
const { data } = await supabase
.from('recent_searches')
.select('*')
.order('created_at', { ascending: false })
.limit(limit)
searches.value = (data as RecentSearch[]) || []
loading.value = false
}
async function saveSearch(params: Record<string, any>, routeSummary: string, mode: string) {
if (!user.value) return
await supabase.from('recent_searches').insert({
user_id: user.value.id,
search_params: params,
route_summary: routeSummary,
search_mode: mode
})
}
watch(user, (u) => {
if (u) fetchRecent()
else searches.value = []
}, { immediate: true })
return { searches, loading, fetchRecent, saveSearch }
}