@wix/himalaya-cli 0.1855.0 → 0.1857.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/auth/src/copy.generated.d.ts +20 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/auth/src/feedback.d.ts +9 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/auth/src/index.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/screens/src/index.d.ts +21 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/auth.mjs +53 -16
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +94 -29
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{fb500748f6c4768468f2e7f985aa67c38633077c7a98caaa6b500c7b00eea8e9.bin → 7c8b32af7572e93ce52c2bc81b8d0bf5525f6e66531f934dac68d4507a6e3026.bin} +1 -1
- package/dist/browser-plane/sw.js +10 -10
- package/dist/cli.mjs +648 -317
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/himi-json-output.md +2 -2
- package/guides/one-app-section-mappings.md +2 -2
- package/guides/one-app-to-himi-app.md +3 -3
- package/guides/recipe-auth.md +18 -1
- package/guides/sdk-reference.json +4 -4
- package/package.json +2 -2
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +5 -2
- package/templates/beauty-salon/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/branded-lite/l10n/ar.json +15 -10
- package/templates/branded-lite/l10n/cs.json +15 -10
- package/templates/branded-lite/l10n/da.json +15 -10
- package/templates/branded-lite/l10n/de.json +15 -10
- package/templates/branded-lite/l10n/el.json +15 -10
- package/templates/branded-lite/l10n/es.json +15 -10
- package/templates/branded-lite/l10n/fi.json +15 -10
- package/templates/branded-lite/l10n/fr.json +15 -10
- package/templates/branded-lite/l10n/he.json +12 -8
- package/templates/branded-lite/l10n/hu.json +15 -10
- package/templates/branded-lite/l10n/id.json +15 -10
- package/templates/branded-lite/l10n/it.json +15 -10
- package/templates/branded-lite/l10n/ja.json +15 -10
- package/templates/branded-lite/l10n/ko.json +15 -10
- package/templates/branded-lite/l10n/lt.json +15 -10
- package/templates/branded-lite/l10n/nl.json +15 -10
- package/templates/branded-lite/l10n/no.json +15 -10
- package/templates/branded-lite/l10n/pl.json +15 -10
- package/templates/branded-lite/l10n/pt.json +15 -10
- package/templates/branded-lite/l10n/ru.json +15 -10
- package/templates/branded-lite/l10n/sv.json +15 -10
- package/templates/branded-lite/l10n/th.json +15 -10
- package/templates/branded-lite/l10n/tr.json +15 -10
- package/templates/branded-lite/l10n/uk.json +15 -10
- package/templates/branded-lite/l10n/vi.json +15 -10
- package/templates/branded-lite/l10n/zh.json +15 -10
- package/templates/branded-lite/recipes/performance-tracker.json +464 -75
- package/templates/branded-lite/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/branded-lite/tier5-src/_shared/performance-tracker-goal.ts +57 -0
- package/templates/branded-lite/tier5-src/_shared/performance-tracker-section.ts +124 -49
- package/templates/branded-lite/tier5-src/_shared/performance-tracker-weeks.ts +2 -2
- package/templates/branded-lite/tier5-src/_shared/programs-section.ts +46 -15
- package/templates/community-club/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/events-meetups/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/fitness-gym/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/gym-fitness/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/nonprofit-cause/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/podcast-creator/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/portfolio-creative/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/restaurant/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/retail-store/tier5-src/_shared/himi-media.ts +6 -2
- package/templates/yoga-studio/tier5-src/_shared/himi-media.ts +6 -2
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The member's own weekly session goal on a performance tracker, as pure rules over a key-value store (no @himalaya import, so a test
|
|
2
|
+
// can load this file alone). The source keeps the goal in a private fitness service that signs its calls with the site's instance, a
|
|
3
|
+
// credential a member's session cannot stand in for, so the goal is kept on this device: under the member's own key, never read for
|
|
4
|
+
// another member, and never shown to a visitor.
|
|
5
|
+
import type { MemberAccess } from "./member-access.js";
|
|
6
|
+
|
|
7
|
+
/** The source's picker offers 1 to 14 sessions a week. */
|
|
8
|
+
export const MIN_MEMBER_GOAL = 1;
|
|
9
|
+
export const MAX_MEMBER_GOAL = 14;
|
|
10
|
+
export const GOAL_CHOICES: readonly number[] = Array.from({ length: MAX_MEMBER_GOAL }, (_, i) => MIN_MEMBER_GOAL + i);
|
|
11
|
+
|
|
12
|
+
/** What the picker lists: 1 to 14, plus the goal in force when the site's default is above that (a default of 20 must show as chosen). */
|
|
13
|
+
export function goalChoices(current: number): number[] {
|
|
14
|
+
return GOAL_CHOICES.includes(current) ? [...GOAL_CHOICES] : [...GOAL_CHOICES, current];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GoalStore { getItem(key: string): string | null; setItem(key: string, value: string): void }
|
|
18
|
+
|
|
19
|
+
const KEY = "himi-performance-tracker:weekly-goal:v1";
|
|
20
|
+
|
|
21
|
+
/** A goal the picker offers (a whole number in [1, 14], or its text), else 0. */
|
|
22
|
+
export function pickableGoal(raw: unknown): number {
|
|
23
|
+
const n = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
24
|
+
return Number.isInteger(n) && n >= MIN_MEMBER_GOAL && n <= MAX_MEMBER_GOAL ? n : 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Whose goal this is: the member's partition (account + business + email), else their email on a host that has no partition. "" = nobody. */
|
|
28
|
+
export function goalOwner(member: Pick<MemberAccess, "email" | "scope"> | undefined): string {
|
|
29
|
+
return member?.email ? member.scope || member.email : "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const keyOf = (owner: string): string => `${KEY}.${encodeURIComponent(owner)}`;
|
|
33
|
+
|
|
34
|
+
/** The goal this member set, or 0 when they have not (or the store cannot be read). */
|
|
35
|
+
export function readMemberGoal(store: GoalStore | undefined, owner: string): number {
|
|
36
|
+
if (!store || !owner) return 0;
|
|
37
|
+
try { return pickableGoal(store.getItem(keyOf(owner))); } catch { return 0; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Whether this device can keep a goal for this member: a probe key is written and read back. A member is offered the picker only when it can. */
|
|
41
|
+
export function canKeepGoal(store: GoalStore | undefined, owner: string): boolean {
|
|
42
|
+
if (!store || !owner) return false;
|
|
43
|
+
try {
|
|
44
|
+
const key = `${keyOf(owner)}:probe`;
|
|
45
|
+
store.setItem(key, "1");
|
|
46
|
+
return store.getItem(key) === "1";
|
|
47
|
+
} catch { return false; }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Keep `goal` for this member. True only when it reads back: a host may swallow a failed write, and a save must never claim success. */
|
|
51
|
+
export function saveMemberGoal(store: GoalStore | undefined, owner: string, goal: number): boolean {
|
|
52
|
+
if (!store || !owner || !pickableGoal(goal)) return false;
|
|
53
|
+
try {
|
|
54
|
+
store.setItem(keyOf(owner), String(goal));
|
|
55
|
+
return readMemberGoal(store, owner) === goal;
|
|
56
|
+
} catch { return false; }
|
|
57
|
+
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
// A page's performance-tracker section as a registrable service: the signed-in member's progress against a weekly session goal
|
|
2
|
-
// (this week's range, "N of G sessions this week", a progress ring), their
|
|
2
|
+
// (this week's range, "N of G sessions this week", a progress ring), their weeks of meeting the goal and their sessions in total. The source
|
|
3
3
|
// reads a private fitness service; this reads the same member-scoped bookings as My Bookings (himi_bookings) and counts with the
|
|
4
4
|
// same rule as its "This week" card (`weekly-goal.ts`: a CONFIRMED booking that already took place; Wix attendance is owner-scoped,
|
|
5
5
|
// so a no-show still counts), so a guest or a refused member gets the sign-in state instead of a read.
|
|
6
|
-
// goal -> the weekly goal (the source's `defaultWeeklyGoal
|
|
6
|
+
// goal -> the default weekly goal (the source's `defaultWeeklyGoal`). A member picks their own from 1 to 14 in a sheet with a number wheel, as in
|
|
7
|
+
// the source; it is kept on this device under the member's key (`performance-tracker-goal.ts`), because the source's goal lives in a
|
|
8
|
+
// private service a member's session cannot call. A visitor keeps the default and is asked to sign in to change it,
|
|
7
9
|
// showTotal -> the all-time row (the source's `totalNumberOfSessions.show`).
|
|
8
10
|
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe performance-tracker.json).
|
|
9
11
|
import { defineService } from "@himalaya/state";
|
|
10
12
|
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
11
|
-
import {
|
|
13
|
+
import { copyPlural, stashCopy } from "./himi-copy.js";
|
|
12
14
|
import { formatNumber } from "./engine-intl.js";
|
|
13
15
|
import { fetchMemberBookings } from "./member-bookings.js";
|
|
14
16
|
import { memberAccess, memberAccessDenied, memberChanged } from "./member-access.js";
|
|
15
17
|
import { parseWeeklyGoal, weeklyGoalProgress } from "./weekly-goal.js";
|
|
18
|
+
import { canKeepGoal, goalChoices, goalOwner, pickableGoal, readMemberGoal, saveMemberGoal, type GoalStore } from "./performance-tracker-goal.js";
|
|
16
19
|
import { DEFAULT_WEEKLY_GOAL, MAX_ALL_TIME_SESSIONS, MAX_PAGES, allTimeSessions, sessionsInWeek, streakMayBeLonger, weekRange, weeklyStreak } from "./performance-tracker-weeks.js";
|
|
20
|
+
import type { MemberBookingRow } from "./member-bookings.js";
|
|
17
21
|
|
|
18
22
|
export interface PerformanceTrackerOptions {
|
|
19
23
|
/** The weekly session goal. Not a goal in [1, 21]: the source's default of 2. */
|
|
@@ -22,11 +26,13 @@ export interface PerformanceTrackerOptions {
|
|
|
22
26
|
showTotal?: boolean;
|
|
23
27
|
}
|
|
24
28
|
|
|
29
|
+
export interface GoalOption { id: string; label: string }
|
|
30
|
+
|
|
25
31
|
export interface PerformanceTrackerState {
|
|
26
32
|
status: "loading" | "ready" | "error";
|
|
27
33
|
/** A guest, or a member Wix refused: the section asks to sign in instead of reading. */
|
|
28
34
|
signedOut: boolean;
|
|
29
|
-
/** "Nov 16
|
|
35
|
+
/** "Nov 16 - Nov 22". */
|
|
30
36
|
weekRange: string;
|
|
31
37
|
/** "1 of 2 sessions this week". */
|
|
32
38
|
goalLabel: string;
|
|
@@ -36,8 +42,15 @@ export interface PerformanceTrackerState {
|
|
|
36
42
|
progress: number;
|
|
37
43
|
/** "1/2", inside the ring. */
|
|
38
44
|
ringText: string;
|
|
45
|
+
/** The goal wheel: 1 to 14 (the numbers the wheel shows), the id of the wheel's choice, the id in force, and its label ("2 Sessions"; a visitor reads it as text). */
|
|
46
|
+
goalOptions: GoalOption[]; goalDraft: string; goalValue: string; goalSessions: string;
|
|
47
|
+
/** The goal sheet is open. */
|
|
48
|
+
goalOpen: boolean;
|
|
49
|
+
/** The device cannot keep a goal (or just failed to): the goal row is plain text, with no sheet to open. */
|
|
50
|
+
goalLocked: boolean; goalUnlocked: boolean;
|
|
51
|
+
/** "Weeks of meeting my goal": the count, then its label ("Week of..." for one). */
|
|
39
52
|
streak: string; streakLabel: string;
|
|
40
|
-
/** "500+" past the source's cap. */
|
|
53
|
+
/** "500+" past the source's cap, then "Sessions attended in total". */
|
|
41
54
|
total: string; totalLabel: string;
|
|
42
55
|
notLoading: boolean; notErrored: boolean; notSignedOut: boolean;
|
|
43
56
|
/** Nothing to show yet: loading, failed or signed out. */
|
|
@@ -47,70 +60,132 @@ export interface PerformanceTrackerState {
|
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
export function registerPerformanceTrackerSection(serviceName: string, options: PerformanceTrackerOptions = {}) {
|
|
50
|
-
const
|
|
63
|
+
const defaultGoal = parseWeeklyGoal(options.goal) || DEFAULT_WEEKLY_GOAL;
|
|
51
64
|
const showTotal = options.showTotal !== false;
|
|
52
|
-
const
|
|
65
|
+
const sessionsLabel = (n: number): string => copyPlural("performanceTracker.goalSessions", "{n, plural, one {# Session} other {# Sessions}}", n);
|
|
66
|
+
const weeksLabel = (n: number): string => copyPlural("performanceTracker.weeksMeetingGoal", "{n, plural, one {Week of meeting my goal} other {Weeks of meeting my goal}}", n);
|
|
67
|
+
const attendedLabel = (n: number): string => copyPlural("performanceTracker.sessionsAttended", "{n, plural, one {Session attended in total} other {Sessions attended in total}}", n);
|
|
68
|
+
const blank = {
|
|
69
|
+
goalLabel: "", remainingLabel: "", progress: 0, ringText: "", streak: "", total: "",
|
|
70
|
+
goalOptions: [] as GoalOption[], goalDraft: "", goalValue: "", goalSessions: "", goalOpen: false, goalLocked: false, goalUnlocked: true,
|
|
71
|
+
streakLabel: "", totalLabel: "",
|
|
72
|
+
};
|
|
53
73
|
const view = (status: PerformanceTrackerState["status"], signedOut: boolean, fields: Partial<typeof blank> = {}, now?: number): PerformanceTrackerState => {
|
|
54
74
|
const noContent = !(status === "ready" && !signedOut);
|
|
55
75
|
return {
|
|
56
76
|
// No clock read at registration (a worker boots deterministically): the range is set by the load.
|
|
57
77
|
status, signedOut, weekRange: now === undefined ? "" : weekRange(now), ...blank, ...fields,
|
|
58
|
-
streakLabel: copyParam("performanceTracker.weekStreak", "Week streak"),
|
|
59
|
-
totalLabel: copyParam("performanceTracker.allTimeSessions", "All-time sessions"),
|
|
60
78
|
notLoading: status !== "loading", notErrored: status !== "error", notSignedOut: !signedOut,
|
|
61
79
|
noContent, noTotal: noContent || !showTotal,
|
|
62
80
|
};
|
|
63
81
|
};
|
|
64
82
|
const session = hostSessionFromGlobal();
|
|
83
|
+
const goalStore = (): GoalStore | undefined => {
|
|
84
|
+
const host = globalThis as { himalaya?: { storage?: GoalStore }; localStorage?: GoalStore };
|
|
85
|
+
try { return host.himalaya?.storage ?? host.localStorage; } catch { return undefined; }
|
|
86
|
+
};
|
|
87
|
+
// What the last read found, so choosing a goal repaints this week's numbers without reading the bookings again.
|
|
88
|
+
let found: { rows: MemberBookingRow[]; now: number; unreadRemain: boolean; owner: string; locked: boolean } | undefined;
|
|
89
|
+
const ready = (read: NonNullable<typeof found>, goal: number): PerformanceTrackerState => {
|
|
90
|
+
const { rows, now, unreadRemain } = read;
|
|
91
|
+
const progress = weeklyGoalProgress(sessionsInWeek(rows, now, 0), goal);
|
|
92
|
+
const total = allTimeSessions(rows, now);
|
|
93
|
+
const streak = weeklyStreak(rows, now, goal);
|
|
94
|
+
return view("ready", false, {
|
|
95
|
+
goalLabel: progress.label, remainingLabel: progress.remainingLabel, progress: progress.fraction,
|
|
96
|
+
ringText: `${formatNumber(progress.done)}/${formatNumber(progress.goal)}`,
|
|
97
|
+
goalOptions: goalChoices(progress.goal).map((n) => ({ id: String(n), label: formatNumber(n) })),
|
|
98
|
+
goalDraft: String(progress.goal), goalValue: String(progress.goal), goalSessions: sessionsLabel(progress.goal),
|
|
99
|
+
goalLocked: read.locked, goalUnlocked: !read.locked,
|
|
100
|
+
streak: `${formatNumber(streak)}${streakMayBeLonger(rows, now, goal, streak, unreadRemain) ? "+" : ""}`, streakLabel: weeksLabel(streak),
|
|
101
|
+
total: total > MAX_ALL_TIME_SESSIONS ? `${formatNumber(MAX_ALL_TIME_SESSIONS)}+` : `${formatNumber(total)}${unreadRemain ? "+" : ""}`,
|
|
102
|
+
totalLabel: attendedLabel(Math.min(total, MAX_ALL_TIME_SESSIONS)),
|
|
103
|
+
}, now);
|
|
104
|
+
};
|
|
105
|
+
// A guest, or a member Wix refused, keeps the default goal and is asked to sign in to change it.
|
|
106
|
+
const signedOut = () => view("ready", true, { goalSessions: sessionsLabel(defaultGoal) });
|
|
65
107
|
// Only the newest load may answer: a guest read that finishes after the member signed in must not overwrite the member's progress.
|
|
66
108
|
let sequence = 0;
|
|
67
109
|
const initial = view("loading", false);
|
|
68
110
|
// The member changed: the progress already published is the previous member's, so it goes at once.
|
|
69
111
|
const restart = () => { void service.clear(); void service.load(); };
|
|
70
|
-
|
|
112
|
+
type State = PerformanceTrackerState;
|
|
113
|
+
const load = async (_state: State, arg?: unknown): Promise<State | undefined> => {
|
|
114
|
+
stashCopy(arg);
|
|
115
|
+
const seq = ++sequence;
|
|
116
|
+
let member: Awaited<ReturnType<typeof memberAccess>> | undefined;
|
|
117
|
+
try {
|
|
118
|
+
member = await memberAccess();
|
|
119
|
+
if (seq !== sequence) return undefined;
|
|
120
|
+
if (!member.email) return signedOut();
|
|
121
|
+
const now = Date.now();
|
|
122
|
+
const nowIso = new Date(now).toISOString();
|
|
123
|
+
const read = (cursor: string) => fetchMemberBookings({ query: "", filter: "value:Past", sort: "za", savedIds: [] }, cursor, nowIso, member);
|
|
124
|
+
let page = await read("");
|
|
125
|
+
const rows = [...page.items];
|
|
126
|
+
for (let pages = 1; pages < MAX_PAGES && page.nextCursor; pages++) { page = await read(page.nextCursor); rows.push(...page.items); }
|
|
127
|
+
// Older bookings the page cap left unread: the streak and the all-time total are then "at least", never a silent shortfall.
|
|
128
|
+
const unreadRemain = Boolean(page.nextCursor);
|
|
129
|
+
if (seq !== sequence) return undefined;
|
|
130
|
+
const owner = goalOwner(member);
|
|
131
|
+
found = { rows, now, unreadRemain, owner, locked: !canKeepGoal(goalStore(), owner) };
|
|
132
|
+
return ready(found, readMemberGoal(goalStore(), owner) || defaultGoal);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (seq !== sequence) return undefined;
|
|
135
|
+
// The member signed out (or changed) while the read was out: read again for whoever is signed in now.
|
|
136
|
+
const changed = await memberChanged(member, error);
|
|
137
|
+
// A newer load may have answered while that check was out: restarting then would blank its card and read the bookings again.
|
|
138
|
+
if (seq !== sequence) return undefined;
|
|
139
|
+
if (changed) { restart(); return undefined; }
|
|
140
|
+
// Wix refusing the member is a sign-in state, as on My Bookings; anything else is a failed read.
|
|
141
|
+
if (memberAccessDenied(error)) return signedOut();
|
|
142
|
+
console.warn("performance_tracker_section: the bookings could not be read", error);
|
|
143
|
+
return view("error", false);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const service = defineService<State, {
|
|
147
|
+
load: (state: State, arg?: unknown) => Promise<State | undefined>;
|
|
148
|
+
refresh: (state: State, arg?: unknown) => Promise<State | undefined>;
|
|
149
|
+
openGoal: (state: State) => State;
|
|
150
|
+
closeGoal: (state: State) => State;
|
|
151
|
+
draftGoal: (state: State, arg?: unknown) => State;
|
|
152
|
+
chooseGoal: (state: State) => Promise<State>;
|
|
153
|
+
clear: () => Promise<State>;
|
|
154
|
+
}>(serviceName, {
|
|
71
155
|
state: initial,
|
|
72
156
|
// The progress is one member's: never written to disk and restored for the next person on the device.
|
|
73
|
-
notHydrated: Object.keys(initial) as Array<keyof
|
|
157
|
+
notHydrated: Object.keys(initial) as Array<keyof State>,
|
|
74
158
|
actions: {
|
|
75
|
-
clear: async () => initial,
|
|
76
|
-
load
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (seq !== sequence) return undefined;
|
|
104
|
-
// The member signed out (or changed) while the read was out: read again for whoever is signed in now.
|
|
105
|
-
const changed = await memberChanged(member, error);
|
|
106
|
-
// A newer load may have answered while that check was out: restarting then would blank its card and read the bookings again.
|
|
107
|
-
if (seq !== sequence) return undefined;
|
|
108
|
-
if (changed) { restart(); return undefined; }
|
|
109
|
-
// Wix refusing the member is a sign-in state, as on My Bookings; anything else is a failed read.
|
|
110
|
-
if (memberAccessDenied(error)) return view("ready", true);
|
|
111
|
-
console.warn("performance_tracker_section: the bookings could not be read", error);
|
|
112
|
-
return view("error", false);
|
|
159
|
+
clear: async () => { found = undefined; return initial; },
|
|
160
|
+
load,
|
|
161
|
+
// The "..." menu's Refresh: the same read, for the member who is here now.
|
|
162
|
+
refresh: load,
|
|
163
|
+
// The goal row opens the sheet on the goal in force.
|
|
164
|
+
openGoal: (state) => (state.status === "ready" && !state.signedOut && !state.goalLocked ? { ...state, goalOpen: true, goalDraft: state.goalValue } : state),
|
|
165
|
+
closeGoal: (state) => (state.goalOpen ? { ...state, goalOpen: false } : state),
|
|
166
|
+
// The wheel turned: only a goal the wheel offers is taken.
|
|
167
|
+
draftGoal: (state, arg) => {
|
|
168
|
+
const pick = pickableGoal((arg as { selectedId?: unknown } | undefined)?.selectedId);
|
|
169
|
+
return pick && state.goalOpen ? { ...state, goalDraft: String(pick) } : state;
|
|
170
|
+
},
|
|
171
|
+
// "Select": keep the wheel's choice for this member, then repaint and close. A choice that cannot be kept leaves the goal as it was.
|
|
172
|
+
chooseGoal: async (state) => {
|
|
173
|
+
const choice = pickableGoal(state.goalDraft);
|
|
174
|
+
const read = found;
|
|
175
|
+
if (!choice || !read || read.locked || state.status !== "ready" || state.signedOut) return { ...state, goalOpen: false };
|
|
176
|
+
if (String(choice) === state.goalValue) return { ...state, goalOpen: false };
|
|
177
|
+
const seq = sequence;
|
|
178
|
+
let owner = "";
|
|
179
|
+
try { owner = goalOwner(await memberAccess()); } catch { return { ...state, goalOpen: false }; }
|
|
180
|
+
// The member changed, or a newer load took over, while the identity was read: the choice was not this member's to keep.
|
|
181
|
+
if (seq !== sequence || owner !== read.owner) return { ...state, goalOpen: false };
|
|
182
|
+
if (!saveMemberGoal(goalStore(), owner, choice)) {
|
|
183
|
+
// The goal row turns into plain text: nothing is offered that cannot be kept, and the goal in force is the one shown.
|
|
184
|
+
console.warn("performance_tracker_section: the weekly goal could not be kept on this device");
|
|
185
|
+
read.locked = true;
|
|
186
|
+
return ready(read, readMemberGoal(goalStore(), owner) || defaultGoal);
|
|
113
187
|
}
|
|
188
|
+
return ready(read, choice);
|
|
114
189
|
},
|
|
115
190
|
},
|
|
116
191
|
});
|
|
@@ -62,10 +62,10 @@ export function allTimeSessions(rows: readonly MemberBookingRow[], now: number):
|
|
|
62
62
|
return new Set(rows.filter((row) => isHeldSession(row, now)).map((row) => row.id || `${row.start}|${row.title}`)).size;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/** "Nov 16
|
|
65
|
+
/** "Nov 16 - Nov 22" (the source's `{startDate} - {endDate}`): Monday to Sunday of the week `now` is in. */
|
|
66
66
|
export function weekRange(now: number): string {
|
|
67
67
|
const start = new Date(weekStartMs(now));
|
|
68
68
|
const end = new Date(start);
|
|
69
69
|
end.setDate(end.getDate() + 6);
|
|
70
|
-
return `${formatMonthDay(start)}
|
|
70
|
+
return `${formatMonthDay(start)} - ${formatMonthDay(end)}`;
|
|
71
71
|
}
|
|
@@ -456,8 +456,10 @@ export interface ProgramsSectionOptions {
|
|
|
456
456
|
showDuration?: boolean;
|
|
457
457
|
showParticipants?: boolean;
|
|
458
458
|
showPrice?: boolean;
|
|
459
|
-
/** Program ids promoted to the front, in this order (source `sortingSettings.ordering === "MANUAL"`). */
|
|
459
|
+
/** Program ids promoted to the front, in this order (source `sortingSettings.ordering === "MANUAL"`). Within the section's categories, when it has any. */
|
|
460
460
|
order?: string[];
|
|
461
|
+
/** The categories the source section is scoped to (`categorySettings`): only their programs are listed, and the category filter offers only them. Absent: every program. */
|
|
462
|
+
categoryIds?: string[];
|
|
461
463
|
/** carousel: the member's own participations only (the One App participant carousel). Signed out, empty or failed reads show nothing. */
|
|
462
464
|
participating?: boolean;
|
|
463
465
|
/** list: hide a filter the source section turns off. */
|
|
@@ -467,6 +469,22 @@ export interface ProgramsSectionOptions {
|
|
|
467
469
|
inlineLimit?: number;
|
|
468
470
|
}
|
|
469
471
|
|
|
472
|
+
/** A page cursor of this section: the API's own cursor plus the programs the manual order promoted to the first page. The promoted set belongs to
|
|
473
|
+
* the read that produced the cursor, so it travels with it (never in state shared by overlapping reads of the same criteria). The encoding carries
|
|
474
|
+
* its own prefix: an opaque API cursor is never taken for it, whatever its shape. */
|
|
475
|
+
const CURSOR_TAG = "himi-programs-cursor:";
|
|
476
|
+
function wrapCursor(apiCursor: string, promoted: ReadonlySet<string>): string {
|
|
477
|
+
return apiCursor && promoted.size ? CURSOR_TAG + JSON.stringify({ c: apiCursor, p: [...promoted] }) : apiCursor;
|
|
478
|
+
}
|
|
479
|
+
function unwrapCursor(cursor: string): { api: string; promoted: string[] } {
|
|
480
|
+
if (!cursor.startsWith(CURSOR_TAG)) return { api: cursor, promoted: [] };
|
|
481
|
+
try {
|
|
482
|
+
const wrapped = JSON.parse(cursor.slice(CURSOR_TAG.length)) as { c?: unknown; p?: unknown };
|
|
483
|
+
if (typeof wrapped.c === "string") return { api: wrapped.c, promoted: Array.isArray(wrapped.p) ? wrapped.p.filter((id): id is string => typeof id === "string") : [] };
|
|
484
|
+
} catch { /* not ours after all */ }
|
|
485
|
+
return { api: cursor, promoted: [] };
|
|
486
|
+
}
|
|
487
|
+
|
|
470
488
|
const CAROUSEL_LIMIT = 5;
|
|
471
489
|
const ORDER_LIMIT = 100;
|
|
472
490
|
|
|
@@ -480,12 +498,14 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
|
|
|
480
498
|
const inlineLimit = !carousel && options.inlineLimit !== undefined && options.inlineLimit > 0 ? Math.min(PAGE_SIZE, Math.floor(options.inlineLimit)) : 0;
|
|
481
499
|
// A promoted program is read by id, so it would bypass the member's participations: the participant carousel has no manual order.
|
|
482
500
|
const order = (options.participating ? [] : options.order ?? []).filter((id) => typeof id === "string" && id).slice(0, ORDER_LIMIT);
|
|
483
|
-
/** The
|
|
484
|
-
|
|
485
|
-
|
|
501
|
+
/** The section's own categories: its programs are the only ones listed, and the category filter offers only these. */
|
|
502
|
+
const sectionCategories = (options.categoryIds ?? []).filter((id) => typeof id === "string" && id);
|
|
503
|
+
/** The promoted programs, in their configured order, among those the section lists (`scope`: its status, category and, for the joined view, participation filter). A failed read promotes nothing: the default order stands. */
|
|
504
|
+
async function promotedPrograms(scope: Record<string, unknown>, ids: string[]): Promise<WixProgram[]> {
|
|
505
|
+
if (!ids.length) return [];
|
|
486
506
|
try {
|
|
487
|
-
const response = await queryPrograms({ filter: {
|
|
488
|
-
const rank = new Map(
|
|
507
|
+
const response = await queryPrograms({ filter: { ...scope, id: { $in: ids } }, cursorPaging: { limit: ids.length } });
|
|
508
|
+
const rank = new Map(ids.map((id, index) => [id, index]));
|
|
489
509
|
return (response.programs ?? []).filter((p) => rank.has(p.id)).sort((a, b) => (rank.get(a.id) ?? 0) - (rank.get(b.id) ?? 0));
|
|
490
510
|
} catch { return []; }
|
|
491
511
|
}
|
|
@@ -494,7 +514,7 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
|
|
|
494
514
|
async function loadCategories(): Promise<void> {
|
|
495
515
|
try {
|
|
496
516
|
const response = await listProgramCategories();
|
|
497
|
-
categories = (response.categories ?? []).filter((c) => c.id && c.label);
|
|
517
|
+
categories = (response.categories ?? []).filter((c) => c.id && c.label && (!sectionCategories.length || sectionCategories.includes(c.id)));
|
|
498
518
|
categoriesFailed = false;
|
|
499
519
|
// A picked category the site no longer has would keep the query filtered behind a hidden control.
|
|
500
520
|
if (categoryId && !categories.some((c) => c.id === categoryId)) categoryId = "";
|
|
@@ -513,7 +533,6 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
|
|
|
513
533
|
let statusFilter: "all" | "joined" = options.participating ? "joined" : "all";
|
|
514
534
|
let categoryId = "";
|
|
515
535
|
let pageScope: Scope | undefined;
|
|
516
|
-
|
|
517
536
|
async function fetchPage(filter: string, cursor: string): Promise<CollectionPage<ProgramContent>> {
|
|
518
537
|
const scope = await resolveScope();
|
|
519
538
|
if (cursor && (!pageScope || !sameScope(pageScope, scope))) throw memberAccessChanged();
|
|
@@ -525,15 +544,27 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
|
|
|
525
544
|
const category = picked && categories && !categories.some((c) => c.id === picked) ? "" : picked;
|
|
526
545
|
const { map: participations, complete: participationsKnown } = await participationsFor(scope, !cursor, status === "joined");
|
|
527
546
|
const programFilter: Record<string, unknown> = { status: { $in: ["PUBLISHED", "ENDED"] } };
|
|
528
|
-
|
|
547
|
+
// A picked chip is one of the section's own categories (the chips offer no others), so it narrows the section's scope.
|
|
548
|
+
const scopedCategories = category ? [category] : sectionCategories;
|
|
549
|
+
if (scopedCategories.length) programFilter.categoryIds = { $hasSome: scopedCategories };
|
|
529
550
|
if (status === "joined") {
|
|
530
551
|
if (!participations.size) return { items: [], nextCursor: "", metadata };
|
|
531
552
|
programFilter.id = { $in: [...participations.keys()] };
|
|
532
553
|
}
|
|
533
554
|
// A page whose every program is dropped (ended and never joined) would leave the list hidden with
|
|
534
555
|
// nothing on screen to call loadMore, so read on until a page has rows or the catalog ends.
|
|
535
|
-
|
|
536
|
-
|
|
556
|
+
// The API cursor, and the programs the manual order promoted to the first page: the cursor carries them (`wrapCursor`), so the pages after
|
|
557
|
+
// the first skip exactly what the read that produced them promoted, whatever other reads of the same criteria are still in flight.
|
|
558
|
+
const carried = unwrapCursor(cursor);
|
|
559
|
+
let pageCursor = carried.api;
|
|
560
|
+
let promotedFirst: WixProgram[] = [];
|
|
561
|
+
const promotedIds = new Set<string>(carried.promoted);
|
|
562
|
+
// The first page leads with the manual order (a carousel or an inline list shows nothing but that page). The joined view promotes the ordered
|
|
563
|
+
// programs the member joined: the participant query already holds only those.
|
|
564
|
+
if (!cursor) {
|
|
565
|
+
promotedFirst = await promotedPrograms(programFilter, status === "joined" ? order.filter((id) => participations.has(id)) : order);
|
|
566
|
+
for (const p of promotedFirst) promotedIds.add(p.id);
|
|
567
|
+
}
|
|
537
568
|
for (let read = 0; ; read++) {
|
|
538
569
|
// A cursor page carries only the cursor — it already encodes the filter and sort — as the
|
|
539
570
|
// participants query of the same service does.
|
|
@@ -542,8 +573,7 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
|
|
|
542
573
|
: { filter: programFilter, sort: [{ fieldName: "createdDate", order: "DESC" }], cursorPaging: { limit: PAGE_SIZE } });
|
|
543
574
|
const after = await resolveScope();
|
|
544
575
|
if (!sameScope(scope, after)) throw memberAccessChanged();
|
|
545
|
-
const
|
|
546
|
-
const visible = [...promoted, ...(response.programs ?? []).filter((p) => !promotedIds.has(p.id))].filter((p) => p.id && !isDraft(p))
|
|
576
|
+
const visible = [...promotedFirst, ...(response.programs ?? []).filter((p) => !promotedIds.has(p.id))].filter((p) => p.id && !isDraft(p))
|
|
547
577
|
// An ended program the member never joined is not theirs to see (the One App's visibility rule) —
|
|
548
578
|
// applied only when the member's participations are known, so a degraded read hides nothing they joined.
|
|
549
579
|
.filter((p) => !isEnded(p) || participations.has(p.id) || !participationsKnown);
|
|
@@ -569,7 +599,7 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
|
|
|
569
599
|
// A revalidating load publishes nothing until it settles, so page 1 records the scope its later pages
|
|
570
600
|
// are read under here, not only from the published snapshot.
|
|
571
601
|
if (!cursor) pageScope = scope;
|
|
572
|
-
return { items, nextCursor, metadata };
|
|
602
|
+
return { items, nextCursor: wrapCursor(nextCursor, promotedIds), metadata };
|
|
573
603
|
}
|
|
574
604
|
}
|
|
575
605
|
/** How many all-dropped pages one fetch reads, in all, before it ends the list. */
|
|
@@ -647,7 +677,8 @@ export function registerProgramsSection(serviceName: string, options: ProgramsSe
|
|
|
647
677
|
// filter switch or a refresh reloads, so the control never flickers away under the finger.
|
|
648
678
|
hideStatusFilter: options.filters?.status === false || (!member && statusFilter !== "joined"),
|
|
649
679
|
categoryId, categoryChips,
|
|
650
|
-
|
|
680
|
+
// One category chosen in the section is the whole list: choosing among one is not a filter.
|
|
681
|
+
hideCategoryFilter: options.filters?.category === false || categoriesFailed || !categories || categories.length === 0 || sectionCategories.length === 1,
|
|
651
682
|
// See all only for an inline (limited) list that has programs past the cards it shows.
|
|
652
683
|
noSeeAll: !(inlineLimit && status === "ready" && meta.more === true),
|
|
653
684
|
hidePriceRetry: status !== "ready" || !views.some((view) => view && view.route !== "disabled" && (scopeIncomplete || view.retryable)),
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|
|
@@ -24,6 +24,10 @@ export function programImage(program: WixProgram, size: WixImageSize = WIX_LIST_
|
|
|
24
24
|
const cover = (program as { coverImage?: unknown }).coverImage;
|
|
25
25
|
const coverUrl = typeof cover === "string" ? cover : (cover as { url?: unknown } | undefined)?.url;
|
|
26
26
|
const description = (program as { description?: unknown }).description;
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const block = description && typeof description === "object" ? description as { image?: { url?: unknown; id?: unknown }; video?: { posters?: Array<{ url?: unknown }> } } : undefined;
|
|
28
|
+
const nested = block?.image;
|
|
29
|
+
// A program whose description has a video and no image is covered by the video's poster (the source's cover); `seo.imageUrl` is that same cover as the site publishes it.
|
|
30
|
+
const poster = block?.video?.posters?.find((candidate) => typeof candidate?.url === "string" && candidate.url)?.url;
|
|
31
|
+
const published = (program as { seo?: { imageUrl?: unknown } }).seo?.imageUrl;
|
|
32
|
+
return firstImage([coverUrl, program.image, nested?.url, nested?.id, poster, published], size);
|
|
29
33
|
}
|