feat(categories): add skeleton for categories loading

This commit is contained in:
2025-09-24 17:31:45 +03:00
parent 0f04cbf105
commit 294e0cd17e
3 changed files with 38 additions and 27 deletions

View File

@@ -52,7 +52,6 @@ settings.load()
console.log('Load front page categories and products.'); console.log('Load front page categories and products.');
const categoriesStore = useCategoriesStore(); const categoriesStore = useCategoriesStore();
categoriesStore.fetchTopCategories(); categoriesStore.fetchTopCategories();
categoriesStore.fetchCategories();
}) })
.then(() => new AppMetaInitializer(settings).init()) .then(() => new AppMetaInitializer(settings).init())
.then(() => { appLoading.unmount(); app.mount('#app'); }) .then(() => { appLoading.unmount(); app.mount('#app'); })

View File

@@ -6,15 +6,17 @@ export const useCategoriesStore = defineStore('categories', {
topCategories: [], topCategories: [],
categories: [], categories: [],
isLoading: false, isLoading: false,
isCategoriesLoaded: false,
}), }),
actions: { actions: {
async fetchCategories() { async fetchCategories() {
if (this.isLoading === false && this.categories.length === 0) { if (this.isCategoriesLoaded === false && this.categories.length === 0) {
try { try {
this.isLoading = true; this.isLoading = true;
const {data} = await ftch('categoriesList'); const {data} = await ftch('categoriesList');
this.categories = data; this.categories = data;
this.isCategoriesLoaded = true;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {

View File

@@ -2,6 +2,15 @@
<div class="mx-auto max-w-2xl px-4 py-4 sm:px-6 sm:py-24 lg:max-w-7xl lg:px-8 mb-5 safe-top"> <div class="mx-auto max-w-2xl px-4 py-4 sm:px-6 sm:py-24 lg:max-w-7xl lg:px-8 mb-5 safe-top">
<h2 class="text-3xl mb-5">Категории</h2> <h2 class="text-3xl mb-5">Категории</h2>
<div v-if="categoriesStore.isLoading" class="flex flex-col gap-4">
<div class="skeleton h-14 w-full"></div>
<div class="skeleton h-14 w-full"></div>
<div class="skeleton h-14 w-full"></div>
<div class="skeleton h-14 w-full"></div>
<div class="skeleton h-14 w-full"></div>
</div>
<template v-else>
<button v-if="parentId && parentCategory" class="py-2 px-4 flex items-center mb-3 cursor-pointer" @click="goBack"> <button v-if="parentId && parentCategory" class="py-2 px-4 flex items-center mb-3 cursor-pointer" @click="goBack">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6 min-w-6"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6 min-w-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5 3 12m0 0 7.5-7.5M3 12h18" /> <path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5 3 12m0 0 7.5-7.5M3 12h18" />
@@ -28,6 +37,7 @@
@onSelect="onSelect" @onSelect="onSelect"
/> />
</div> </div>
</template>
</div> </div>
</template> </template>