feat: infinity scroll, load more, resore scroll
This commit is contained in:
@@ -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: {},
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
12
spa/src/stores/SettingsStore.js
Normal file
12
spa/src/stores/SettingsStore.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import {defineStore} from "pinia";
|
||||
|
||||
export const useSettingsStore = defineStore('settings', {
|
||||
state: () => ({
|
||||
night_auto: true,
|
||||
theme: {
|
||||
light: 'light',
|
||||
dark: 'dark',
|
||||
},
|
||||
noMoreProductsMessage: '🔚 Ну всё, разгрузили всё, что было. Даже кладовщика разбудить не удалось.',
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user