Initial commit: Vuelato - buscador de vuelos
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
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>
This commit is contained in:
32
app/composables/useDestinationImages.ts
Normal file
32
app/composables/useDestinationImages.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
const imageCache = reactive<Record<string, { thumb_url: string; image_url: string; photographer: string; photographer_url: string } | null>>({})
|
||||
const pending = new Set<string>()
|
||||
|
||||
export function useDestinationImages() {
|
||||
async function fetchImage(cityName: string) {
|
||||
const key = cityName.trim().toLowerCase()
|
||||
if (key in imageCache || pending.has(key)) return
|
||||
pending.add(key)
|
||||
|
||||
try {
|
||||
const data = await $fetch<{ thumb_url: string; image_url: string; photographer: string; photographer_url: string } | null>('/api/destination-image', {
|
||||
query: { city: cityName },
|
||||
})
|
||||
imageCache[key] = data
|
||||
} catch {
|
||||
imageCache[key] = null
|
||||
} finally {
|
||||
pending.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
function getImage(cityName: string) {
|
||||
const key = cityName.trim().toLowerCase()
|
||||
return imageCache[key] ?? null
|
||||
}
|
||||
|
||||
function prefetch(cityNames: string[]) {
|
||||
cityNames.forEach(name => fetchImage(name))
|
||||
}
|
||||
|
||||
return { fetchImage, getImage, prefetch, imageCache }
|
||||
}
|
||||
Reference in New Issue
Block a user