@wix/himalaya-cli 0.1256.0 → 0.1258.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/core/dev-server/src/builder.d.ts +2 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/motion/src/index.d.ts +45 -5
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/sdk-types/src/capabilities.generated.d.ts +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/audio-record.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calendar.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calls.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/contacts.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/location.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/motion.mjs +18 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/photos.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdk-types.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/tasks.mjs +1 -1
- package/dist/cli.mjs +649 -65
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/base44-app-to-himi-app.md +41 -5
- package/guides/component-reference.json +0 -84
- package/guides/component-reference.md +2 -23
- package/guides/sdk-reference.json +15 -3
- package/package.json +2 -2
- package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/beauty-salon/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/beauty-salon/tier5-src/himi-booking-bookings/index.ts +41 -4
- package/templates/beauty-salon/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/branded-lite/config.ts +14 -1
- package/templates/branded-lite/dev/index.ts +845 -2
- package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/branded-lite/tier5-src/himi-booking-bookings/index.ts +41 -4
- package/templates/branded-lite/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/branded-lite/tier5-src/himi-branded-lite-steps/index.ts +524 -0
- package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/community-club/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/community-club/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/events-meetups/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/events-meetups/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/gym-fitness/config.ts +14 -1
- package/templates/gym-fitness/dev/index.ts +844 -1
- package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/gym-fitness/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/gym-fitness/tier5-src/himi-booking-bookings/index.ts +41 -4
- package/templates/gym-fitness/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/gym-fitness/tier5-src/himi-branded-lite-steps/index.ts +524 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/nonprofit-cause/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/nonprofit-cause/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/podcast-creator/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/podcast-creator/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/portfolio-creative/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/restaurant/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/restaurant/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/retail-store/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/yoga-studio/dev/index.ts +90 -1
- package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -0
- package/templates/yoga-studio/tier5-src/_shared/weekly-goal.ts +107 -0
- package/templates/yoga-studio/tier5-src/himi-booking-bookings/index.ts +41 -4
- package/templates/yoga-studio/tier5-src/himi-branded-lite-home/index.ts +31 -7
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -0
|
@@ -14,6 +14,7 @@ import { formatServicePrice } from "../_shared/wix-service-price.js";
|
|
|
14
14
|
import { cleanTitle, initials } from "../_shared/himi-text.js";
|
|
15
15
|
import { accentColor as resolveAccentColor, ACCENT_KEY, LAYOUT_KEY, type LayoutId, recommendLayout, resolveLayout } from "../_shared/himi-layouts.js";
|
|
16
16
|
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
17
|
+
import { parseWeeklyGoal, weeklyGoalProgress, weeklySessionsFromPages } from "../_shared/weekly-goal.js";
|
|
17
18
|
import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
|
|
18
19
|
import { formatDateMedium } from "../_shared/engine-intl.js";
|
|
19
20
|
import { readSavedProducts, type SavedProduct } from "../_shared/himi-store-saved.js";
|
|
@@ -837,7 +838,10 @@ function derive(state: State): State {
|
|
|
837
838
|
// hide them entirely, so every non-bookings layout renders unchanged.
|
|
838
839
|
noTodaysClasses: state.todaysClasses.length === 0,
|
|
839
840
|
noCoachAvatars: state.coachAvatars.length === 0,
|
|
840
|
-
|
|
841
|
+
// The weekly-goal Gauge shows only for a signed-in member of an app that provisions
|
|
842
|
+
// `goals.weeklySessions` — the label is set by refreshPersonal exactly then, and stays "" for
|
|
843
|
+
// a visitor or an app without a goal (so it shows at "0 of 2", but never as fake progress).
|
|
844
|
+
noWeeklyGoal: state.weeklyGoalLabel === "",
|
|
841
845
|
// Collapse gates for the salonLuxe / calmStudio / communityPulse blocks —
|
|
842
846
|
// the same contract: empty data hides the block entirely.
|
|
843
847
|
noServiceShowcase: state.serviceShowcase.length === 0,
|
|
@@ -1070,6 +1074,8 @@ function memberSchedule(rows: MemberBookingRow[], now = new Date()): { label: st
|
|
|
1070
1074
|
async function refreshPersonal(generation: number, arg?: unknown): Promise<void> {
|
|
1071
1075
|
const member = await memberAccess();
|
|
1072
1076
|
let rows: MemberBookingRow[] = [], progress = { label: "", fraction: 0 }, error = false;
|
|
1077
|
+
let weekly: { count: number; fraction: number; label: string } | null = null;
|
|
1078
|
+
const weeklyGoal = parseWeeklyGoal(paramValue(arg, "weeklyGoal"));
|
|
1073
1079
|
if (member.email && parseVerticals(arg).includes("bookings")) {
|
|
1074
1080
|
const now = new Date();
|
|
1075
1081
|
const [upcoming, past] = await Promise.allSettled([
|
|
@@ -1087,10 +1093,24 @@ async function refreshPersonal(generation: number, arg?: unknown): Promise<void>
|
|
|
1087
1093
|
// when either query failed.
|
|
1088
1094
|
progress = memberSchedule([...upcoming.value.items, ...past.value.items], now);
|
|
1089
1095
|
}
|
|
1096
|
+
if (weeklyGoal > 0 && past.status === "fulfilled") {
|
|
1097
|
+
// The goal counts sessions that already HAPPENED this week (_shared/weekly-goal.ts). A
|
|
1098
|
+
// failed past read leaves it hidden rather than claiming "0 of N".
|
|
1099
|
+
// Pages further back only while the first page still sits inside this week; a failing
|
|
1100
|
+
// later page hides the Gauge too.
|
|
1101
|
+
try {
|
|
1102
|
+
const readPast = (cursor: string) =>
|
|
1103
|
+
fetchMemberBookings({ query: "", filter: "value:Past", sort: "za", savedIds: [] }, cursor, now.toISOString(), member);
|
|
1104
|
+
const goal = weeklyGoalProgress(await weeklySessionsFromPages(past.value, readPast, now.getTime()), weeklyGoal);
|
|
1105
|
+
weekly = { count: goal.done, fraction: goal.fraction, label: goal.label };
|
|
1106
|
+
} catch {
|
|
1107
|
+
weekly = null;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1090
1110
|
error = upcoming.status === "rejected" || past.status === "rejected";
|
|
1091
|
-
try { await assertMemberAccess(member); } catch { rows = []; progress = { label: "", fraction: 0 }; error = false; }
|
|
1111
|
+
try { await assertMemberAccess(member); } catch { rows = []; progress = { label: "", fraction: 0 }; error = false; weekly = null; }
|
|
1092
1112
|
}
|
|
1093
|
-
if (generation === personalGeneration) svc.personalLoaded({ generation, rows, progress, error });
|
|
1113
|
+
if (generation === personalGeneration) svc.personalLoaded({ generation, rows, progress, error, weekly });
|
|
1094
1114
|
}
|
|
1095
1115
|
async function refresh(state: State, arg?: unknown): Promise<State | undefined> {
|
|
1096
1116
|
const generation = ++personalGeneration;
|
|
@@ -1102,7 +1122,9 @@ async function refresh(state: State, arg?: unknown): Promise<State | undefined>
|
|
|
1102
1122
|
const current = svc.getState();
|
|
1103
1123
|
return derive({ ...publicState, nextBooking: current.nextBooking, hideNextBooking: current.hideNextBooking,
|
|
1104
1124
|
memberProgressLabel: current.memberProgressLabel, memberProgressFraction: current.memberProgressFraction,
|
|
1105
|
-
hideMemberProgress: current.hideMemberProgress, personalError: current.personalError, hidePersonalError: current.hidePersonalError
|
|
1125
|
+
hideMemberProgress: current.hideMemberProgress, personalError: current.personalError, hidePersonalError: current.hidePersonalError,
|
|
1126
|
+
// The weekly goal is PERSONAL (member bookings); the public refresh resets it, so keep it.
|
|
1127
|
+
weeklyClassCount: current.weeklyClassCount, weeklyClassGoalFraction: current.weeklyClassGoalFraction, weeklyGoalLabel: current.weeklyGoalLabel });
|
|
1106
1128
|
}
|
|
1107
1129
|
|
|
1108
1130
|
const svc = defineService<State, {
|
|
@@ -1113,15 +1135,17 @@ const svc = defineService<State, {
|
|
|
1113
1135
|
refresh: (state: State, arg?: unknown) => Promise<State | undefined>;
|
|
1114
1136
|
dismissOnboarding: (state: State) => State;
|
|
1115
1137
|
clearPersonal: (state: State) => State;
|
|
1116
|
-
personalLoaded: (state: State, arg: { generation: number; rows: MemberBookingRow[]; progress: { label: string; fraction: number }; error: boolean }) => State;
|
|
1138
|
+
personalLoaded: (state: State, arg: { generation: number; rows: MemberBookingRow[]; progress: { label: string; fraction: number }; error: boolean; weekly: { count: number; fraction: number; label: string } | null }) => State;
|
|
1117
1139
|
}>("himiBrandedHome", {
|
|
1118
1140
|
state: baseState(),
|
|
1119
1141
|
actions: {
|
|
1120
|
-
clearPersonal: state => ({ ...state, nextBooking: [], hideNextBooking: true, memberProgressLabel: "", memberProgressFraction: 0, hideMemberProgress: true, personalError: false, hidePersonalError: true
|
|
1142
|
+
clearPersonal: state => derive({ ...state, nextBooking: [], hideNextBooking: true, memberProgressLabel: "", memberProgressFraction: 0, hideMemberProgress: true, personalError: false, hidePersonalError: true,
|
|
1143
|
+
weeklyClassCount: 0, weeklyClassGoalFraction: 0, weeklyGoalLabel: "" }),
|
|
1121
1144
|
personalLoaded: (state, arg) => arg.generation !== personalGeneration ? state : derive({ ...state,
|
|
1122
1145
|
nextBooking: arg.rows, hideNextBooking: !arg.rows.length,
|
|
1123
1146
|
memberProgressLabel: arg.progress.label, memberProgressFraction: arg.progress.fraction, hideMemberProgress: !arg.progress.label,
|
|
1124
|
-
personalError: arg.error, hidePersonalError: !arg.error
|
|
1147
|
+
personalError: arg.error, hidePersonalError: !arg.error,
|
|
1148
|
+
weeklyClassCount: arg.weekly?.count ?? 0, weeklyClassGoalFraction: arg.weekly?.fraction ?? 0, weeklyGoalLabel: arg.weekly?.label ?? "" }),
|
|
1125
1149
|
refresh,
|
|
1126
1150
|
// "Got it" on the first-run card: persist + hide. Persistence is
|
|
1127
1151
|
// best-effort — the UI hides either way for this session.
|
|
@@ -11,6 +11,8 @@ export interface CollectionSaving {
|
|
|
11
11
|
type State = Record<string, unknown>;
|
|
12
12
|
interface BackendCollection {
|
|
13
13
|
restorePagesOnLoad?: boolean;
|
|
14
|
+
/** Sees the load action's argument (the screen's onAppear params) BEFORE the query runs. */
|
|
15
|
+
onLoad?(arg: unknown): void;
|
|
14
16
|
controller: ReturnType<typeof createCollectionQuery<CollectionRow>>;
|
|
15
17
|
apply(state: State, page: CollectionQueryState<CollectionRow>): State;
|
|
16
18
|
}
|
|
@@ -294,6 +296,7 @@ export function decorateCollection(name: string, def: { state: State; actions?:
|
|
|
294
296
|
actions.collectionDataChanged = s => derive(backend.apply(s, backend.controller.getState()));
|
|
295
297
|
actions.load = (_s, arg) => {
|
|
296
298
|
stashCopy(arg); syncSaved(); applyNavigationCriteria(arg, _s);
|
|
299
|
+
backend.onLoad?.(arg);
|
|
297
300
|
return backend.controller.query(criteria(), backend.restorePagesOnLoad).then(() => undefined);
|
|
298
301
|
};
|
|
299
302
|
actions.refresh = (_s, arg) => {
|
|
@@ -320,6 +323,9 @@ export function decorateCollection(name: string, def: { state: State; actions?:
|
|
|
320
323
|
export function defineBackendCollection<S extends object, Row extends object>(name: string, options: {
|
|
321
324
|
/** Revalidate already opened pages on navigation return; explicit refresh resets. */
|
|
322
325
|
restorePagesOnLoad?: boolean;
|
|
326
|
+
/** The load action's argument (onAppear params beyond `copy`), before the query runs — for a
|
|
327
|
+
* domain setting that rides the descriptor, e.g. My Bookings' `weeklyGoal`. */
|
|
328
|
+
onLoad?(arg: unknown): void;
|
|
323
329
|
state: S;
|
|
324
330
|
source: CollectionQuerySource<Row>;
|
|
325
331
|
apply(state: S, page: CollectionQueryState<Row>): S;
|
|
@@ -330,6 +336,7 @@ export function defineBackendCollection<S extends object, Row extends object>(na
|
|
|
330
336
|
const controller = createCollectionQuery(options.source, () => { publish?.(); });
|
|
331
337
|
const definition = decorateCollection(name, { state: options.state as State, actions: options.actions as Record<string, Reducer> | undefined }, options.saving, {
|
|
332
338
|
restorePagesOnLoad: options.restorePagesOnLoad,
|
|
339
|
+
onLoad: options.onLoad,
|
|
333
340
|
controller: controller as unknown as BackendCollection['controller'],
|
|
334
341
|
apply: (state, page) => options.apply(state as S, page as unknown as CollectionQueryState<Row>) as State,
|
|
335
342
|
});
|
|
@@ -2350,6 +2350,7 @@ const SCREENS = runtimeSetting({
|
|
|
2350
2350
|
"verticals": "[\"bookings\",\"programs\",\"plans\",\"events\",\"blog\"]",
|
|
2351
2351
|
"homeModules": "[{\"id\":\"member_progress\",\"label\":\"Today's schedule\",\"dataSource\":\"member.bookings.schedule\",\"emptyWhen\":[\"hideMemberProgress\"]},{\"id\":\"up_next\",\"label\":\"Up next\",\"dataSource\":\"member.bookings\",\"emptyWhen\":[\"hideNextBooking\",\"hidePersonalError\"]},{\"id\":\"saved\",\"label\":\"Saved on this device\",\"dataSource\":\"device.saved_items\",\"emptyWhen\":[\"noSavedContent\"]},{\"id\":\"section_0\",\"label\":\"Today's schedule\",\"dataSource\":\"calmStudio.section0\",\"emptyWhen\":[\"noTodaysClasses\"]},{\"id\":\"section_1\",\"label\":\"Your practice\",\"dataSource\":\"calmStudio.section1\"}]",
|
|
2352
2352
|
"ownerDefaultLayout": "calmStudio",
|
|
2353
|
+
"weeklyGoal": "2",
|
|
2353
2354
|
"copy": "{\"home.bookClassCta\":\"Reserve your spot\",\"home.onboardingBody\":\"Reserve classes, follow programs, and join retreats — all from one calm place.\",\"home.practiceTitle\":\"Your practice\",\"home.profileBody\":\"Sign in for bookings, RSVPs, memberships, programs and saved posts.\",\"home.retreatsTitle\":\"Retreats & workshops\",\"home.scheduleTitle\":\"Today's schedule\",\"home.teachersCaption\":\"Your teachers\"}"
|
|
2354
2355
|
}
|
|
2355
2356
|
}
|
|
@@ -8391,6 +8392,91 @@ const SCREENS = runtimeSetting({
|
|
|
8391
8392
|
}
|
|
8392
8393
|
}
|
|
8393
8394
|
},
|
|
8395
|
+
{
|
|
8396
|
+
"id": "himi_bookings.tracker",
|
|
8397
|
+
"body": {
|
|
8398
|
+
"package": "himalaya",
|
|
8399
|
+
"type": "VStack",
|
|
8400
|
+
"props": {
|
|
8401
|
+
"spacing": 8,
|
|
8402
|
+
"alignment": "leading",
|
|
8403
|
+
"children": [
|
|
8404
|
+
{
|
|
8405
|
+
"id": "",
|
|
8406
|
+
"body": {
|
|
8407
|
+
"package": "himalaya",
|
|
8408
|
+
"type": "Text",
|
|
8409
|
+
"props": {
|
|
8410
|
+
"text": "This week",
|
|
8411
|
+
"style": "footnote",
|
|
8412
|
+
"color": "textSecondary"
|
|
8413
|
+
}
|
|
8414
|
+
}
|
|
8415
|
+
},
|
|
8416
|
+
{
|
|
8417
|
+
"id": "himi_bookings.weekly_label",
|
|
8418
|
+
"body": {
|
|
8419
|
+
"package": "himalaya",
|
|
8420
|
+
"type": "Text",
|
|
8421
|
+
"props": {
|
|
8422
|
+
"text": "$service:himiBookingBookings.weeklyLabel",
|
|
8423
|
+
"style": "title2"
|
|
8424
|
+
}
|
|
8425
|
+
}
|
|
8426
|
+
},
|
|
8427
|
+
{
|
|
8428
|
+
"id": "himi_bookings.weekly_progress",
|
|
8429
|
+
"body": {
|
|
8430
|
+
"package": "himalaya",
|
|
8431
|
+
"type": "ProgressBar",
|
|
8432
|
+
"props": {
|
|
8433
|
+
"progress": 0,
|
|
8434
|
+
"progressPath": "$service:himiBookingBookings.weeklyPct",
|
|
8435
|
+
"tint": "accentPrimary",
|
|
8436
|
+
"trackColor": "surfaceTertiary"
|
|
8437
|
+
}
|
|
8438
|
+
},
|
|
8439
|
+
"modifiers": {
|
|
8440
|
+
"accessibilityLabel": "This week",
|
|
8441
|
+
"accessibilityValue": "$service:himiBookingBookings.weeklyLabel"
|
|
8442
|
+
}
|
|
8443
|
+
},
|
|
8444
|
+
{
|
|
8445
|
+
"id": "",
|
|
8446
|
+
"body": {
|
|
8447
|
+
"package": "himalaya",
|
|
8448
|
+
"type": "Text",
|
|
8449
|
+
"props": {
|
|
8450
|
+
"text": "$service:himiBookingBookings.weeklyRemainingLabel",
|
|
8451
|
+
"style": "body",
|
|
8452
|
+
"color": "textSecondary"
|
|
8453
|
+
}
|
|
8454
|
+
}
|
|
8455
|
+
}
|
|
8456
|
+
]
|
|
8457
|
+
}
|
|
8458
|
+
},
|
|
8459
|
+
"modifiers": {
|
|
8460
|
+
"background": {
|
|
8461
|
+
"token": "surfaceElevated"
|
|
8462
|
+
},
|
|
8463
|
+
"border": {
|
|
8464
|
+
"width": 1,
|
|
8465
|
+
"color": {
|
|
8466
|
+
"token": "border"
|
|
8467
|
+
}
|
|
8468
|
+
},
|
|
8469
|
+
"cornerRadius": 16,
|
|
8470
|
+
"padding": {
|
|
8471
|
+
"leading": 16,
|
|
8472
|
+
"trailing": 16,
|
|
8473
|
+
"top": 16,
|
|
8474
|
+
"bottom": 16
|
|
8475
|
+
},
|
|
8476
|
+
"fillMaxWidth": true,
|
|
8477
|
+
"hiddenPath": "$service:himiBookingBookings.hideTracker"
|
|
8478
|
+
}
|
|
8479
|
+
},
|
|
8394
8480
|
{
|
|
8395
8481
|
"id": "himi_bookings.schedule_view",
|
|
8396
8482
|
"body": {
|
|
@@ -11428,7 +11514,10 @@ const SCREENS = runtimeSetting({
|
|
|
11428
11514
|
"bottom": 24
|
|
11429
11515
|
},
|
|
11430
11516
|
"onAppear": {
|
|
11431
|
-
"actionId": "tier5.himiBookingBookings.load"
|
|
11517
|
+
"actionId": "tier5.himiBookingBookings.load",
|
|
11518
|
+
"params": {
|
|
11519
|
+
"weeklyGoal": "2"
|
|
11520
|
+
}
|
|
11432
11521
|
}
|
|
11433
11522
|
}
|
|
11434
11523
|
},
|
|
@@ -11,6 +11,8 @@ export interface CollectionSaving {
|
|
|
11
11
|
type State = Record<string, unknown>;
|
|
12
12
|
interface BackendCollection {
|
|
13
13
|
restorePagesOnLoad?: boolean;
|
|
14
|
+
/** Sees the load action's argument (the screen's onAppear params) BEFORE the query runs. */
|
|
15
|
+
onLoad?(arg: unknown): void;
|
|
14
16
|
controller: ReturnType<typeof createCollectionQuery<CollectionRow>>;
|
|
15
17
|
apply(state: State, page: CollectionQueryState<CollectionRow>): State;
|
|
16
18
|
}
|
|
@@ -294,6 +296,7 @@ export function decorateCollection(name: string, def: { state: State; actions?:
|
|
|
294
296
|
actions.collectionDataChanged = s => derive(backend.apply(s, backend.controller.getState()));
|
|
295
297
|
actions.load = (_s, arg) => {
|
|
296
298
|
stashCopy(arg); syncSaved(); applyNavigationCriteria(arg, _s);
|
|
299
|
+
backend.onLoad?.(arg);
|
|
297
300
|
return backend.controller.query(criteria(), backend.restorePagesOnLoad).then(() => undefined);
|
|
298
301
|
};
|
|
299
302
|
actions.refresh = (_s, arg) => {
|
|
@@ -320,6 +323,9 @@ export function decorateCollection(name: string, def: { state: State; actions?:
|
|
|
320
323
|
export function defineBackendCollection<S extends object, Row extends object>(name: string, options: {
|
|
321
324
|
/** Revalidate already opened pages on navigation return; explicit refresh resets. */
|
|
322
325
|
restorePagesOnLoad?: boolean;
|
|
326
|
+
/** The load action's argument (onAppear params beyond `copy`), before the query runs — for a
|
|
327
|
+
* domain setting that rides the descriptor, e.g. My Bookings' `weeklyGoal`. */
|
|
328
|
+
onLoad?(arg: unknown): void;
|
|
323
329
|
state: S;
|
|
324
330
|
source: CollectionQuerySource<Row>;
|
|
325
331
|
apply(state: S, page: CollectionQueryState<Row>): S;
|
|
@@ -330,6 +336,7 @@ export function defineBackendCollection<S extends object, Row extends object>(na
|
|
|
330
336
|
const controller = createCollectionQuery(options.source, () => { publish?.(); });
|
|
331
337
|
const definition = decorateCollection(name, { state: options.state as State, actions: options.actions as Record<string, Reducer> | undefined }, options.saving, {
|
|
332
338
|
restorePagesOnLoad: options.restorePagesOnLoad,
|
|
339
|
+
onLoad: options.onLoad,
|
|
333
340
|
controller: controller as unknown as BackendCollection['controller'],
|
|
334
341
|
apply: (state, page) => options.apply(state as S, page as unknown as CollectionQueryState<Row>) as State,
|
|
335
342
|
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// The weekly session goal (`provisioning.goals.weeklySessions`) over a member's own bookings —
|
|
2
|
+
// shared by the home weekly-goal Gauge (himi-branded-lite-home) and the My Bookings "This week"
|
|
3
|
+
// card (himi-booking-bookings), so the two can never count differently.
|
|
4
|
+
//
|
|
5
|
+
// WHAT COUNTS as a session toward the goal: a CONFIRMED booking whose start falls in the CURRENT
|
|
6
|
+
// calendar week (Monday 00:00 local → now) and is already in the past. An allow-list, not a
|
|
7
|
+
// deny-list: CREATED (checkout never completed), PENDING / PENDING_APPROVAL / PENDING_CHECKOUT,
|
|
8
|
+
// WAITING_LIST, CANCELED and DECLINED — and any status Wix adds later — do not count. That is
|
|
9
|
+
// "booked and it happened", not verified
|
|
10
|
+
// attendance: the member-scoped queryBookings row carries no attendance/check-in field (the Wix
|
|
11
|
+
// Attendance API is owner-scoped), so a no-show still counts. Future bookings this week do not
|
|
12
|
+
// count — they have not happened yet.
|
|
13
|
+
//
|
|
14
|
+
// DETERMINISM: nothing here runs at worker boot; every clock read is an argument. PURE (no network,
|
|
15
|
+
// no bridge) so the rules are unit-tested directly; the read lives with its caller.
|
|
16
|
+
|
|
17
|
+
import type { MemberBookingRow } from "./member-bookings.js";
|
|
18
|
+
import { copyParam, copyTemplate } from "./himi-copy.js";
|
|
19
|
+
|
|
20
|
+
export const MAX_WEEKLY_SESSION_GOAL = 21;
|
|
21
|
+
|
|
22
|
+
/** The one status that means the session was booked and held (as memberBookingRow normalizes
|
|
23
|
+
* it: upper-case, `_` → space). */
|
|
24
|
+
const COUNTS_AS_SESSION = /^CONFIRMED$/;
|
|
25
|
+
|
|
26
|
+
/** At most this many pages of past bookings are read for one week's count. */
|
|
27
|
+
export const MAX_WEEKLY_PAGES = 4;
|
|
28
|
+
|
|
29
|
+
/** The onAppear `weeklyGoal` param → a goal in [1, 21], or 0 = no goal provisioned. */
|
|
30
|
+
export function parseWeeklyGoal(raw: unknown): number {
|
|
31
|
+
const n = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
32
|
+
return Number.isInteger(n) && n >= 1 ? Math.min(n, MAX_WEEKLY_SESSION_GOAL) : 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Monday 00:00 local of `now`'s week, epoch ms. */
|
|
36
|
+
export function weekStartMs(now: number): number {
|
|
37
|
+
const d = new Date(now);
|
|
38
|
+
d.setHours(0, 0, 0, 0);
|
|
39
|
+
d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
|
|
40
|
+
return d.getTime();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Sessions toward the goal among `rows` — see the file header for what counts. */
|
|
44
|
+
export function weeklySessionsDone(rows: readonly MemberBookingRow[], now: number): number {
|
|
45
|
+
const from = weekStartMs(now);
|
|
46
|
+
const seen = new Set<string>();
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
const start = Date.parse(row.start);
|
|
49
|
+
if (!Number.isFinite(start) || start < from || start >= now) continue;
|
|
50
|
+
if (!COUNTS_AS_SESSION.test((row.status || "").trim().toUpperCase())) continue;
|
|
51
|
+
seen.add(row.id || `${row.start}|${row.title}`);
|
|
52
|
+
}
|
|
53
|
+
return seen.size;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface BookingsPage {
|
|
57
|
+
items: MemberBookingRow[];
|
|
58
|
+
nextCursor?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Sessions toward the goal from PAST bookings read newest-first: `first` is the first page, and
|
|
62
|
+
* `next(cursor)` reads more only while the oldest row so far is still inside this week (a page of
|
|
63
|
+
* 50 almost always reaches back before Monday). Bounded to MAX_WEEKLY_PAGES reads; a failing
|
|
64
|
+
* read rejects, so the caller hides the count rather than under-counting. */
|
|
65
|
+
export async function weeklySessionsFromPages(
|
|
66
|
+
first: BookingsPage,
|
|
67
|
+
next: (cursor: string) => Promise<BookingsPage>,
|
|
68
|
+
now: number,
|
|
69
|
+
): Promise<number> {
|
|
70
|
+
const from = weekStartMs(now);
|
|
71
|
+
const rows = [...first.items];
|
|
72
|
+
let page = first;
|
|
73
|
+
for (let read = 1; read < MAX_WEEKLY_PAGES && page.nextCursor; read++) {
|
|
74
|
+
const oldest = page.items[page.items.length - 1];
|
|
75
|
+
if (oldest && Date.parse(oldest.start) < from) break;
|
|
76
|
+
page = await next(page.nextCursor);
|
|
77
|
+
rows.push(...page.items);
|
|
78
|
+
}
|
|
79
|
+
return weeklySessionsDone(rows, now);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface WeeklyGoalProgress {
|
|
83
|
+
done: number;
|
|
84
|
+
goal: number;
|
|
85
|
+
/** 0..1 — the Gauge / ProgressBar fill. */
|
|
86
|
+
fraction: number;
|
|
87
|
+
met: boolean;
|
|
88
|
+
/** "1 of 2 sessions this week" */
|
|
89
|
+
label: string;
|
|
90
|
+
/** "1 more to reach your weekly goal" / "Weekly goal reached. Great consistency." */
|
|
91
|
+
remainingLabel: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function weeklyGoalProgress(done: number, goal: number): WeeklyGoalProgress {
|
|
95
|
+
const safeGoal = Math.max(1, goal);
|
|
96
|
+
const met = done >= safeGoal;
|
|
97
|
+
return {
|
|
98
|
+
done,
|
|
99
|
+
goal: safeGoal,
|
|
100
|
+
fraction: Math.min(done / safeGoal, 1),
|
|
101
|
+
met,
|
|
102
|
+
label: copyTemplate("weeklyGoal.progress", "{done} of {goal} sessions this week", { done, goal: safeGoal }),
|
|
103
|
+
remainingLabel: met
|
|
104
|
+
? copyParam("weeklyGoal.met", "Weekly goal reached. Great consistency.")
|
|
105
|
+
: copyTemplate("weeklyGoal.remaining", "{count} more to reach your weekly goal", { count: safeGoal - done }),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -6,6 +6,7 @@ import { memberAccess, assertMemberAccess, memberAccessChanged, memberAccessDeni
|
|
|
6
6
|
import { fetchMemberBookings, type MemberBookingRow } from "../_shared/member-bookings.js";
|
|
7
7
|
import { dayKey, dayLabel } from "@himalaya/time";
|
|
8
8
|
import { localPreferences } from "../_shared/local-preferences.js";
|
|
9
|
+
import { parseWeeklyGoal, weeklyGoalProgress, weeklySessionsFromPages } from "../_shared/weekly-goal.js";
|
|
9
10
|
|
|
10
11
|
const input = (globalThis as { himalaya?: { input?: Record<string, unknown> } }).himalaya?.input;
|
|
11
12
|
const validDate = (value: unknown): value is string => typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value) && dayKey(new Date(`${value}T12:00:00`)) === value;
|
|
@@ -21,6 +22,26 @@ let pageMember: MemberAccess | undefined;
|
|
|
21
22
|
let queryNow = ""; // set by the first-page fetch, never at boot (see selectedDate)
|
|
22
23
|
let cancelTarget: { row: MemberBookingRow; member: MemberAccess } | undefined;
|
|
23
24
|
let cancelling = false;
|
|
25
|
+
// The weekly session goal (`provisioning.goals.weeklySessions`), from the onAppear `weeklyGoal`
|
|
26
|
+
// param — 0 when the app provisions none, which keeps the "This week" card hidden for good. The
|
|
27
|
+
// count comes from a dedicated read of this week's PAST bookings on each first-page fetch, NOT
|
|
28
|
+
// from `rows` (those follow the list's filter — Upcoming by default — and would read 0).
|
|
29
|
+
let weeklyGoal = 0;
|
|
30
|
+
/** The count of the page that APPLIED — set in `apply`, never by a fetch, so a superseded fetch
|
|
31
|
+
* (another member, a refresh) cannot overwrite it: it travels in that page's metadata and is
|
|
32
|
+
* dropped with it. */
|
|
33
|
+
let weeklyDone: number | null = null;
|
|
34
|
+
/** This week's sessions from the PAST bookings, newest first (paged only while still inside this
|
|
35
|
+
* week). null when a read fails, so the card hides rather than claiming "0 of N". */
|
|
36
|
+
async function fetchWeeklySessionsDone(member: MemberAccess, now: number): Promise<number | null> {
|
|
37
|
+
try {
|
|
38
|
+
const nowIso = new Date(now).toISOString();
|
|
39
|
+
const read = (cursor: string) => fetchMemberBookings({ query: "", filter: "value:Past", sort: "za", savedIds: [] }, cursor, nowIso, member);
|
|
40
|
+
return await weeklySessionsFromPages(await read(""), read, now);
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
24
45
|
interface S {
|
|
25
46
|
status: "loading" | "ready" | "error"; rows: MemberBookingRow[]; isMember: boolean; identityLine: string;
|
|
26
47
|
emptyText: string; isLoading: boolean; notLoading: boolean; errored: boolean; notErrored: boolean; noEmpty: boolean;
|
|
@@ -28,6 +49,7 @@ interface S {
|
|
|
28
49
|
scheduleMode: string; selectedDate: string; dayRows: MemberBookingRow[]; dayHeading: string;
|
|
29
50
|
hideAgenda: boolean; hideCalendar: boolean; hideMonth: boolean; hideSchedule: boolean;
|
|
30
51
|
dayEmptyText: string; decorations: Array<{ date: string; dotCount: number; dotColorToken: string }>;
|
|
52
|
+
weeklyLabel: string; weeklyRemainingLabel: string; weeklyPct: number; weeklyMet: boolean; hideTracker: boolean;
|
|
31
53
|
nextCursor?: string; complete?: boolean; loadingMore?: boolean; pageError?: boolean; total?: number;
|
|
32
54
|
}
|
|
33
55
|
function derive(s: S): S {
|
|
@@ -36,7 +58,12 @@ function derive(s: S): S {
|
|
|
36
58
|
const dayRows = selectedDate ? s.rows.filter(row => row.day === selectedDate) : [];
|
|
37
59
|
const counts = new Map<string, number>();
|
|
38
60
|
for (const row of s.rows) if (row.day) counts.set(row.day, (counts.get(row.day) ?? 0) + 1);
|
|
39
|
-
|
|
61
|
+
// Member-only, and only once this week's count was actually read (a failed read hides the card
|
|
62
|
+
// rather than claiming "0 of N").
|
|
63
|
+
const weekly = weeklyGoal > 0 && !hideSchedule && weeklyDone !== null ? weeklyGoalProgress(weeklyDone, weeklyGoal) : null;
|
|
64
|
+
return { ...s, scheduleMode: mode,
|
|
65
|
+
weeklyLabel: weekly?.label ?? "", weeklyRemainingLabel: weekly?.remainingLabel ?? "", weeklyPct: weekly?.fraction ?? 0,
|
|
66
|
+
weeklyMet: weekly?.met ?? false, hideTracker: !weekly, selectedDate, dayRows, dayHeading: selectedDate ? dayLabel(selectedDate) : "", hideSchedule,
|
|
40
67
|
hideAgenda: hideSchedule || mode !== "agenda", hideCalendar: hideSchedule || mode === "agenda", hideMonth: mode !== "month",
|
|
41
68
|
decorations: [...counts].map(([date, n]) => ({ date, dotCount: Math.min(n, 3), dotColorToken: "accentPrimary" })),
|
|
42
69
|
dayEmptyText: dayRows.length ? "" : s.complete ? copyParam("bookings.emptyDay", "No bookings on this day.") : copyParam("bookings.emptyLoadedDay", "No bookings on this day in loaded results. Load more to check later pages."),
|
|
@@ -46,7 +73,12 @@ const svc = defineBackendCollection<S, MemberBookingRow>("himiBookingBookings",
|
|
|
46
73
|
restorePagesOnLoad: true,
|
|
47
74
|
state: derive({ status: "loading", rows: [], isMember: false, identityLine: "", emptyText: "", isLoading: true, notLoading: false,
|
|
48
75
|
errored: false, notErrored: true, noEmpty: true, actionMessage: "", cancelPresented: false, cancelTitle: "",
|
|
49
|
-
scheduleMode: mode, selectedDate, dayRows: [], dayHeading: "", hideAgenda: true, hideCalendar: true, hideMonth: true, hideSchedule: true, dayEmptyText: "", decorations: []
|
|
76
|
+
scheduleMode: mode, selectedDate, dayRows: [], dayHeading: "", hideAgenda: true, hideCalendar: true, hideMonth: true, hideSchedule: true, dayEmptyText: "", decorations: [],
|
|
77
|
+
weeklyLabel: "", weeklyRemainingLabel: "", weeklyPct: 0, weeklyMet: false, hideTracker: true }),
|
|
78
|
+
onLoad(arg) {
|
|
79
|
+
const goal = parseWeeklyGoal((arg as Record<string, unknown> | undefined)?.weeklyGoal);
|
|
80
|
+
if (goal) weeklyGoal = goal;
|
|
81
|
+
},
|
|
50
82
|
source: {
|
|
51
83
|
id: row => row.id,
|
|
52
84
|
clearOnError: memberAccessDenied,
|
|
@@ -55,12 +87,17 @@ const svc = defineBackendCollection<S, MemberBookingRow>("himiBookingBookings",
|
|
|
55
87
|
const member = await memberAccess();
|
|
56
88
|
if (cursor && (!pageMember || pageMember.email !== member.email || pageMember.scope !== member.scope)) throw memberAccessChanged();
|
|
57
89
|
if (!cursor || !queryNow) queryNow = new Date().toISOString();
|
|
58
|
-
|
|
90
|
+
const page = await fetchMemberBookings(criteria, cursor, queryNow, member);
|
|
91
|
+
if (cursor) return page;
|
|
92
|
+
const weekly = weeklyGoal > 0 && member.email ? await fetchWeeklySessionsDone(member, Date.now()) : null;
|
|
93
|
+
return { ...page, metadata: { ...page.metadata, weeklyDone: weekly } };
|
|
59
94
|
},
|
|
60
95
|
},
|
|
61
96
|
apply(s, page) {
|
|
62
97
|
const member = { email: String(page.metadata?.email ?? ""), scope: String(page.metadata?.scope ?? "") };
|
|
63
|
-
if (page.status === "loading" || !member.email) { pageMember = undefined; cancelTarget = undefined; }
|
|
98
|
+
if (page.status === "loading" || !member.email) { pageMember = undefined; cancelTarget = undefined; weeklyDone = null; }
|
|
99
|
+
const weekly = page.metadata?.weeklyDone;
|
|
100
|
+
if (page.status === "ready" && !page.loadingMore && (typeof weekly === "number" || weekly === null)) weeklyDone = weekly;
|
|
64
101
|
if (page.status === "ready" && !page.loadingMore && !page.pageError) pageMember = member;
|
|
65
102
|
const loading = page.status === "loading", errored = page.status === "error";
|
|
66
103
|
return derive({ ...s, status: loading ? "loading" : errored ? "error" : "ready", rows: page.items, isMember: !!member.email,
|
|
@@ -14,6 +14,7 @@ import { formatServicePrice } from "../_shared/wix-service-price.js";
|
|
|
14
14
|
import { cleanTitle, initials } from "../_shared/himi-text.js";
|
|
15
15
|
import { accentColor as resolveAccentColor, ACCENT_KEY, LAYOUT_KEY, type LayoutId, recommendLayout, resolveLayout } from "../_shared/himi-layouts.js";
|
|
16
16
|
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
17
|
+
import { parseWeeklyGoal, weeklyGoalProgress, weeklySessionsFromPages } from "../_shared/weekly-goal.js";
|
|
17
18
|
import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
|
|
18
19
|
import { formatDateMedium } from "../_shared/engine-intl.js";
|
|
19
20
|
import { readSavedProducts, type SavedProduct } from "../_shared/himi-store-saved.js";
|
|
@@ -837,7 +838,10 @@ function derive(state: State): State {
|
|
|
837
838
|
// hide them entirely, so every non-bookings layout renders unchanged.
|
|
838
839
|
noTodaysClasses: state.todaysClasses.length === 0,
|
|
839
840
|
noCoachAvatars: state.coachAvatars.length === 0,
|
|
840
|
-
|
|
841
|
+
// The weekly-goal Gauge shows only for a signed-in member of an app that provisions
|
|
842
|
+
// `goals.weeklySessions` — the label is set by refreshPersonal exactly then, and stays "" for
|
|
843
|
+
// a visitor or an app without a goal (so it shows at "0 of 2", but never as fake progress).
|
|
844
|
+
noWeeklyGoal: state.weeklyGoalLabel === "",
|
|
841
845
|
// Collapse gates for the salonLuxe / calmStudio / communityPulse blocks —
|
|
842
846
|
// the same contract: empty data hides the block entirely.
|
|
843
847
|
noServiceShowcase: state.serviceShowcase.length === 0,
|
|
@@ -1070,6 +1074,8 @@ function memberSchedule(rows: MemberBookingRow[], now = new Date()): { label: st
|
|
|
1070
1074
|
async function refreshPersonal(generation: number, arg?: unknown): Promise<void> {
|
|
1071
1075
|
const member = await memberAccess();
|
|
1072
1076
|
let rows: MemberBookingRow[] = [], progress = { label: "", fraction: 0 }, error = false;
|
|
1077
|
+
let weekly: { count: number; fraction: number; label: string } | null = null;
|
|
1078
|
+
const weeklyGoal = parseWeeklyGoal(paramValue(arg, "weeklyGoal"));
|
|
1073
1079
|
if (member.email && parseVerticals(arg).includes("bookings")) {
|
|
1074
1080
|
const now = new Date();
|
|
1075
1081
|
const [upcoming, past] = await Promise.allSettled([
|
|
@@ -1087,10 +1093,24 @@ async function refreshPersonal(generation: number, arg?: unknown): Promise<void>
|
|
|
1087
1093
|
// when either query failed.
|
|
1088
1094
|
progress = memberSchedule([...upcoming.value.items, ...past.value.items], now);
|
|
1089
1095
|
}
|
|
1096
|
+
if (weeklyGoal > 0 && past.status === "fulfilled") {
|
|
1097
|
+
// The goal counts sessions that already HAPPENED this week (_shared/weekly-goal.ts). A
|
|
1098
|
+
// failed past read leaves it hidden rather than claiming "0 of N".
|
|
1099
|
+
// Pages further back only while the first page still sits inside this week; a failing
|
|
1100
|
+
// later page hides the Gauge too.
|
|
1101
|
+
try {
|
|
1102
|
+
const readPast = (cursor: string) =>
|
|
1103
|
+
fetchMemberBookings({ query: "", filter: "value:Past", sort: "za", savedIds: [] }, cursor, now.toISOString(), member);
|
|
1104
|
+
const goal = weeklyGoalProgress(await weeklySessionsFromPages(past.value, readPast, now.getTime()), weeklyGoal);
|
|
1105
|
+
weekly = { count: goal.done, fraction: goal.fraction, label: goal.label };
|
|
1106
|
+
} catch {
|
|
1107
|
+
weekly = null;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1090
1110
|
error = upcoming.status === "rejected" || past.status === "rejected";
|
|
1091
|
-
try { await assertMemberAccess(member); } catch { rows = []; progress = { label: "", fraction: 0 }; error = false; }
|
|
1111
|
+
try { await assertMemberAccess(member); } catch { rows = []; progress = { label: "", fraction: 0 }; error = false; weekly = null; }
|
|
1092
1112
|
}
|
|
1093
|
-
if (generation === personalGeneration) svc.personalLoaded({ generation, rows, progress, error });
|
|
1113
|
+
if (generation === personalGeneration) svc.personalLoaded({ generation, rows, progress, error, weekly });
|
|
1094
1114
|
}
|
|
1095
1115
|
async function refresh(state: State, arg?: unknown): Promise<State | undefined> {
|
|
1096
1116
|
const generation = ++personalGeneration;
|
|
@@ -1102,7 +1122,9 @@ async function refresh(state: State, arg?: unknown): Promise<State | undefined>
|
|
|
1102
1122
|
const current = svc.getState();
|
|
1103
1123
|
return derive({ ...publicState, nextBooking: current.nextBooking, hideNextBooking: current.hideNextBooking,
|
|
1104
1124
|
memberProgressLabel: current.memberProgressLabel, memberProgressFraction: current.memberProgressFraction,
|
|
1105
|
-
hideMemberProgress: current.hideMemberProgress, personalError: current.personalError, hidePersonalError: current.hidePersonalError
|
|
1125
|
+
hideMemberProgress: current.hideMemberProgress, personalError: current.personalError, hidePersonalError: current.hidePersonalError,
|
|
1126
|
+
// The weekly goal is PERSONAL (member bookings); the public refresh resets it, so keep it.
|
|
1127
|
+
weeklyClassCount: current.weeklyClassCount, weeklyClassGoalFraction: current.weeklyClassGoalFraction, weeklyGoalLabel: current.weeklyGoalLabel });
|
|
1106
1128
|
}
|
|
1107
1129
|
|
|
1108
1130
|
const svc = defineService<State, {
|
|
@@ -1113,15 +1135,17 @@ const svc = defineService<State, {
|
|
|
1113
1135
|
refresh: (state: State, arg?: unknown) => Promise<State | undefined>;
|
|
1114
1136
|
dismissOnboarding: (state: State) => State;
|
|
1115
1137
|
clearPersonal: (state: State) => State;
|
|
1116
|
-
personalLoaded: (state: State, arg: { generation: number; rows: MemberBookingRow[]; progress: { label: string; fraction: number }; error: boolean }) => State;
|
|
1138
|
+
personalLoaded: (state: State, arg: { generation: number; rows: MemberBookingRow[]; progress: { label: string; fraction: number }; error: boolean; weekly: { count: number; fraction: number; label: string } | null }) => State;
|
|
1117
1139
|
}>("himiBrandedHome", {
|
|
1118
1140
|
state: baseState(),
|
|
1119
1141
|
actions: {
|
|
1120
|
-
clearPersonal: state => ({ ...state, nextBooking: [], hideNextBooking: true, memberProgressLabel: "", memberProgressFraction: 0, hideMemberProgress: true, personalError: false, hidePersonalError: true
|
|
1142
|
+
clearPersonal: state => derive({ ...state, nextBooking: [], hideNextBooking: true, memberProgressLabel: "", memberProgressFraction: 0, hideMemberProgress: true, personalError: false, hidePersonalError: true,
|
|
1143
|
+
weeklyClassCount: 0, weeklyClassGoalFraction: 0, weeklyGoalLabel: "" }),
|
|
1121
1144
|
personalLoaded: (state, arg) => arg.generation !== personalGeneration ? state : derive({ ...state,
|
|
1122
1145
|
nextBooking: arg.rows, hideNextBooking: !arg.rows.length,
|
|
1123
1146
|
memberProgressLabel: arg.progress.label, memberProgressFraction: arg.progress.fraction, hideMemberProgress: !arg.progress.label,
|
|
1124
|
-
personalError: arg.error, hidePersonalError: !arg.error
|
|
1147
|
+
personalError: arg.error, hidePersonalError: !arg.error,
|
|
1148
|
+
weeklyClassCount: arg.weekly?.count ?? 0, weeklyClassGoalFraction: arg.weekly?.fraction ?? 0, weeklyGoalLabel: arg.weekly?.label ?? "" }),
|
|
1125
1149
|
refresh,
|
|
1126
1150
|
// "Got it" on the first-run card: persist + hide. Persistence is
|
|
1127
1151
|
// best-effort — the UI hides either way for this session.
|
|
@@ -11,6 +11,8 @@ export interface CollectionSaving {
|
|
|
11
11
|
type State = Record<string, unknown>;
|
|
12
12
|
interface BackendCollection {
|
|
13
13
|
restorePagesOnLoad?: boolean;
|
|
14
|
+
/** Sees the load action's argument (the screen's onAppear params) BEFORE the query runs. */
|
|
15
|
+
onLoad?(arg: unknown): void;
|
|
14
16
|
controller: ReturnType<typeof createCollectionQuery<CollectionRow>>;
|
|
15
17
|
apply(state: State, page: CollectionQueryState<CollectionRow>): State;
|
|
16
18
|
}
|
|
@@ -294,6 +296,7 @@ export function decorateCollection(name: string, def: { state: State; actions?:
|
|
|
294
296
|
actions.collectionDataChanged = s => derive(backend.apply(s, backend.controller.getState()));
|
|
295
297
|
actions.load = (_s, arg) => {
|
|
296
298
|
stashCopy(arg); syncSaved(); applyNavigationCriteria(arg, _s);
|
|
299
|
+
backend.onLoad?.(arg);
|
|
297
300
|
return backend.controller.query(criteria(), backend.restorePagesOnLoad).then(() => undefined);
|
|
298
301
|
};
|
|
299
302
|
actions.refresh = (_s, arg) => {
|
|
@@ -320,6 +323,9 @@ export function decorateCollection(name: string, def: { state: State; actions?:
|
|
|
320
323
|
export function defineBackendCollection<S extends object, Row extends object>(name: string, options: {
|
|
321
324
|
/** Revalidate already opened pages on navigation return; explicit refresh resets. */
|
|
322
325
|
restorePagesOnLoad?: boolean;
|
|
326
|
+
/** The load action's argument (onAppear params beyond `copy`), before the query runs — for a
|
|
327
|
+
* domain setting that rides the descriptor, e.g. My Bookings' `weeklyGoal`. */
|
|
328
|
+
onLoad?(arg: unknown): void;
|
|
323
329
|
state: S;
|
|
324
330
|
source: CollectionQuerySource<Row>;
|
|
325
331
|
apply(state: S, page: CollectionQueryState<Row>): S;
|
|
@@ -330,6 +336,7 @@ export function defineBackendCollection<S extends object, Row extends object>(na
|
|
|
330
336
|
const controller = createCollectionQuery(options.source, () => { publish?.(); });
|
|
331
337
|
const definition = decorateCollection(name, { state: options.state as State, actions: options.actions as Record<string, Reducer> | undefined }, options.saving, {
|
|
332
338
|
restorePagesOnLoad: options.restorePagesOnLoad,
|
|
339
|
+
onLoad: options.onLoad,
|
|
333
340
|
controller: controller as unknown as BackendCollection['controller'],
|
|
334
341
|
apply: (state, page) => options.apply(state as S, page as unknown as CollectionQueryState<Row>) as State,
|
|
335
342
|
});
|