- Replace the crown logo with logo.svg / logo_bk.svg across both frontends; regenerate favicons and PWA icons via scripts/generate-brand-icons.cjs - Custom button: admin chooses whether it shows before login or only after - Dashboard: drop the survey-majority banner, hide the custom-order row Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
3.6 KiB
TypeScript
95 lines
3.6 KiB
TypeScript
// Scoped port of legacy henza_pwa/src/store/store.ts.
|
|
//
|
|
// Legacy fetched one curated payload (POST /front + GET /config) that carried
|
|
// the home banner slider, the category grid, promotions, the ignore-list and
|
|
// the gold price ticker. The new API exposes none of that as a single config
|
|
// endpoint, so this store restores the two pieces that drive visible home-page
|
|
// UI and are actually derivable today:
|
|
//
|
|
// - `cats` — REAL data: distinct categories derived from GET /catalog/products
|
|
// (the response already includes each product's category).
|
|
// Legacy's per-category `icon.image` was a remote URL from the old
|
|
// Laravel host and has no equivalent, so a local brand mark stands
|
|
// in until category artwork exists.
|
|
// - `config.main_slider` — legacy's banner slides were remote URLs too. These
|
|
// are placeholder slides built from legacy's own local artwork,
|
|
// using legacy's exact slide shape ({text, type, src, link}) so
|
|
// HomeSlider's popup/link/discount click handling works unchanged.
|
|
//
|
|
// Not ported (no backend): promotionList, ignoreList, priceList, isLoaded.
|
|
//
|
|
// `isLoaded` — «عمداً تکرار نشد — D3/ب» (owner, 2026-10-12). Legacy used it as a
|
|
// router guard against a bootstrap request this app does not have; see the same
|
|
// note in user-app's configStore for the full reasoning (D4).
|
|
import { defineStore } from 'pinia'
|
|
import { api } from '../api/client'
|
|
import shippingArt from '../assets/img/shipping-and-delivery.png'
|
|
import competitionArt from '../assets/img/sports-and-competition.png'
|
|
import brandArt from '../assets/img/brand-logo.svg'
|
|
import { brand } from '../brand'
|
|
|
|
export interface Slide {
|
|
text: string | undefined
|
|
type: string | undefined
|
|
src: string | undefined
|
|
link: string | undefined
|
|
}
|
|
|
|
export interface HomeCategory {
|
|
id: string
|
|
title: string
|
|
icon?: { image: string }
|
|
}
|
|
|
|
const PLACEHOLDER_SLIDES: Slide[] = [
|
|
{
|
|
type: 'popup',
|
|
src: shippingArt,
|
|
text: 'ارسال سریع و مطمئن سفارشهای شما به سراسر کشور.',
|
|
link: undefined,
|
|
},
|
|
{
|
|
type: 'popup',
|
|
src: competitionArt,
|
|
text: `جدیدترین محصولات ${brand.name} را در بخش محصولات جدید ببینید.`,
|
|
link: undefined,
|
|
},
|
|
{
|
|
type: 'popup',
|
|
src: brandArt,
|
|
text: `${brand.name}، همراه شما در خرید و فروش طلا.`,
|
|
link: undefined,
|
|
},
|
|
]
|
|
|
|
export const useConfigStore = defineStore('config', {
|
|
state: () => ({
|
|
config: { main_slider: PLACEHOLDER_SLIDES as Slide[] },
|
|
cats: [] as HomeCategory[],
|
|
loaded: false,
|
|
}),
|
|
actions: {
|
|
setCats(cats: HomeCategory[]) {
|
|
this.cats = cats
|
|
},
|
|
// Legacy's store.init() fanned out to /config, /promotion, /ignore, /price.
|
|
// Here the live source is the catalogue's own category list.
|
|
//
|
|
// Reads GET /catalog/products/facets, a small aggregate. It used to load the
|
|
// whole catalogue and derive the categories from it in the browser — up to
|
|
// ~16k products fetched to populate one row of chips, and wrong beyond the
|
|
// first page once the list is paged, because a category whose products all
|
|
// sit further down would vanish from the home screen.
|
|
async init(force = false) {
|
|
void force // the facets are a small read; there is no cached copy to bypass
|
|
try {
|
|
const { categories } = await api.getCatalogFacets()
|
|
this.cats = categories.map((c) => ({ ...c, icon: { image: brandArt } }))
|
|
this.loaded = true
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
},
|
|
},
|
|
})
|