fix altro
This commit is contained in:
@@ -26,9 +26,12 @@ export const useCatalogStore = defineStore('CatalogStore', {
|
||||
}),
|
||||
|
||||
getters: {
|
||||
getCatalogById: (state) => (id: string) => {
|
||||
getCatalogById: (state) => (id: string): ICatalog => {
|
||||
return state.catalogs.find((cat: ICatalog) => cat._id === id) || null;
|
||||
},
|
||||
getCatalogByIdPageAssigned: (state) => (idPage: string): ICatalog => {
|
||||
return state.catalogs.find((cat: ICatalog) => cat.idPageAssigned === idPage) || null;
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
@@ -37,10 +40,10 @@ export const useCatalogStore = defineStore('CatalogStore', {
|
||||
let cat = this.getCatalogById(id);
|
||||
if (!cat || !cat.prodotti_caricati_inmem) {
|
||||
// Carica dal server
|
||||
const ris = await this.loadCatalogById(id);
|
||||
if (ris) {
|
||||
const catalog = await this.loadCatalogById(id);
|
||||
if (catalog) {
|
||||
// Aggiorna lo store con i dati ricevuti
|
||||
this.updateDataCatalog(ris);
|
||||
this.updateDataCatalog(catalog);
|
||||
cat = this.getCatalogById(id);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +60,7 @@ export const useCatalogStore = defineStore('CatalogStore', {
|
||||
console.log('catalogs', res.data.catalog);
|
||||
if (res.data.catalog) {
|
||||
// console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
return res.data.product;
|
||||
return res.data.catalog;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
@@ -89,12 +92,12 @@ export const useCatalogStore = defineStore('CatalogStore', {
|
||||
}
|
||||
},
|
||||
|
||||
updateDataCatalog(res: any) {
|
||||
if (res && res.data.catalog) {
|
||||
updateDataCatalog(catalog: ICatalog) {
|
||||
if (catalog) {
|
||||
// Update catalog from server
|
||||
const indelem = this.catalogs.findIndex((catalog: ICatalogCompleto) => catalog._id === res.data.catalog._id);
|
||||
const indelem = this.catalogs.findIndex((catalog: ICatalogCompleto) => catalog._id === catalog._id);
|
||||
if (indelem >= 0) {
|
||||
this.catalogs[indelem] = { ...res.data.catalog };
|
||||
this.catalogs[indelem] = { ...catalog };
|
||||
this.catalogs[indelem].prodotti_caricati_inmem = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user