From 8a9bac8221146b5db4960cc10de3e29dcd75c9bf Mon Sep 17 00:00:00 2001 From: Nikita Kiselev Date: Mon, 5 Jan 2026 15:35:18 +0300 Subject: [PATCH] feat(search): improvement search cache (#44) --- frontend/spa/src/stores/SearchStore.js | 36 ++++++++++++++ frontend/spa/src/views/Search.vue | 49 ++++++++++++------- .../src/Handlers/ProductsHandler.php | 41 +++++++++++++++- .../upload/oc_telegram_shop/src/routes.php | 1 + 4 files changed, 106 insertions(+), 21 deletions(-) diff --git a/frontend/spa/src/stores/SearchStore.js b/frontend/spa/src/stores/SearchStore.js index 98886ea..9cde9e5 100644 --- a/frontend/spa/src/stores/SearchStore.js +++ b/frontend/spa/src/stores/SearchStore.js @@ -17,6 +17,13 @@ export const useSearchStore = defineStore('search', { isLoadingMore: false, isSearchPerformed: false, hasMore: false, + + // Placeholder товары для пустого состояния поиска + placeholderProducts: { + data: [], + total: 0, + }, + isLoadingPlaceholder: false, }), actions: { @@ -91,6 +98,35 @@ export const useSearchStore = defineStore('search', { this.isSearchPerformed = true; } }, + + async loadSearchPlaceholder() { + // Если данные уже есть в store, возвращаем их + if (this.placeholderProducts.data.length > 0) { + return { + data: this.placeholderProducts.data, + meta: { + total: this.placeholderProducts.total, + }, + }; + } + + try { + this.isLoadingPlaceholder = true; + // Иначе загружаем с сервера + const response = await ftch('productsSearchPlaceholder'); + this.placeholderProducts.data = response.data.slice(0, 3); + this.placeholderProducts.total = response?.meta?.total || 0; + + return { + data: this.placeholderProducts.data, + meta: { + total: this.placeholderProducts.total, + }, + }; + } finally { + this.isLoadingPlaceholder = false; + } + }, }, }); diff --git a/frontend/spa/src/views/Search.vue b/frontend/spa/src/views/Search.vue index aa7102c..8d8492b 100644 --- a/frontend/spa/src/views/Search.vue +++ b/frontend/spa/src/views/Search.vue @@ -79,25 +79,38 @@ class="flex flex-col items-center justify-center text-center py-16 px-10" >
-