Implement Smart Location: auto-detect user location if preference is enabled, hide location button, and handle permission denial by resetting preference
This commit is contained in:
@ -3,11 +3,13 @@ import { ref, onMounted, computed } from 'vue'
|
||||
import { businessService } from '@/services/businessService'
|
||||
import type { Business } from '@/types'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import FavoriteButton from '@/components/FavoriteButton.vue'
|
||||
import { analyticsService } from '@/services/analyticsService'
|
||||
import { getImageUrl } from '@/utils/imageUrl'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const businesses = ref<Business[]>([])
|
||||
const isLoading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
@ -16,14 +18,19 @@ const selectedCategory = ref('Todas')
|
||||
const selectedArea = ref('Todas')
|
||||
|
||||
// ── Categorías con emoji e ícono material
|
||||
const CATEGORY_META: Record<string, { emoji: string; icon: string }> = {
|
||||
'Todas': { emoji: '✨', icon: 'apps' },
|
||||
'Restaurante': { emoji: '🍽️', icon: 'restaurant' },
|
||||
'Hotel': { emoji: '🏨', icon: 'hotel' },
|
||||
'Café': { emoji: '☕', icon: 'local_cafe' },
|
||||
'Comercio': { emoji: '🏪', icon: 'store' },
|
||||
'Turismo': { emoji: '🌄', icon: 'landscape' },
|
||||
'Bebidas': { emoji: '🍹', icon: 'local_bar' },
|
||||
const CATEGORY_META: Record<string, { emoji: string; icon: string; key: string }> = {
|
||||
'Todas': { emoji: '✨', icon: 'apps', key: 'discover.categories.all' },
|
||||
'Restaurante': { emoji: '🍽️', icon: 'restaurant', key: 'discover.categories.restaurant' },
|
||||
'Hotel': { emoji: '🏨', icon: 'hotel', key: 'discover.categories.hotel' },
|
||||
'Café': { emoji: '☕', icon: 'local_cafe', key: 'discover.categories.cafe' },
|
||||
'Comercio': { emoji: '🏪', icon: 'store', key: 'discover.categories.commerce' },
|
||||
'Turismo': { emoji: '🌄', icon: 'landscape', key: 'discover.categories.tourism' },
|
||||
'Bebidas': { emoji: '🍹', icon: 'local_bar', key: 'discover.categories.drinks' },
|
||||
}
|
||||
|
||||
function catName(cat: string) {
|
||||
const meta = CATEGORY_META[cat]
|
||||
return meta ? t(meta.key) : cat
|
||||
}
|
||||
|
||||
function catEmoji(cat: string) {
|
||||
@ -40,7 +47,7 @@ async function loadBusinesses() {
|
||||
businesses.value = await businessService.getAllBusinesses()
|
||||
} catch (e) {
|
||||
console.error('Error loading businesses:', e)
|
||||
error.value = 'No se pudieron cargar los lugares. Revisa tu conexión.'
|
||||
error.value = t('discover.error')
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
@ -100,6 +107,9 @@ function handleExplore(biz: Business) {
|
||||
|
||||
|
||||
function resetFilters() {
|
||||
selectedCategory.value = 'Todas'
|
||||
selectedArea.value = t('discover.allAreas') === 'All' ? 'Todas' : 'Todas' // Simplified to keep internal logic consistent
|
||||
// Using strings as keys for internal logic, translating only for display
|
||||
selectedCategory.value = 'Todas'
|
||||
selectedArea.value = 'Todas'
|
||||
searchQuery.value = ''
|
||||
@ -112,8 +122,8 @@ function resetFilters() {
|
||||
<!-- ── HEADER ── -->
|
||||
<header class="disc-header">
|
||||
<div class="header-body">
|
||||
<h1 class="disc-title">¡Explora Chiriquí! 🌿</h1>
|
||||
<p class="disc-sub">Descubre los mejores lugares cerca de ti</p>
|
||||
<h1 class="disc-title">{{ t('discover.title') }}</h1>
|
||||
<p class="disc-sub">{{ t('discover.subtitle') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Búsqueda -->
|
||||
@ -123,7 +133,7 @@ function resetFilters() {
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
class="search-input"
|
||||
placeholder="Buscar restaurantes, hoteles..."
|
||||
:placeholder="t('discover.searchPlaceholder')"
|
||||
/>
|
||||
<button v-if="searchQuery" class="search-clear" @click="searchQuery = ''">
|
||||
<span class="material-icons">close</span>
|
||||
@ -141,7 +151,7 @@ function resetFilters() {
|
||||
:class="{ 'cat-chip--active': selectedCategory === cat }"
|
||||
@click="selectedCategory = cat"
|
||||
>
|
||||
{{ catEmoji(cat) }} {{ cat }}
|
||||
{{ catEmoji(cat) }} {{ catName(cat) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -149,7 +159,7 @@ function resetFilters() {
|
||||
<!-- ── LOADING ── -->
|
||||
<div v-if="isLoading" class="state-center">
|
||||
<div class="spinner"></div>
|
||||
<p>Cargando lugares...</p>
|
||||
<p>{{ t('discover.loading') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- ── ERROR ── -->
|
||||
@ -158,7 +168,7 @@ function resetFilters() {
|
||||
<p style="font-weight: 600; color: var(--text-secondary);">{{ error }}</p>
|
||||
<button class="cta-btn" style="margin-top: 1rem;" @click="loadBusinesses">
|
||||
<span class="material-icons">refresh</span>
|
||||
Reintentar
|
||||
{{ t('common.retry') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@ -184,14 +194,13 @@ function resetFilters() {
|
||||
<!-- Contador de resultados -->
|
||||
<div class="results-bar">
|
||||
<span class="results-count">
|
||||
{{ filteredBusinesses.length }}
|
||||
{{ filteredBusinesses.length === 1 ? 'lugar' : 'lugares' }}
|
||||
<template v-if="selectedCategory !== 'Todas'"> en {{ selectedCategory }}</template>
|
||||
{{ t('discover.results', { count: filteredBusinesses.length }) }}
|
||||
<template v-if="selectedCategory !== 'Todas'"> {{ t('discover.in') }} {{ catName(selectedCategory) }}</template>
|
||||
<template v-if="selectedArea !== 'Todas'"> · {{ selectedArea }}</template>
|
||||
</span>
|
||||
<button class="reset-btn" @click="resetFilters">
|
||||
<span class="material-icons">refresh</span>
|
||||
Limpiar
|
||||
{{ t('common.clear') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@ -218,7 +227,7 @@ function resetFilters() {
|
||||
</div>
|
||||
<span class="biz-cat-badge">
|
||||
<span class="material-icons" style="font-size:0.875rem">{{ catIcon(biz.category || '') }}</span>
|
||||
{{ biz.category }}
|
||||
{{ catName(biz.category || '') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="biz-body">
|
||||
@ -234,16 +243,16 @@ function resetFilters() {
|
||||
<!-- Vacío -->
|
||||
<div v-else class="empty-state">
|
||||
<span class="material-icons empty-icon">search_off</span>
|
||||
<h2 class="empty-title">Sin resultados</h2>
|
||||
<p class="empty-sub">No encontramos lugares con ese filtro.</p>
|
||||
<button class="cta-btn" @click="resetFilters">Ver todos los lugares</button>
|
||||
<h2 class="empty-title">{{ t('discover.noResults') }}</h2>
|
||||
<p class="empty-sub">{{ t('discover.noResultsDesc') }}</p>
|
||||
<button class="cta-btn" @click="resetFilters">{{ t('discover.viewAll') }}</button>
|
||||
</div>
|
||||
|
||||
<!-- CTA al final -->
|
||||
<div v-if="filteredBusinesses.length > 0" class="more-card" @click="resetFilters">
|
||||
<p class="more-card-title">¿Buscas algo más?</p>
|
||||
<p class="more-card-sub">Explora sin filtros para descubrir todo</p>
|
||||
<button class="cta-btn">Ver todo</button>
|
||||
<p class="more-card-title">{{ t('discover.lookingMore') }}</p>
|
||||
<p class="more-card-sub">{{ t('discover.exploreWithoutFilters') }}</p>
|
||||
<button class="cta-btn">{{ t('common.all') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -252,7 +261,7 @@ function resetFilters() {
|
||||
|
||||
<!-- CHIPS DE ÁREA -->
|
||||
<div v-if="areas.length > 0" class="area-section">
|
||||
<p class="section-label">🗺️ Por Área</p>
|
||||
<p class="section-label">{{ t('discover.sections.byArea') }}</p>
|
||||
<div class="area-chips">
|
||||
<button
|
||||
v-for="area in areas"
|
||||
@ -269,7 +278,7 @@ function resetFilters() {
|
||||
|
||||
<!-- DESTACADOS -->
|
||||
<div v-if="featuredBusinesses.length > 0" class="featured-section">
|
||||
<p class="section-label">✨ Destacados</p>
|
||||
<p class="section-label">{{ t('discover.sections.featured') }}</p>
|
||||
<div class="featured-grid">
|
||||
<div
|
||||
v-for="biz in featuredBusinesses"
|
||||
@ -293,7 +302,7 @@ function resetFilters() {
|
||||
<div class="featured-info">
|
||||
<span class="featured-cat">
|
||||
<span class="material-icons" style="font-size:0.8rem">{{ catIcon(biz.category || '') }}</span>
|
||||
{{ biz.category }}
|
||||
{{ catName(biz.category || '') }}
|
||||
</span>
|
||||
<p class="featured-name">{{ biz.name }}</p>
|
||||
<p class="featured-area">
|
||||
@ -307,7 +316,7 @@ function resetFilters() {
|
||||
|
||||
<!-- TODOS LOS LUGARES -->
|
||||
<div v-if="gridBusinesses.length > 0" class="all-section">
|
||||
<p class="section-label">🏙️ Todos los lugares</p>
|
||||
<p class="section-label">{{ t('discover.sections.allPlaces') }}</p>
|
||||
<TransitionGroup name="fade" tag="div" class="biz-grid">
|
||||
<div
|
||||
v-for="biz in gridBusinesses"
|
||||
@ -330,7 +339,7 @@ function resetFilters() {
|
||||
</div>
|
||||
<span class="biz-cat-badge">
|
||||
<span class="material-icons" style="font-size:0.875rem">{{ catIcon(biz.category || '') }}</span>
|
||||
{{ biz.category }}
|
||||
{{ catName(biz.category || '') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="biz-body">
|
||||
@ -346,8 +355,8 @@ function resetFilters() {
|
||||
|
||||
<div v-if="businesses.length === 0" class="empty-state">
|
||||
<span class="material-icons empty-icon">storefront</span>
|
||||
<h2 class="empty-title">Sin lugares aún</h2>
|
||||
<p class="empty-sub">Pronto habrá negocios y lugares turísticos disponibles aquí.</p>
|
||||
<h2 class="empty-title">{{ t('discover.empty') }}</h2>
|
||||
<p class="empty-sub">{{ t('discover.emptyDesc') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -357,7 +366,7 @@ function resetFilters() {
|
||||
<style scoped>
|
||||
/* ═══════════════════════════════════════════
|
||||
BASE
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.disc-page {
|
||||
min-height: 100vh;
|
||||
background: var(--bg-primary);
|
||||
@ -366,7 +375,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
HEADER
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.disc-header {
|
||||
padding: 1.25rem 1.25rem 0.75rem;
|
||||
background: var(--bg-secondary);
|
||||
@ -433,7 +442,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
CHIPS DE CATEGORÍA
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.cat-chips-wrap {
|
||||
background: var(--bg-secondary);
|
||||
padding: 0.75rem 0;
|
||||
@ -481,7 +490,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
CONTENIDO
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.disc-content {
|
||||
padding: 1.25rem;
|
||||
display: flex;
|
||||
@ -502,7 +511,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
CHIPS DE ÁREA
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.area-section { display: flex; flex-direction: column; }
|
||||
|
||||
.area-chips {
|
||||
@ -539,7 +548,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
SECCIÓN DESTACADOS
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.featured-section { display: flex; flex-direction: column; }
|
||||
|
||||
.featured-grid {
|
||||
@ -623,7 +632,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
GRID DE NEGOCIOS
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.all-section { display: flex; flex-direction: column; }
|
||||
|
||||
.biz-grid {
|
||||
@ -707,7 +716,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
BARRA DE RESULTADOS
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.results-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@ -742,7 +751,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
TARJETA "MÁS"
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.more-card {
|
||||
background: var(--bg-secondary);
|
||||
border: 1.5px dashed var(--border-color);
|
||||
@ -770,7 +779,7 @@ function resetFilters() {
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
CTA Y VACÍO
|
||||
═══════════════════════════════════════════ */
|
||||
═══════════════════════════════════════════ */
|
||||
.cta-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@ -798,7 +807,7 @@ function resetFilters() {
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 3.5rem;
|
||||
font-size: 4rem;
|
||||
color: var(--text-secondary);
|
||||
opacity: 0.3;
|
||||
margin-bottom: 1rem;
|
||||
@ -808,54 +817,25 @@ function resetFilters() {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 900;
|
||||
color: var(--text-primary);
|
||||
margin: 0 0 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.empty-sub {
|
||||
font-size: 0.9375rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
margin: 0 0 1.5rem;
|
||||
line-height: 1.5;
|
||||
max-width: 280px;
|
||||
}
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
LOADING / SPINNER
|
||||
═══════════════════════════════════════════ */
|
||||
.state-center {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 4rem 1.25rem;
|
||||
gap: 1rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border: 2.5px solid var(--border-color);
|
||||
border-top-color: var(--active-color);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.75s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
TRANSICIÓN DE TARJETAS
|
||||
═══════════════════════════════════════════ */
|
||||
.fade-enter-active { transition: opacity 0.25s ease, transform 0.25s ease; }
|
||||
.fade-enter-from { opacity: 0; transform: translateY(8px); }
|
||||
/* Transitions */
|
||||
.fade-enter-active, .fade-leave-active { transition: all 0.3s ease; }
|
||||
.fade-enter-from, .fade-leave-to { opacity: 0; transform: translateY(10px); }
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
RESPONSIVE
|
||||
═══════════════════════════════════════════ */
|
||||
@media (min-width: 560px) {
|
||||
.biz-grid { grid-template-columns: repeat(3, 1fr); }
|
||||
}
|
||||
|
||||
@media (max-width: 360px) {
|
||||
.featured-grid { grid-template-columns: 1fr; }
|
||||
.featured-card { aspect-ratio: 4/3; }
|
||||
═══════════════════════════════════════════ */
|
||||
@media (max-width: 480px) {
|
||||
.biz-grid, .featured-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user