edit one business
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
<template>
|
||||
<WebAppLayout>
|
||||
<section class="space-y-5">
|
||||
<div v-if="bootstrapping" class="py-12 text-center text-sm text-muted">
|
||||
در حال بارگذاری…
|
||||
</div>
|
||||
|
||||
<section v-else class="space-y-5">
|
||||
<div>
|
||||
<h1 class="text-xl font-bold text-text">کشف خدمات</h1>
|
||||
<p class="mt-1 text-sm text-muted">کسبوکارهای محلی نزدیک شما</p>
|
||||
</div>
|
||||
|
||||
<div class="relative">
|
||||
<div v-if="showSearch" class="relative">
|
||||
<label class="sr-only" for="search">جستجو</label>
|
||||
<AppIcon
|
||||
name="search"
|
||||
@@ -22,11 +26,8 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="loadingCategories" class="text-center text-sm text-muted">
|
||||
در حال بارگذاری دستهها…
|
||||
</div>
|
||||
<CategoryFilter
|
||||
v-else-if="categories.length"
|
||||
v-if="showCategoryFilter"
|
||||
:categories="activeCategories"
|
||||
:selected-id="selectedCategoryId"
|
||||
@select="onCategorySelect"
|
||||
@@ -58,6 +59,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { fetchBusinessCategories } from '@/api/business-categories';
|
||||
import { fetchBusinesses } from '@/api/businesses';
|
||||
import { ApiError } from '@/api/client';
|
||||
@@ -67,18 +69,24 @@ import AppIcon from '@/components/ui/AppIcon.vue';
|
||||
import CategoryFilter from '@/components/business/CategoryFilter.vue';
|
||||
import WebAppLayout from '@/layouts/WebAppLayout.vue';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const categories = ref<BusinessCategory[]>([]);
|
||||
const businesses = ref<Business[]>([]);
|
||||
const selectedCategoryId = ref<string | null>(null);
|
||||
const searchQuery = ref('');
|
||||
const loadingCategories = ref(true);
|
||||
const loadingBusinesses = ref(true);
|
||||
const bootstrapping = ref(true);
|
||||
const loadingBusinesses = ref(false);
|
||||
const error = ref('');
|
||||
|
||||
const activeCategories = computed(() =>
|
||||
categories.value.filter((c) => c.isActive),
|
||||
);
|
||||
|
||||
const showCategoryFilter = computed(() => activeCategories.value.length > 1);
|
||||
|
||||
const showSearch = computed(() => businesses.value.length > 1);
|
||||
|
||||
const filteredBusinesses = computed(() => {
|
||||
const q = searchQuery.value.trim().toLowerCase();
|
||||
if (!q) {
|
||||
@@ -94,15 +102,14 @@ const filteredBusinesses = computed(() => {
|
||||
});
|
||||
|
||||
async function loadCategories() {
|
||||
loadingCategories.value = true;
|
||||
try {
|
||||
const all = await fetchBusinessCategories();
|
||||
categories.value = all;
|
||||
categories.value = await fetchBusinessCategories();
|
||||
if (activeCategories.value.length === 1) {
|
||||
selectedCategoryId.value = activeCategories.value[0].id;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value =
|
||||
e instanceof ApiError ? e.message : 'بارگذاری دستهها ناموفق بود.';
|
||||
} finally {
|
||||
loadingCategories.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +134,23 @@ function onCategorySelect(id: string | null) {
|
||||
}
|
||||
|
||||
watch(selectedCategoryId, () => {
|
||||
loadBusinesses();
|
||||
if (!bootstrapping.value) {
|
||||
void loadBusinesses();
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
void Promise.all([loadCategories(), loadBusinesses()]);
|
||||
onMounted(async () => {
|
||||
await loadCategories();
|
||||
await loadBusinesses();
|
||||
|
||||
if (businesses.value.length === 1) {
|
||||
await router.replace({
|
||||
name: 'app-business-detail',
|
||||
params: { id: businesses.value[0].id },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
bootstrapping.value = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user