@wix/himalaya-cli 0.1953.0 → 0.1955.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/auth-providers/wix/src/index.d.ts +5 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-auth.mjs +2 -1
- package/dist/cli.mjs +224 -98
- package/guides/one-app-section-mappings.md +4 -4
- package/guides/one-app-to-himi-app.md +14 -10
- package/package.json +2 -2
- package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/beauty-salon/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/beauty-salon/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/beauty-salon/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/beauty-salon/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/beauty-salon/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/beauty-salon-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/branded-lite/l10n/ar.json +10 -0
- package/templates/branded-lite/l10n/cs.json +10 -0
- package/templates/branded-lite/l10n/da.json +10 -0
- package/templates/branded-lite/l10n/de.json +10 -0
- package/templates/branded-lite/l10n/el.json +10 -0
- package/templates/branded-lite/l10n/es.json +10 -0
- package/templates/branded-lite/l10n/fi.json +10 -0
- package/templates/branded-lite/l10n/fr.json +10 -0
- package/templates/branded-lite/l10n/he.json +9 -0
- package/templates/branded-lite/l10n/hu.json +10 -0
- package/templates/branded-lite/l10n/id.json +10 -0
- package/templates/branded-lite/l10n/it.json +10 -0
- package/templates/branded-lite/l10n/ja.json +10 -0
- package/templates/branded-lite/l10n/ko.json +10 -0
- package/templates/branded-lite/l10n/lt.json +10 -0
- package/templates/branded-lite/l10n/nl.json +10 -0
- package/templates/branded-lite/l10n/no.json +10 -0
- package/templates/branded-lite/l10n/pl.json +10 -0
- package/templates/branded-lite/l10n/pt.json +10 -0
- package/templates/branded-lite/l10n/ru.json +10 -0
- package/templates/branded-lite/l10n/sv.json +10 -0
- package/templates/branded-lite/l10n/th.json +10 -0
- package/templates/branded-lite/l10n/tr.json +10 -0
- package/templates/branded-lite/l10n/uk.json +10 -0
- package/templates/branded-lite/l10n/vi.json +10 -0
- package/templates/branded-lite/l10n/zh.json +10 -0
- package/templates/branded-lite/recipes/blog-carousel-classic.json +335 -0
- package/templates/branded-lite/recipes/blog-carousel-full.json +374 -0
- package/templates/branded-lite/recipes/class-calendar.json +707 -0
- package/templates/branded-lite/recipes/events-inline-carousel.json +308 -0
- package/templates/branded-lite/recipes/galleries-carousel.json +51 -2
- package/templates/branded-lite/recipes/galleries-collage.json +51 -2
- package/templates/branded-lite/recipes/galleries-list.json +51 -2
- package/templates/branded-lite/recipes/groups-cards.json +194 -86
- package/templates/branded-lite/recipes/groups-list.json +209 -62
- package/templates/branded-lite/recipes/upcoming-sessions.json +280 -0
- package/templates/branded-lite/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/branded-lite/tier5-src/_shared/blog-list.ts +5 -1
- package/templates/branded-lite/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/branded-lite/tier5-src/_shared/class-calendar-section.ts +280 -0
- package/templates/branded-lite/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/branded-lite/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/branded-lite/tier5-src/_shared/galleries-section.ts +70 -23
- package/templates/branded-lite/tier5-src/_shared/groups-section.ts +297 -26
- package/templates/branded-lite/tier5-src/_shared/upcoming-sessions-section.ts +121 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/brandy/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/community-club/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/community-club-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/conference/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/events-meetups/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/events-meetups-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/fitness-gym/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/fitness-gym/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/fitness-gym/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/fitness-gym/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/gym-fitness/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/gym-fitness/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/gym-fitness/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/gym-fitness/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/gym-fitness/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/gym-fitness-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/medical-services/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/medical-services/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/nonprofit-cause/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/owner-lite/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/owner-lite/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/podcast-creator/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/portfolio-creative/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/professional-services/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/professional-services/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/restaurant/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/restaurant-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/retail-store/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/retail-store-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/salon-spa/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/salon-spa/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/salon-spa/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/salon-spa/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/wholesale-store/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/yoga-studio/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/yoga-studio/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/yoga-studio/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/yoga-studio/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/yoga-studio/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/yoga-studio-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/branded-lite/recipes/blog-hero.json +0 -95
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// A page's upcoming sessions section as a registrable service: the business's next class and course sessions (the One App's
|
|
2
|
+
// `platform_general_upcoming_section`, the Bookings member widget), read as the Agenda reads them (`class-sessions.ts`). Everyone
|
|
3
|
+
// sees the schedule; a signed-in member also sees their own place in it (Booked, On waitlist), from the same member-scoped read
|
|
4
|
+
// as the Agenda (`placesIn`). Each row is a date block, the class, the day and local times, and its coach; a tap opens the class
|
|
5
|
+
// on that session.
|
|
6
|
+
// limit -> at most N sessions (the source strip shows 3; View All, the source's CTA, always opens the Agenda),
|
|
7
|
+
// interval -> the source's time window from now: "day" (the rest of today), "week" (7 days) or "month" (a calendar month ahead).
|
|
8
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe upcoming-sessions.json).
|
|
9
|
+
import { defineService } from "@himalaya/state";
|
|
10
|
+
import { addDays, dayKey } from "@himalaya/time";
|
|
11
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
12
|
+
import { copyParam, copyTemplate, stashCopy } from "./himi-copy.js";
|
|
13
|
+
import { appLocale } from "./app-locale.js";
|
|
14
|
+
import { formatClock, formatClockRange, formatMonthShort, formatWeekdayShort } from "./engine-intl.js";
|
|
15
|
+
import { placesIn, type MemberPlace, type Session } from "./booking-session.js";
|
|
16
|
+
import { readClassServices, readClassSessions } from "./class-sessions.js";
|
|
17
|
+
|
|
18
|
+
export type UpcomingSessionsInterval = "day" | "week" | "month";
|
|
19
|
+
|
|
20
|
+
export interface UpcomingSessionsOptions {
|
|
21
|
+
/** Show at most this many sessions. */
|
|
22
|
+
limit: number;
|
|
23
|
+
/** The source's time window from now. Default: "month". */
|
|
24
|
+
interval?: UpcomingSessionsInterval;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface UpcomingSessionRow {
|
|
28
|
+
id: string; title: string;
|
|
29
|
+
serviceId: string; sessionId: string; start: string;
|
|
30
|
+
/** The date block: "9" over "DEC". */
|
|
31
|
+
dayNumber: string; month: string;
|
|
32
|
+
/** "Wed, 6:00 PM – 6:40 PM", in the device's time zone. */
|
|
33
|
+
when: string;
|
|
34
|
+
/** "With Dana", "" when the session names no staff member. */
|
|
35
|
+
coach: string; noCoach: boolean;
|
|
36
|
+
/** The member's own place: "Booked" or "On waitlist", "" (and no badge) otherwise. */
|
|
37
|
+
place: string; noPlace: boolean;
|
|
38
|
+
a11y: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface UpcomingSessionsState {
|
|
42
|
+
status: "loading" | "ready" | "error";
|
|
43
|
+
rows: UpcomingSessionRow[];
|
|
44
|
+
emptyText: string;
|
|
45
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean; noEmpty: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The date block's month, short and in capitals as the source draws it: "DEC". */
|
|
49
|
+
const monthShort = (date: Date): string => formatMonthShort(date).replace(/\.$/, "").toLocaleUpperCase(appLocale());
|
|
50
|
+
|
|
51
|
+
/** The last local day of the window that starts today. */
|
|
52
|
+
export function windowEnd(today: string, interval: UpcomingSessionsInterval): string {
|
|
53
|
+
if (interval === "day") return today;
|
|
54
|
+
if (interval === "week") return dayKey(addDays(today, 6));
|
|
55
|
+
const [y, m, d] = today.split("-").map(Number) as [number, number, number];
|
|
56
|
+
// The same day next month, or that month's last day (Jan 31 → Feb 28), then the day before it: a month of days.
|
|
57
|
+
const next = new Date(y, m, Math.min(d, new Date(y, m + 1, 0).getDate()));
|
|
58
|
+
return dayKey(addDays(next, -1));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function upcomingRow(s: Session, place: MemberPlace | undefined): UpcomingSessionRow {
|
|
62
|
+
const start = new Date(s.start), end = new Date(s.end);
|
|
63
|
+
const range = Date.parse(s.end) > Date.parse(s.start) ? formatClockRange(start, end) : formatClock(start);
|
|
64
|
+
const when = [formatWeekdayShort(start), range].filter(Boolean).join(", ");
|
|
65
|
+
const coach = s.staff ? copyTemplate("service.staffOne", "With {name}", { name: s.staff }) : "";
|
|
66
|
+
const label = place?.place === "booked" ? copyParam("agenda.bookedLabel", "Booked")
|
|
67
|
+
: place?.place === "waitlisted" ? copyParam("agenda.onWaitlistLabel", "On waitlist") : "";
|
|
68
|
+
return {
|
|
69
|
+
id: s.key, title: s.title, serviceId: s.serviceId, sessionId: s.sessionId, start: s.start,
|
|
70
|
+
dayNumber: String(start.getDate()), month: monthShort(start), when, coach, noCoach: !coach,
|
|
71
|
+
place: label, noPlace: !label,
|
|
72
|
+
a11y: [s.title, when, coach, label].filter(Boolean).join(", "),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function registerUpcomingSessionsSection(serviceName: string, options: UpcomingSessionsOptions) {
|
|
77
|
+
const interval: UpcomingSessionsInterval = options.interval === "day" || options.interval === "week" ? options.interval : "month";
|
|
78
|
+
const view = (status: UpcomingSessionsState["status"], rows: UpcomingSessionRow[]): UpcomingSessionsState => ({
|
|
79
|
+
status, rows,
|
|
80
|
+
emptyText: status === "ready" && !rows.length ? copyParam("upcomingSessions.emptyText", "There are no upcoming sessions.") : "",
|
|
81
|
+
notLoading: status !== "loading", notErrored: status !== "error",
|
|
82
|
+
noRows: !rows.length, noEmpty: !(status === "ready" && !rows.length),
|
|
83
|
+
});
|
|
84
|
+
// Only the newest load may answer: a guest read that finishes after the member signed in must not overwrite the member's places.
|
|
85
|
+
let sequence = 0;
|
|
86
|
+
const initial = view("loading", []);
|
|
87
|
+
/** The section appeared (its first load ran): only then does a sign-in or sign-out read it again. */
|
|
88
|
+
let appeared = false;
|
|
89
|
+
const service = defineService<UpcomingSessionsState, { load: (state: UpcomingSessionsState, arg?: unknown) => Promise<UpcomingSessionsState | undefined>; clear: () => UpcomingSessionsState }>(serviceName, {
|
|
90
|
+
state: initial,
|
|
91
|
+
// The Booked badges are one member's: never written to disk and restored for the next person on the device.
|
|
92
|
+
notHydrated: Object.keys(initial) as Array<keyof UpcomingSessionsState>,
|
|
93
|
+
actions: {
|
|
94
|
+
// The member changed: the badges shown are the previous member's, so they go at once.
|
|
95
|
+
clear: () => { ++sequence; return initial; },
|
|
96
|
+
load: async (_state, arg) => {
|
|
97
|
+
stashCopy(arg);
|
|
98
|
+
appeared = true;
|
|
99
|
+
const seq = ++sequence;
|
|
100
|
+
try {
|
|
101
|
+
const now = Date.now();
|
|
102
|
+
const today = dayKey(new Date(now));
|
|
103
|
+
const end = windowEnd(today, interval);
|
|
104
|
+
// Still to come: a session that already started is not upcoming. Only the shown sessions need the member's places.
|
|
105
|
+
const shown = (await readClassSessions(await readClassServices({ share: true }), today, end, { share: true })).filter((s) => Date.parse(s.start) > now).slice(0, options.limit);
|
|
106
|
+
const { found } = await placesIn(today, end, shown);
|
|
107
|
+
if (seq !== sequence) return undefined;
|
|
108
|
+
return view("ready", shown.map((s) => upcomingRow(s, found.get(s.key))));
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (seq !== sequence) return undefined;
|
|
111
|
+
console.warn("upcoming_sessions_section: the sessions could not be read", error);
|
|
112
|
+
return view("error", []);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
// Signing in or out on another screen changes the member's Booked badges.
|
|
118
|
+
// Only once the section has appeared: a page worker registers its services at boot, for pages nobody has opened yet.
|
|
119
|
+
hostSessionFromGlobal().subscribe(() => { if (!appeared) return; void service.clear(); void service.load(); });
|
|
120
|
+
return service;
|
|
121
|
+
}
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
// starts at the selected day, so a day with nothing on it shows the next sessions instead
|
|
21
21
|
// of an empty page — the agenda answers "what is on from here".
|
|
22
22
|
import { defineService, navigate } from "@himalaya/state";
|
|
23
|
-
import { addDays, dayKey, dayLabel, timeLabel,
|
|
23
|
+
import { addDays, dayKey, dayLabel, timeLabel, weekOf, type DayDecoration, type Weekday } from "@himalaya/time";
|
|
24
24
|
import { createEvent, getPermissionStatus, requestPermission } from "@himalaya/calendar";
|
|
25
25
|
import { open } from "@himalaya/open-url";
|
|
26
26
|
import {
|
|
27
|
-
cancelBookingAsMember, isBookingPolicyViolation, leaveWaitlist, listWaitlists, queryBookings,
|
|
28
|
-
|
|
27
|
+
cancelBookingAsMember, isBookingPolicyViolation, leaveWaitlist, listWaitlists, queryBookings,
|
|
28
|
+
registerToWaitlist, type WixAvailabilityEntry, type WixBooking, type WixService,
|
|
29
29
|
} from "@himalaya/wix-bookings";
|
|
30
30
|
import { getMyMember } from "@himalaya/wix-members";
|
|
31
31
|
import { signInPageStyle, signInSheetStyle } from "../_shared/sign-in-sheet.js";
|
|
@@ -34,7 +34,8 @@ import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
|
34
34
|
import { readResultSnackbar, resultSnackbarOn, showResultSnackbar } from "../_shared/result-snackbar.js";
|
|
35
35
|
import { slotStartInstant } from "../_shared/himi-bookings.js";
|
|
36
36
|
import { formatServicePrice } from "../_shared/wix-service-price.js";
|
|
37
|
-
import {
|
|
37
|
+
import { orderedSessions, readClassServices, readClassSessions } from "../_shared/class-sessions.js";
|
|
38
|
+
import { AGENDA_DAYS, decorationsOf, keepsSelection, monthGridOf, selectionForRange, titledDays, windowFor } from "../_shared/agenda-calendar.js";
|
|
38
39
|
import { assertMemberAccess, memberAccess, memberAccessChanged, type MemberAccess } from "../_shared/member-access.js";
|
|
39
40
|
import { atLeast } from "../_shared/member-account-routes.js";
|
|
40
41
|
import { MEMBER_AVATAR_KEYS, memberAvatarSource } from "../_shared/member-avatar.js";
|
|
@@ -44,19 +45,16 @@ import {
|
|
|
44
45
|
type LocationChoice, type LocationOptionRow,
|
|
45
46
|
} from "../_shared/booking-location.js";
|
|
46
47
|
import {
|
|
47
|
-
bySession, markWaitlisted, placesIn, placesOf, sessionControl, sessionKey, sessionOf, spotsLabel,
|
|
48
|
+
bySession, lengthLabel, markWaitlisted, placesIn, placesOf, sessionControl, sessionKey, sessionOf, spotsLabel,
|
|
48
49
|
type MemberPlace, type Place, type Session,
|
|
49
50
|
} from "../_shared/booking-session.js";
|
|
50
51
|
|
|
51
52
|
// The session model is shared with the service screen opened from a row; re-exported for the tests.
|
|
52
|
-
export { bySession, markWaitlisted, placesOf, sessionKey, sessionOf };
|
|
53
|
+
export { bySession, lengthLabel, markWaitlisted, placesOf, sessionKey, sessionOf };
|
|
53
54
|
export type { MemberPlace, Place, Session };
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
export
|
|
57
|
-
/** Services whose sessions are fixed events: a class's are each booked on their own, a course's
|
|
58
|
-
* are listed but the course is booked as a whole (on its service screen). */
|
|
59
|
-
const SESSION_TYPES = new Set(["CLASS", "COURSE"]);
|
|
56
|
+
// The calendar rules are shared with the class calendar section; re-exported for the tests.
|
|
57
|
+
export { AGENDA_DAYS, decorationsOf, keepsSelection, selectionForRange, titledDays, windowFor };
|
|
60
58
|
/** The `Agenda` wire shape: declared fields plus a flat string `extra` map for the row. */
|
|
61
59
|
export interface AgendaEvent {
|
|
62
60
|
id: string;
|
|
@@ -143,16 +141,6 @@ interface S extends LoadFlags {
|
|
|
143
141
|
|
|
144
142
|
const flag = (on: boolean): string => (on ? "true" : "");
|
|
145
143
|
|
|
146
|
-
/** "1 hr", "45 min", "1 hr 30 min" — the length under the time. */
|
|
147
|
-
export function lengthLabel(start: string, end: string): string {
|
|
148
|
-
const mins = Math.round((Date.parse(end) - Date.parse(start)) / 60_000);
|
|
149
|
-
if (!Number.isFinite(mins) || mins <= 0) return "";
|
|
150
|
-
const h = Math.floor(mins / 60), m = mins % 60;
|
|
151
|
-
return h && m
|
|
152
|
-
? copyTemplate("agenda.lengthHoursMinutes", "{h} hr {m} min", { h, m })
|
|
153
|
-
: h ? copyTemplate("agenda.lengthHours", "{h} hr", { h }) : copyTemplate("agenda.lengthMinutes", "{m} min", { m });
|
|
154
|
-
}
|
|
155
|
-
|
|
156
144
|
/** The parts that are known, joined by a middle dot: "Omer Levi · Studio Zen". */
|
|
157
145
|
const joined = (...parts: string[]): string => parts.filter(Boolean).join(" · ");
|
|
158
146
|
|
|
@@ -193,93 +181,6 @@ export function eventOf(s: Session, place: MemberPlace | undefined, lastOfDay =
|
|
|
193
181
|
};
|
|
194
182
|
}
|
|
195
183
|
|
|
196
|
-
/** The first and last cell any month grid of `day`'s month can have, padding included. */
|
|
197
|
-
function monthGrid(day: string): { start: string; end: string } {
|
|
198
|
-
const d = toDate(day);
|
|
199
|
-
if (!d) return { start: day, end: day };
|
|
200
|
-
return { start: dayKey(new Date(d.getFullYear(), d.getMonth(), 1 - 6)), end: dayKey(new Date(d.getFullYear(), d.getMonth() + 1, 6)) };
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** One dot per day that has a session — "something is on", not how much — and the visible
|
|
204
|
-
* days before today dimmed and unselectable: the agenda is what is still to come. */
|
|
205
|
-
export function decorationsOf(sessions: Session[], today: string, rangeStart: string, rangeEnd: string): DayDecoration[] {
|
|
206
|
-
const out: DayDecoration[] = [];
|
|
207
|
-
const dimmed = new Set<string>();
|
|
208
|
-
const dim = (from: string, to: string) => {
|
|
209
|
-
for (let day = from; day && day < today && day <= to; day = dayKey(addDays(day, 1))) {
|
|
210
|
-
if (!dimmed.has(day)) { dimmed.add(day); out.push({ date: day, disabled: true }); }
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
// Bounded by the visible days: a page a year back dims its 7-42 cells, not a year.
|
|
214
|
-
dim(rangeStart, rangeEnd);
|
|
215
|
-
// And this month's grid: an older binary (no week mode) draws it on first open, while it
|
|
216
|
-
// reports nothing until the member pages.
|
|
217
|
-
dim(monthGrid(today).start, today);
|
|
218
|
-
for (const date of [...new Set(sessions.filter((s) => s.day >= today).map((s) => s.day))].sort()) out.push({ date, dotCount: 1 });
|
|
219
|
-
return out;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/** The days to load: the visible days (never before today) through AGENDA_DAYS past the
|
|
223
|
-
* selected day, so the list under the calendar always has its full reach. */
|
|
224
|
-
export function windowFor(today: string, rangeStart: string, rangeEnd: string, selected: string): { start: string; end: string } {
|
|
225
|
-
const start = rangeStart > today ? rangeStart : today;
|
|
226
|
-
const from = selected > today ? selected : today;
|
|
227
|
-
// Through the last cell of the selected day's month grid as well, which is what an older
|
|
228
|
-
// binary draws before it has reported any page: every dot on it is then real.
|
|
229
|
-
const end = [rangeEnd, dayKey(addDays(from, AGENDA_DAYS)), monthGrid(from).end].reduce((a, b) => (b > a ? b : a));
|
|
230
|
-
return { start, end };
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** Where the selection goes when the calendar pages away from it: the first day of the
|
|
234
|
-
* page (the 1st of the titled month in month view — the grid's first cell is padding),
|
|
235
|
-
* or today when that is on the page. A page wholly before today has no day to select (past
|
|
236
|
-
* days are disabled), so `current` stays selected and the list keeps showing from it. */
|
|
237
|
-
export function selectionForRange(today: string, rangeStart: string, rangeEnd: string, current = today): string {
|
|
238
|
-
const { first, last } = titledDays(rangeStart, rangeEnd);
|
|
239
|
-
if (today >= first && today <= last) return today;
|
|
240
|
-
return last < today ? current : first;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** The days a page is about: the whole week, or a month grid's TITLED month — its padding cells
|
|
244
|
-
* belong to the neighbouring months. */
|
|
245
|
-
export function titledDays(rangeStart: string, rangeEnd: string): { first: string; last: string } {
|
|
246
|
-
let first = rangeStart;
|
|
247
|
-
let last = rangeEnd;
|
|
248
|
-
const span = Math.round((Date.parse(rangeEnd) - Date.parse(rangeStart)) / 86_400_000);
|
|
249
|
-
if (span > 7) {
|
|
250
|
-
// A month grid: its padding cells belong to the neighbouring months. Today counts only when
|
|
251
|
-
// it is in the TITLED month — a today in the trailing padding would move the selection, and
|
|
252
|
-
// with it the grid, a month forward.
|
|
253
|
-
const d = toDate(rangeStart);
|
|
254
|
-
if (d) {
|
|
255
|
-
const month = rangeStart.endsWith("-01") ? d : new Date(d.getFullYear(), d.getMonth() + 1, 1);
|
|
256
|
-
first = dayKey(month);
|
|
257
|
-
last = dayKey(new Date(month.getFullYear(), month.getMonth() + 1, 0));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return { first, last };
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/** The month grid (whole weeks) of `day`'s month, as a calendar draws it. */
|
|
264
|
-
function monthGridOf(day: string, firstWeekday: number): { start: string; end: string } | undefined {
|
|
265
|
-
const d = toDate(day);
|
|
266
|
-
if (!d) return undefined;
|
|
267
|
-
const fw = (((firstWeekday % 7) + 7) % 7) as Weekday;
|
|
268
|
-
const start = weekOf(new Date(d.getFullYear(), d.getMonth(), 1), fw)[0];
|
|
269
|
-
const end = weekOf(new Date(d.getFullYear(), d.getMonth() + 1, 0), fw)[6];
|
|
270
|
-
return start && end ? { start, end } : undefined;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/** Does the selection survive a page change? Inside the page's TITLED days, yes — a selection in a
|
|
274
|
-
* month grid's padding belongs to the neighbouring month. Today stays selected on any page that
|
|
275
|
-
* shows it: opening a week that straddles two months into the month holding most of it must not
|
|
276
|
-
* move the agenda off today. */
|
|
277
|
-
export function keepsSelection(cur: { today: string; selectedDate: string }, start: string, end: string): boolean {
|
|
278
|
-
const page = titledDays(start, end);
|
|
279
|
-
if (cur.selectedDate >= page.first && cur.selectedDate <= page.last) return true;
|
|
280
|
-
return !!cur.today && cur.selectedDate === cur.today && cur.today >= start && cur.today <= end;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
184
|
function calendarStamp(ms: number): string {
|
|
284
185
|
return new Date(ms).toISOString().replace(/[-:]/g, "").replace(/\.\d{3}Z$/, "Z");
|
|
285
186
|
}
|
|
@@ -324,50 +225,16 @@ let calendarBusy = false;
|
|
|
324
225
|
|
|
325
226
|
async function sessionServices(): Promise<WixService[]> {
|
|
326
227
|
if (services) return services;
|
|
327
|
-
|
|
328
|
-
// so a misbehaving paging answer cannot loop forever.
|
|
329
|
-
const all: WixService[] = [];
|
|
330
|
-
for (let page = 0; page < 10; page++) {
|
|
331
|
-
const res = await queryServices({ query: { paging: { limit: 100, offset: page * 100 } } } as never);
|
|
332
|
-
const batch = res.services ?? [];
|
|
333
|
-
all.push(...batch);
|
|
334
|
-
if (batch.length < 100) break;
|
|
335
|
-
}
|
|
336
|
-
services = all.filter((svc) => {
|
|
337
|
-
const raw = svc as WixService & { type?: string; hidden?: boolean };
|
|
338
|
-
return !!svc.id && SESSION_TYPES.has((raw.type ?? "").toUpperCase()) && raw.hidden !== true;
|
|
339
|
-
});
|
|
228
|
+
services = await readClassServices();
|
|
340
229
|
return services;
|
|
341
230
|
}
|
|
342
231
|
|
|
343
|
-
/** Every session of every class service in [start, end].
|
|
344
|
-
* call — the proven single-service availability query — so one service failing (a draft,
|
|
345
|
-
* a removed schedule) costs its own rows, never the whole agenda. */
|
|
232
|
+
/** Every session of every class service in [start, end] (`_shared/class-sessions.ts`). */
|
|
346
233
|
async function sessionsIn(start: string, end: string): Promise<Session[]> {
|
|
347
|
-
|
|
348
|
-
const from = new Date(`${start}T00:00:00`).toISOString();
|
|
349
|
-
const to = new Date(`${dayKey(addDays(end, 1))}T00:00:00`).toISOString();
|
|
350
|
-
const settled = await Promise.allSettled(list.map((svc) => queryServiceAvailability(svc.id, from, to, { bookable: false })));
|
|
351
|
-
const failures = settled.filter((r) => r.status === "rejected").length;
|
|
352
|
-
if (list.length && failures === list.length) throw (settled[0] as PromiseRejectedResult).reason;
|
|
353
|
-
const out: Session[] = [];
|
|
354
|
-
settled.forEach((r, i) => {
|
|
355
|
-
if (r.status !== "fulfilled") return;
|
|
356
|
-
for (const entry of r.value.availabilityEntries ?? []) {
|
|
357
|
-
const session = sessionOf(entry, list[i]);
|
|
358
|
-
if (session) out.push(session);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
return ordered(out);
|
|
234
|
+
return readClassSessions(await sessionServices(), start, end);
|
|
362
235
|
}
|
|
363
236
|
|
|
364
|
-
|
|
365
|
-
function ordered(list: Session[]): Session[] {
|
|
366
|
-
const seen = new Set<string>();
|
|
367
|
-
return list
|
|
368
|
-
.filter((s) => (seen.has(s.key) ? false : (seen.add(s.key), true)))
|
|
369
|
-
.sort((a, b) => Date.parse(a.start) - Date.parse(b.start) || compareText(a.title, b.title));
|
|
370
|
-
}
|
|
237
|
+
const ordered = orderedSessions;
|
|
371
238
|
|
|
372
239
|
/** Is `owner` — the member a place was loaded for — still the one signed in, to the same account
|
|
373
240
|
* and business? Asked right before a write, so a sign-out or a switch since the load never
|
|
@@ -118,6 +118,12 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
|
|
|
118
118
|
return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/** `{ month: "short" }` — "Dec": a date block's month, under its day number. */
|
|
122
|
+
export function formatMonthShort(date: Date, locale = appLocale(), timeZone?: string): string {
|
|
123
|
+
if (hasIntl()) return dateFormat(locale, { month: "short" }, timeZone).format(date);
|
|
124
|
+
return MONTHS_SHORT[date.getMonth()]!;
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
/** `{ month: "short", year: "numeric" }` — "Jul 2026", without parsing a localized day.
|
|
122
128
|
* Like the other date helpers, an engine without Intl keeps the documented en-US fallback. */
|
|
123
129
|
export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
|
|
@@ -118,6 +118,12 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
|
|
|
118
118
|
return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/** `{ month: "short" }` — "Dec": a date block's month, under its day number. */
|
|
122
|
+
export function formatMonthShort(date: Date, locale = appLocale(), timeZone?: string): string {
|
|
123
|
+
if (hasIntl()) return dateFormat(locale, { month: "short" }, timeZone).format(date);
|
|
124
|
+
return MONTHS_SHORT[date.getMonth()]!;
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
/** `{ month: "short", year: "numeric" }` — "Jul 2026", without parsing a localized day.
|
|
122
128
|
* Like the other date helpers, an engine without Intl keeps the documented en-US fallback. */
|
|
123
129
|
export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
|
|
@@ -118,6 +118,12 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
|
|
|
118
118
|
return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/** `{ month: "short" }` — "Dec": a date block's month, under its day number. */
|
|
122
|
+
export function formatMonthShort(date: Date, locale = appLocale(), timeZone?: string): string {
|
|
123
|
+
if (hasIntl()) return dateFormat(locale, { month: "short" }, timeZone).format(date);
|
|
124
|
+
return MONTHS_SHORT[date.getMonth()]!;
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
/** `{ month: "short", year: "numeric" }` — "Jul 2026", without parsing a localized day.
|
|
122
128
|
* Like the other date helpers, an engine without Intl keeps the documented en-US fallback. */
|
|
123
129
|
export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
|
|
@@ -76,6 +76,19 @@ export function readSelectedSite(): SelectedSite | null {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** The id of the business last picked in this app's storage, with no check of who picked it.
|
|
80
|
+
* For a question that names a business and nothing else (is it one of this owner's Spaces?),
|
|
81
|
+
* where a wrong id costs a "no"; never for a name or for data shown on screen, which is what
|
|
82
|
+
* `readSelectedSite` guards. */
|
|
83
|
+
export function pickedSiteId(): string {
|
|
84
|
+
try {
|
|
85
|
+
const parsed = JSON.parse(host()?.storage?.getItem(KEY) || "null") as { id?: unknown } | null;
|
|
86
|
+
return typeof parsed?.id === "string" ? parsed.id.trim() : "";
|
|
87
|
+
} catch {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
79
92
|
/** Record the business the owner just picked. Best-effort: a host without storage
|
|
80
93
|
* simply keeps showing the fallback. */
|
|
81
94
|
export function rememberSelectedSite(site: SelectedSite): void {
|
|
@@ -118,6 +118,12 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
|
|
|
118
118
|
return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/** `{ month: "short" }` — "Dec": a date block's month, under its day number. */
|
|
122
|
+
export function formatMonthShort(date: Date, locale = appLocale(), timeZone?: string): string {
|
|
123
|
+
if (hasIntl()) return dateFormat(locale, { month: "short" }, timeZone).format(date);
|
|
124
|
+
return MONTHS_SHORT[date.getMonth()]!;
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
/** `{ month: "short", year: "numeric" }` — "Jul 2026", without parsing a localized day.
|
|
122
128
|
* Like the other date helpers, an engine without Intl keeps the documented en-US fallback. */
|
|
123
129
|
export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
|
|
@@ -118,6 +118,12 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
|
|
|
118
118
|
return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/** `{ month: "short" }` — "Dec": a date block's month, under its day number. */
|
|
122
|
+
export function formatMonthShort(date: Date, locale = appLocale(), timeZone?: string): string {
|
|
123
|
+
if (hasIntl()) return dateFormat(locale, { month: "short" }, timeZone).format(date);
|
|
124
|
+
return MONTHS_SHORT[date.getMonth()]!;
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
/** `{ month: "short", year: "numeric" }` — "Jul 2026", without parsing a localized day.
|
|
122
128
|
* Like the other date helpers, an engine without Intl keeps the documented en-US fallback. */
|
|
123
129
|
export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
|
|
@@ -118,6 +118,12 @@ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: st
|
|
|
118
118
|
return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/** `{ month: "short" }` — "Dec": a date block's month, under its day number. */
|
|
122
|
+
export function formatMonthShort(date: Date, locale = appLocale(), timeZone?: string): string {
|
|
123
|
+
if (hasIntl()) return dateFormat(locale, { month: "short" }, timeZone).format(date);
|
|
124
|
+
return MONTHS_SHORT[date.getMonth()]!;
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
/** `{ month: "short", year: "numeric" }` — "Jul 2026", without parsing a localized day.
|
|
122
128
|
* Like the other date helpers, an engine without Intl keeps the documented en-US fallback. */
|
|
123
129
|
export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
|
|
@@ -76,6 +76,19 @@ export function readSelectedSite(): SelectedSite | null {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** The id of the business last picked in this app's storage, with no check of who picked it.
|
|
80
|
+
* For a question that names a business and nothing else (is it one of this owner's Spaces?),
|
|
81
|
+
* where a wrong id costs a "no"; never for a name or for data shown on screen, which is what
|
|
82
|
+
* `readSelectedSite` guards. */
|
|
83
|
+
export function pickedSiteId(): string {
|
|
84
|
+
try {
|
|
85
|
+
const parsed = JSON.parse(host()?.storage?.getItem(KEY) || "null") as { id?: unknown } | null;
|
|
86
|
+
return typeof parsed?.id === "string" ? parsed.id.trim() : "";
|
|
87
|
+
} catch {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
79
92
|
/** Record the business the owner just picked. Best-effort: a host without storage
|
|
80
93
|
* simply keeps showing the fallback. */
|
|
81
94
|
export function rememberSelectedSite(site: SelectedSite): void {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// The Bookings Agenda's calendar rules: which days a page dims and dots, which days it reads, and where the selection
|
|
2
|
+
// goes when the calendar pages. Shared by the Agenda screen and the class calendar section a page shows inline, so the
|
|
3
|
+
// two calendars behave the same.
|
|
4
|
+
import { addDays, dayKey, toDate, weekOf, type DayDecoration, type Weekday } from "@himalaya/time";
|
|
5
|
+
import type { Session } from "./booking-session.js";
|
|
6
|
+
|
|
7
|
+
/** How far past the selected day the list reaches. */
|
|
8
|
+
export const AGENDA_DAYS = 28;
|
|
9
|
+
|
|
10
|
+
/** The first and last cell any month grid of `day`'s month can have, padding included. */
|
|
11
|
+
function monthGrid(day: string): { start: string; end: string } {
|
|
12
|
+
const d = toDate(day);
|
|
13
|
+
if (!d) return { start: day, end: day };
|
|
14
|
+
return { start: dayKey(new Date(d.getFullYear(), d.getMonth(), 1 - 6)), end: dayKey(new Date(d.getFullYear(), d.getMonth() + 1, 6)) };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** One dot per day that has a session — "something is on", not how much — and the visible
|
|
18
|
+
* days before today dimmed and unselectable: the agenda is what is still to come. */
|
|
19
|
+
export function decorationsOf(sessions: Session[], today: string, rangeStart: string, rangeEnd: string): DayDecoration[] {
|
|
20
|
+
const out: DayDecoration[] = [];
|
|
21
|
+
const dimmed = new Set<string>();
|
|
22
|
+
const dim = (from: string, to: string) => {
|
|
23
|
+
for (let day = from; day && day < today && day <= to; day = dayKey(addDays(day, 1))) {
|
|
24
|
+
if (!dimmed.has(day)) { dimmed.add(day); out.push({ date: day, disabled: true }); }
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
// Bounded by the visible days: a page a year back dims its 7-42 cells, not a year.
|
|
28
|
+
dim(rangeStart, rangeEnd);
|
|
29
|
+
// And this month's grid: an older binary (no week mode) draws it on first open, while it
|
|
30
|
+
// reports nothing until the member pages.
|
|
31
|
+
dim(monthGrid(today).start, today);
|
|
32
|
+
for (const date of [...new Set(sessions.filter((s) => s.day >= today).map((s) => s.day))].sort()) out.push({ date, dotCount: 1 });
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The days to load: the visible days (never before today) through AGENDA_DAYS past the
|
|
37
|
+
* selected day, so the list under the calendar always has its full reach. */
|
|
38
|
+
export function windowFor(today: string, rangeStart: string, rangeEnd: string, selected: string): { start: string; end: string } {
|
|
39
|
+
const start = rangeStart > today ? rangeStart : today;
|
|
40
|
+
const from = selected > today ? selected : today;
|
|
41
|
+
// Through the last cell of the selected day's month grid as well, which is what an older
|
|
42
|
+
// binary draws before it has reported any page: every dot on it is then real.
|
|
43
|
+
const end = [rangeEnd, dayKey(addDays(from, AGENDA_DAYS)), monthGrid(from).end].reduce((a, b) => (b > a ? b : a));
|
|
44
|
+
return { start, end };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Where the selection goes when the calendar pages away from it: the first day of the
|
|
48
|
+
* page (the 1st of the titled month in month view — the grid's first cell is padding),
|
|
49
|
+
* or today when that is on the page. A page wholly before today has no day to select (past
|
|
50
|
+
* days are disabled), so `current` stays selected and the list keeps showing from it. */
|
|
51
|
+
export function selectionForRange(today: string, rangeStart: string, rangeEnd: string, current = today): string {
|
|
52
|
+
const { first, last } = titledDays(rangeStart, rangeEnd);
|
|
53
|
+
if (today >= first && today <= last) return today;
|
|
54
|
+
return last < today ? current : first;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The days a page is about: the whole week, or a month grid's TITLED month — its padding cells
|
|
58
|
+
* belong to the neighbouring months. */
|
|
59
|
+
export function titledDays(rangeStart: string, rangeEnd: string): { first: string; last: string } {
|
|
60
|
+
let first = rangeStart;
|
|
61
|
+
let last = rangeEnd;
|
|
62
|
+
const span = Math.round((Date.parse(rangeEnd) - Date.parse(rangeStart)) / 86_400_000);
|
|
63
|
+
if (span > 7) {
|
|
64
|
+
// A month grid: its padding cells belong to the neighbouring months. Today counts only when
|
|
65
|
+
// it is in the TITLED month — a today in the trailing padding would move the selection, and
|
|
66
|
+
// with it the grid, a month forward.
|
|
67
|
+
const d = toDate(rangeStart);
|
|
68
|
+
if (d) {
|
|
69
|
+
const month = rangeStart.endsWith("-01") ? d : new Date(d.getFullYear(), d.getMonth() + 1, 1);
|
|
70
|
+
first = dayKey(month);
|
|
71
|
+
last = dayKey(new Date(month.getFullYear(), month.getMonth() + 1, 0));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { first, last };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The month grid (whole weeks) of `day`'s month, as a calendar draws it. */
|
|
78
|
+
export function monthGridOf(day: string, firstWeekday: number): { start: string; end: string } | undefined {
|
|
79
|
+
const d = toDate(day);
|
|
80
|
+
if (!d) return undefined;
|
|
81
|
+
const fw = (((firstWeekday % 7) + 7) % 7) as Weekday;
|
|
82
|
+
const start = weekOf(new Date(d.getFullYear(), d.getMonth(), 1), fw)[0];
|
|
83
|
+
const end = weekOf(new Date(d.getFullYear(), d.getMonth() + 1, 0), fw)[6];
|
|
84
|
+
return start && end ? { start, end } : undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Does the selection survive a page change? Inside the page's TITLED days, yes — a selection in a
|
|
88
|
+
* month grid's padding belongs to the neighbouring month. Today stays selected on any page that
|
|
89
|
+
* shows it: opening a week that straddles two months into the month holding most of it must not
|
|
90
|
+
* move the agenda off today. */
|
|
91
|
+
export function keepsSelection(cur: { today: string; selectedDate: string }, start: string, end: string): boolean {
|
|
92
|
+
const page = titledDays(start, end);
|
|
93
|
+
if (cur.selectedDate >= page.first && cur.selectedDate <= page.last) return true;
|
|
94
|
+
return !!cur.today && cur.selectedDate === cur.today && cur.today >= start && cur.today <= end;
|
|
95
|
+
}
|
|
@@ -138,6 +138,16 @@ export function bySession(found: Map<string, MemberPlace>, inWindow: Session[]):
|
|
|
138
138
|
return out;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/** "1 hr", "45 min", "1 hr 30 min" — the length under a session's time (the Agenda row, the class calendar section). */
|
|
142
|
+
export function lengthLabel(start: string, end: string): string {
|
|
143
|
+
const mins = Math.round((Date.parse(end) - Date.parse(start)) / 60_000);
|
|
144
|
+
if (!Number.isFinite(mins) || mins <= 0) return "";
|
|
145
|
+
const h = Math.floor(mins / 60), m = mins % 60;
|
|
146
|
+
return h && m
|
|
147
|
+
? copyTemplate("agenda.lengthHoursMinutes", "{h} hr {m} min", { h, m })
|
|
148
|
+
: h ? copyTemplate("agenda.lengthHours", "{h} hr", { h }) : copyTemplate("agenda.lengthMinutes", "{m} min", { m });
|
|
149
|
+
}
|
|
150
|
+
|
|
141
151
|
/** "4 spots left", "1 spot left", or "Full". Empty when the site reports no capacity, and for a
|
|
142
152
|
* course: a session's open spots do not say whether the course has room. */
|
|
143
153
|
export function spotsLabel(s: Session): string {
|