fix(ui): cap khanegi bottom nav at 4 slots with drag reorder
Merge all versions onto the shared nav sample so extra items cannot stay enabled. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -91,6 +91,7 @@ export function createDefaultKhanegiUiConfig() {
|
||||
{ id: 'user', label: 'تنظیمات', icon: 'vuesax-linear:setting-2', route: 'user', order: 8, visible: true },
|
||||
],
|
||||
bottom: [
|
||||
// ۴ جایگاه ثابت نوار پایین — با get-user/khanegi-nav-sample.ts یکی بماند
|
||||
{ id: 'gold', label: 'خرید و فروش', icon: 'vuesax-linear:coin', route: 'gold', order: 1, visible: true },
|
||||
{ id: 'transactions', label: 'تراکنشها', icon: 'vuesax-linear:receipt-item', route: 'transactions', order: 2, visible: true },
|
||||
{ id: 'wallet', label: 'کیف پول', icon: 'vuesax-linear:wallet-add', route: 'wallet', order: 3, visible: true },
|
||||
@@ -118,6 +119,88 @@ export function createDefaultKhanegiUiConfig() {
|
||||
|
||||
export type UiConfigBase = ReturnType<typeof createDefaultKhanegiUiConfig>
|
||||
|
||||
/** نوار پایین موبایل فقط ۴ جایگاه دارد (خانه جدا در FAB وسط است) */
|
||||
export const MAX_BOTTOM_NAV_SLOTS = 4
|
||||
|
||||
export type KhanegiNavItem = UiConfigBase['app']['navigation']['sidebar'][number]
|
||||
|
||||
function cloneJson<T>(value: T): T {
|
||||
return JSON.parse(JSON.stringify(value)) as T
|
||||
}
|
||||
|
||||
export function getKhanegiNavSample() {
|
||||
const { navigation } = createDefaultKhanegiUiConfig().app
|
||||
return {
|
||||
sidebar: cloneJson(navigation.sidebar),
|
||||
bottom: cloneJson(navigation.bottom),
|
||||
sidebarReferral: cloneJson(navigation.sidebarReferral),
|
||||
}
|
||||
}
|
||||
|
||||
/** آیتمهای سمپل را نگه میدارد؛ لیبل/وضعیت نسخهها روی همان id overlay میشود */
|
||||
export function mergeNavItemsFromSample(
|
||||
sample: KhanegiNavItem[],
|
||||
stored: KhanegiNavItem[] | undefined,
|
||||
maxVisible?: number,
|
||||
): KhanegiNavItem[] {
|
||||
const sampleById = new Map(sample.map((item) => [item.id, item]))
|
||||
const storedList = Array.isArray(stored) ? stored : []
|
||||
const kept: KhanegiNavItem[] = []
|
||||
const seen = new Set<string>()
|
||||
|
||||
for (const prev of storedList) {
|
||||
const base = sampleById.get(prev.id)
|
||||
if (!base || seen.has(prev.id)) continue
|
||||
seen.add(prev.id)
|
||||
kept.push({
|
||||
...base,
|
||||
label: prev.label || base.label,
|
||||
icon: prev.icon || base.icon,
|
||||
visible: typeof prev.visible === 'boolean' ? prev.visible : base.visible,
|
||||
query: prev.query ?? base.query,
|
||||
})
|
||||
}
|
||||
|
||||
for (const item of sample) {
|
||||
if (seen.has(item.id)) continue
|
||||
kept.push({ ...item })
|
||||
}
|
||||
|
||||
if (typeof maxVisible === 'number') {
|
||||
let visibleCount = 0
|
||||
for (const item of kept) {
|
||||
if (!item.visible) continue
|
||||
visibleCount += 1
|
||||
if (visibleCount > maxVisible) item.visible = false
|
||||
}
|
||||
}
|
||||
|
||||
return kept.map((item, index) => ({ ...item, order: index + 1 }))
|
||||
}
|
||||
|
||||
export function applyKhanegiNavSample(app: { navigation?: any } | null | undefined) {
|
||||
if (!app || typeof app !== 'object') return
|
||||
const sample = getKhanegiNavSample()
|
||||
if (!app.navigation || typeof app.navigation !== 'object') {
|
||||
app.navigation = {
|
||||
type: 'both',
|
||||
sidebar: sample.sidebar,
|
||||
bottom: sample.bottom,
|
||||
sidebarReferral: sample.sidebarReferral,
|
||||
}
|
||||
return
|
||||
}
|
||||
app.navigation.sidebar = mergeNavItemsFromSample(sample.sidebar, app.navigation.sidebar)
|
||||
app.navigation.bottom = mergeNavItemsFromSample(
|
||||
sample.bottom.slice(0, MAX_BOTTOM_NAV_SLOTS),
|
||||
app.navigation.bottom,
|
||||
MAX_BOTTOM_NAV_SLOTS,
|
||||
).slice(0, MAX_BOTTOM_NAV_SLOTS)
|
||||
if (!app.navigation.sidebarReferral || typeof app.navigation.sidebarReferral !== 'object') {
|
||||
app.navigation.sidebarReferral = sample.sidebarReferral
|
||||
}
|
||||
}
|
||||
|
||||
export type UiConfig = UiConfigBase & {
|
||||
/** Immutable factory look — set once; never overwrite on normal save */
|
||||
defaultSnapshot?: {
|
||||
@@ -173,6 +256,9 @@ export function normalizeKhanegiUiConfigForClient<T extends Record<string, any>>
|
||||
if (app.navigation.sidebarReferral?.route === 'products') {
|
||||
app.navigation.sidebarReferral.route = 'buyProduct'
|
||||
}
|
||||
applyKhanegiNavSample(app)
|
||||
} else {
|
||||
applyKhanegiNavSample(app)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user