feat: cache frontpage products and categories
This commit is contained in:
@@ -74,7 +74,7 @@ async function loadMore() {
|
||||
|
||||
productsStore.isLoading = true;
|
||||
try {
|
||||
const response = await productsStore.fetchProducts(categoryId, productsStore.page);
|
||||
const response = await productsStore.fetchProducts(categoryId, productsStore.page, true);
|
||||
productsStore.hasMore = response.meta.hasMore ?? false;
|
||||
productsStore.products.data.push(...response.data);
|
||||
productsStore.products.meta.currentCategoryName = response.meta.currentCategoryName;
|
||||
|
||||
@@ -17,13 +17,14 @@ export const useProductsStore = defineStore('products', {
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async fetchProducts(categoryId = null, page = 1) {
|
||||
async fetchProducts(categoryId = null, page = 1, forMainPage = false) {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
return await ftch('products', {
|
||||
categoryId: categoryId,
|
||||
page: page,
|
||||
search: this.search,
|
||||
forMainPage: forMainPage,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user