feat: new settings and mainpage blocks
This commit is contained in:
32
frontend/spa/src/stores/BlocksStore.js
Normal file
32
frontend/spa/src/stores/BlocksStore.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {processBlock} from "@/utils/ftch.js";
|
||||
|
||||
export const useBlocksStore = defineStore('blocks', {
|
||||
state: () => ({
|
||||
blocks: [],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async processBlocks(rawBlocks) {
|
||||
const results = await Promise.allSettled(
|
||||
rawBlocks.map(block => {
|
||||
console.debug('[Blocks Store]: Process block ', block);
|
||||
return processBlock(block)
|
||||
.then(response => response);
|
||||
})
|
||||
);
|
||||
|
||||
this.blocks = results
|
||||
.map(r => {
|
||||
if (r.status === 'fulfilled') {
|
||||
return r.value.data;
|
||||
} else {
|
||||
return {
|
||||
is_enabled: true,
|
||||
type: 'error',
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -25,20 +25,6 @@ export const useCategoriesStore = defineStore('categories', {
|
||||
}
|
||||
},
|
||||
|
||||
async fetchTopCategories() {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
const response = await ftch('categoriesList', {
|
||||
forMainPage: true,
|
||||
});
|
||||
this.topCategories = response.data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async findCategoryById(id, list = []) {
|
||||
if (! id) return null;
|
||||
|
||||
|
||||
@@ -24,10 +24,11 @@ export const useSettingsStore = defineStore('settings', {
|
||||
}
|
||||
},
|
||||
texts: {
|
||||
no_more_products: 'Нет товаров',
|
||||
empty_cart: 'Корзина пуста',
|
||||
order_created_success: 'Заказ успешно оформлен.',
|
||||
text_no_more_products: 'Нет товаров',
|
||||
text_empty_cart: 'Корзина пуста',
|
||||
text_order_created_success: 'Заказ успешно оформлен.',
|
||||
},
|
||||
mainpage_blocks: [],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
@@ -51,6 +52,7 @@ export const useSettingsStore = defineStore('settings', {
|
||||
this.feature_vouchers = settings.feature_vouchers;
|
||||
this.currency_code = settings.currency_code;
|
||||
this.texts = settings.texts;
|
||||
this.mainpage_blocks = settings.mainpage_blocks;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {fetchBanner} from "@/utils/ftch.js";
|
||||
|
||||
export const useSlidersStore = defineStore('sliders', {
|
||||
state: () => ({
|
||||
mainpage_slider: {
|
||||
is_enabled: false,
|
||||
space_between: 30,
|
||||
autoplay: false,
|
||||
effect: 'cube', // null, flip, cards, cube
|
||||
pagination: false,
|
||||
scrollbar: false,
|
||||
free_mode: false,
|
||||
loop: false,
|
||||
slides: [],
|
||||
},
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async fetchMainpageSlider() {
|
||||
console.debug('[Sliders Store] Fetch mainpage slider from server.');
|
||||
const response = await fetchBanner();
|
||||
this.mainpage_slider = Object.assign({}, this.mainpage_slider, response.data);
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user