Whole site refactor. Added pinia stores and authentication capability.
This commit is contained in:
27
src/stores/categories.store.ts
Normal file
27
src/stores/categories.store.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { Category } from '@/main'
|
||||
import { ref } from 'vue'
|
||||
import { axiosInstance } from '@/main'
|
||||
|
||||
export const useCategoriesStore = defineStore('categories', () => {
|
||||
const categories = ref<Array<Category>>([]);
|
||||
|
||||
async function fetchCategories() {
|
||||
const response = await axiosInstance.get('/towary', {withCredentials: true});
|
||||
categories.value = response.data;
|
||||
|
||||
if(categories.value != undefined) {
|
||||
for (const category of categories.value) {
|
||||
for (const product of category.Towary) {
|
||||
product.Options = new Array(product.Twr_JM);
|
||||
product.ChosenOption = product.Twr_JM;
|
||||
if (product.Twr_JMZ != null) {
|
||||
product.Options.push(product.Twr_JMZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {categories, fetchCategories}
|
||||
})
|
||||
Reference in New Issue
Block a user