pc setup: hero falls back to the case present on the chosen day; add-ons (tilt pivot) are not counted as extra units in a slot card
All checks were successful
Deploy production / deploy (push) Successful in 1m6s
All checks were successful
Deploy production / deploy (push) Successful in 1m6s
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
slotIcon,
|
slotIcon,
|
||||||
slotLabel,
|
slotLabel,
|
||||||
thumb,
|
thumb,
|
||||||
|
isAddOn,
|
||||||
units,
|
units,
|
||||||
usageBadges,
|
usageBadges,
|
||||||
type Part
|
type Part
|
||||||
@@ -34,7 +35,7 @@
|
|||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
const first = $derived(parts[0]);
|
const first = $derived(parts[0]);
|
||||||
const qty = $derived(parts.reduce((s, p) => s + units(p), 0));
|
const qty = $derived(parts.reduce((s, p) => s + (isAddOn(p) ? 0 : units(p)), 0));
|
||||||
const image = $derived(parts.flatMap((p) => p.imageUrls)[0] ?? null);
|
const image = $derived(parts.flatMap((p) => p.imageUrls)[0] ?? null);
|
||||||
const names = $derived([...new Set(parts.map(displayName))]);
|
const names = $derived([...new Set(parts.map(displayName))]);
|
||||||
const spec = $derived(keySpec(first));
|
const spec = $derived(keySpec(first));
|
||||||
|
|||||||
@@ -201,6 +201,9 @@ export const presentAt = (
|
|||||||
export type SlotCard = { key: string; slot: string; parts: Part[] };
|
export type SlotCard = { key: string; slot: string; parts: Part[] };
|
||||||
|
|
||||||
/** Visible parts of one section on day `at`, one card per slot (several parts may share it). */
|
/** Visible parts of one section on day `at`, one card per slot (several parts may share it). */
|
||||||
|
/** An add-on (e.g. a tilt pivot) extends another part in the same slot card; it is not counted as an extra unit. */
|
||||||
|
export const isAddOn = (p: { model: string }) => /\badd-on\b/i.test(p.model);
|
||||||
|
|
||||||
export function slotCards(parts: Part[], section: string, at: string): SlotCard[] {
|
export function slotCards(parts: Part[], section: string, at: string): SlotCard[] {
|
||||||
const cards = new Map<string, SlotCard>();
|
const cards = new Map<string, SlotCard>();
|
||||||
for (const p of parts) {
|
for (const p of parts) {
|
||||||
@@ -216,8 +219,7 @@ export function slotCards(parts: Part[], section: string, at: string): SlotCard[
|
|||||||
return i < 0 ? 999 : i;
|
return i < 0 ? 999 : i;
|
||||||
};
|
};
|
||||||
// Add-ons (e.g. a monitor-arm tilt pivot) sit after the item they extend.
|
// Add-ons (e.g. a monitor-arm tilt pivot) sit after the item they extend.
|
||||||
const addOn = (p: Part) => /\badd-on\b/i.test(p.model);
|
for (const c of cards.values()) c.parts.sort((a, b) => Number(isAddOn(a)) - Number(isAddOn(b)));
|
||||||
for (const c of cards.values()) c.parts.sort((a, b) => Number(addOn(a)) - Number(addOn(b)));
|
|
||||||
return [...cards.values()].sort((a, b) => rank(a.slot) - rank(b.slot));
|
return [...cards.values()].sort((a, b) => rank(a.slot) - rank(b.slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,9 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
// ---- photos ----
|
// ---- photos ----
|
||||||
const casePart = $derived(parts.find((p) => p.slot === 'case' && p.imageUrls.length));
|
const casePart = $derived(
|
||||||
|
parts.find((p) => p.slot === 'case' && p.imageUrls.length && presentAt(p, at))
|
||||||
|
);
|
||||||
const heroImage = $derived(data.photos[0]?.url ?? casePart?.imageUrls[0] ?? null);
|
const heroImage = $derived(data.photos[0]?.url ?? casePart?.imageUrls[0] ?? null);
|
||||||
const photoItem = $derived<LightboxItem>({
|
const photoItem = $derived<LightboxItem>({
|
||||||
title: 'My setup',
|
title: 'My setup',
|
||||||
|
|||||||
Reference in New Issue
Block a user