feat: infinity scroll, load more, resore scroll

This commit is contained in:
Nikita Kiselev
2025-07-23 13:26:22 +03:00
parent 6a14ad0a74
commit bb2ee38118
9 changed files with 188 additions and 106 deletions

View File

@@ -3,34 +3,24 @@ import ftch from "../utils/ftch.js";
export const useProductsStore = defineStore('products', {
state: () => ({
homeProducts: {
data: [],
meta: {},
},
products: {
data: [],
meta: {},
},
page: 1,
isLoading: false,
hasMore: true,
savedCategoryId: null,
savedScrollY: 0,
}),
actions: {
async fetchHomeProducts() {
async fetchProducts(categoryId = null, page = 1) {
try {
this.isLoading = true;
this.homeProducts = await ftch('products');
} catch (error) {
console.error(error);
} finally {
this.isLoading = false;
}
},
async fetchProducts(categoryId = null) {
try {
this.isLoading = true;
this.products = await ftch('products', {
return await ftch('products', {
categoryId: categoryId,
page: page,
});
} catch (error) {
console.error(error);
@@ -38,5 +28,14 @@ export const useProductsStore = defineStore('products', {
this.isLoading = false;
}
},
reset() {
this.page = 1;
this.hasMore = true;
this.products = {
data: [],
meta: {},
};
}
},
});

View File

@@ -0,0 +1,12 @@
import {defineStore} from "pinia";
export const useSettingsStore = defineStore('settings', {
state: () => ({
night_auto: true,
theme: {
light: 'light',
dark: 'dark',
},
noMoreProductsMessage: '🔚 Ну всё, разгрузили всё, что было. Даже кладовщика разбудить не удалось.',
}),
});