feat: catalog read cache (api + user apps) and clearer Zarrin accounting errors
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
//
|
||||
// Not ported (no backend): promotionList, ignoreList, priceList, isLoaded.
|
||||
import { defineStore } from 'pinia'
|
||||
import { api } from '../api/client'
|
||||
import { useCatalogStore } from './catalogStore'
|
||||
import shippingArt from '../assets/img/shipping-and-delivery.png'
|
||||
import competitionArt from '../assets/img/sports-and-competition.png'
|
||||
import brandArt from '../assets/img/montzar-logo.png'
|
||||
@@ -70,20 +70,13 @@ export const useConfigStore = defineStore('config', {
|
||||
// Legacy's store.init() fanned out to /config, /promotion, /ignore, /price.
|
||||
// Here the only live source is the product catalogue, from which the real
|
||||
// category list is derived.
|
||||
async init() {
|
||||
// The catalogue comes from catalogStore, so calling this next to another
|
||||
// catalogue read costs no second request.
|
||||
async init(force = false) {
|
||||
try {
|
||||
const products = await api.listProducts()
|
||||
const seen = new Map<string, HomeCategory>()
|
||||
for (const p of products) {
|
||||
if (p.category && !seen.has(p.category.id)) {
|
||||
seen.set(p.category.id, {
|
||||
id: p.category.id,
|
||||
title: p.category.title,
|
||||
icon: { image: brandArt },
|
||||
})
|
||||
}
|
||||
}
|
||||
this.cats = [...seen.values()]
|
||||
const catalog = useCatalogStore()
|
||||
await catalog.load(force)
|
||||
this.cats = catalog.categories.map((c) => ({ ...c, icon: { image: brandArt } }))
|
||||
this.loaded = true
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
||||
Reference in New Issue
Block a user