@wix/himalaya-cli 0.1777.0 → 0.1779.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/ts/src/webview-embedded.d.ts +8 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +5 -0
- package/dist/cli.mjs +1322 -154
- package/guides/himi-test.md +57 -0
- package/guides/one-app-section-mappings.md +5 -8
- package/guides/one-app-to-himi-app.md +21 -7
- package/guides/release-notes.md +15 -0
- package/package.json +2 -2
- package/templates/beauty-salon/l10n/ar.json +5 -0
- package/templates/beauty-salon/l10n/cs.json +5 -0
- package/templates/beauty-salon/l10n/da.json +5 -0
- package/templates/beauty-salon/l10n/de.json +5 -0
- package/templates/beauty-salon/l10n/el.json +5 -0
- package/templates/beauty-salon/l10n/es.json +5 -0
- package/templates/beauty-salon/l10n/fi.json +5 -0
- package/templates/beauty-salon/l10n/fr.json +5 -0
- package/templates/beauty-salon/l10n/he.json +4 -0
- package/templates/beauty-salon/l10n/hu.json +5 -0
- package/templates/beauty-salon/l10n/id.json +5 -0
- package/templates/beauty-salon/l10n/it.json +5 -0
- package/templates/beauty-salon/l10n/ja.json +5 -0
- package/templates/beauty-salon/l10n/ko.json +5 -0
- package/templates/beauty-salon/l10n/lt.json +5 -0
- package/templates/beauty-salon/l10n/nl.json +5 -0
- package/templates/beauty-salon/l10n/no.json +5 -0
- package/templates/beauty-salon/l10n/pl.json +5 -0
- package/templates/beauty-salon/l10n/pt.json +5 -0
- package/templates/beauty-salon/l10n/ru.json +5 -0
- package/templates/beauty-salon/l10n/sv.json +5 -0
- package/templates/beauty-salon/l10n/th.json +5 -0
- package/templates/beauty-salon/l10n/tr.json +5 -0
- package/templates/beauty-salon/l10n/uk.json +5 -0
- package/templates/beauty-salon/l10n/vi.json +5 -0
- package/templates/beauty-salon/l10n/zh.json +5 -0
- package/templates/beauty-salon/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/branded-lite/l10n/ar.json +15 -0
- package/templates/branded-lite/l10n/cs.json +15 -0
- package/templates/branded-lite/l10n/da.json +15 -0
- package/templates/branded-lite/l10n/de.json +15 -0
- package/templates/branded-lite/l10n/el.json +15 -0
- package/templates/branded-lite/l10n/es.json +15 -0
- package/templates/branded-lite/l10n/fi.json +15 -0
- package/templates/branded-lite/l10n/fr.json +15 -0
- package/templates/branded-lite/l10n/he.json +12 -0
- package/templates/branded-lite/l10n/hu.json +15 -0
- package/templates/branded-lite/l10n/id.json +15 -0
- package/templates/branded-lite/l10n/it.json +15 -0
- package/templates/branded-lite/l10n/ja.json +15 -0
- package/templates/branded-lite/l10n/ko.json +15 -0
- package/templates/branded-lite/l10n/lt.json +15 -0
- package/templates/branded-lite/l10n/nl.json +15 -0
- package/templates/branded-lite/l10n/no.json +15 -0
- package/templates/branded-lite/l10n/pl.json +15 -0
- package/templates/branded-lite/l10n/pt.json +15 -0
- package/templates/branded-lite/l10n/ru.json +15 -0
- package/templates/branded-lite/l10n/sv.json +15 -0
- package/templates/branded-lite/l10n/th.json +15 -0
- package/templates/branded-lite/l10n/tr.json +15 -0
- package/templates/branded-lite/l10n/uk.json +15 -0
- package/templates/branded-lite/l10n/vi.json +15 -0
- package/templates/branded-lite/l10n/zh.json +15 -0
- package/templates/branded-lite/recipes/blog-categories.json +115 -0
- package/templates/branded-lite/recipes/event-schedule.json +114 -0
- package/templates/branded-lite/recipes/groups-newsfeed.json +245 -0
- package/templates/branded-lite/recipes/loyalty-offering.json +241 -0
- package/templates/branded-lite/recipes/loyalty-status.json +173 -0
- package/templates/branded-lite/recipes/members-carousel.json +144 -0
- package/templates/branded-lite/recipes/performance-tracker.json +325 -0
- package/templates/branded-lite/recipes/podcasts-widget.json +280 -0
- package/templates/branded-lite/recipes/products-search-bar.json +139 -0
- package/templates/branded-lite/recipes/wishlist-grid.json +236 -0
- package/templates/branded-lite/tier5-src/_shared/blog-categories.ts +62 -0
- package/templates/branded-lite/tier5-src/_shared/event-agenda.ts +122 -0
- package/templates/branded-lite/tier5-src/_shared/event-schedule-section.ts +91 -0
- package/templates/branded-lite/tier5-src/_shared/group-feed-section.ts +2 -2
- package/templates/branded-lite/tier5-src/_shared/groups-newsfeed-section.ts +105 -0
- package/templates/branded-lite/tier5-src/_shared/loyalty-offering-section.ts +88 -0
- package/templates/branded-lite/tier5-src/_shared/loyalty-status-section.ts +88 -0
- package/templates/branded-lite/tier5-src/_shared/members-directory.ts +9 -3
- package/templates/branded-lite/tier5-src/_shared/performance-tracker-section.ts +120 -0
- package/templates/branded-lite/tier5-src/_shared/performance-tracker-weeks.ts +71 -0
- package/templates/branded-lite/tier5-src/_shared/podcast-section.ts +131 -0
- package/templates/branded-lite/tier5-src/_shared/saved-products-section.ts +64 -0
- package/templates/branded-lite/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/community-club/l10n/ar.json +5 -0
- package/templates/community-club/l10n/cs.json +5 -0
- package/templates/community-club/l10n/da.json +5 -0
- package/templates/community-club/l10n/de.json +5 -0
- package/templates/community-club/l10n/el.json +5 -0
- package/templates/community-club/l10n/es.json +5 -0
- package/templates/community-club/l10n/fi.json +5 -0
- package/templates/community-club/l10n/fr.json +5 -0
- package/templates/community-club/l10n/he.json +4 -0
- package/templates/community-club/l10n/hu.json +5 -0
- package/templates/community-club/l10n/id.json +5 -0
- package/templates/community-club/l10n/it.json +5 -0
- package/templates/community-club/l10n/ja.json +5 -0
- package/templates/community-club/l10n/ko.json +5 -0
- package/templates/community-club/l10n/lt.json +5 -0
- package/templates/community-club/l10n/nl.json +5 -0
- package/templates/community-club/l10n/no.json +5 -0
- package/templates/community-club/l10n/pl.json +5 -0
- package/templates/community-club/l10n/pt.json +5 -0
- package/templates/community-club/l10n/ru.json +5 -0
- package/templates/community-club/l10n/sv.json +5 -0
- package/templates/community-club/l10n/th.json +5 -0
- package/templates/community-club/l10n/tr.json +5 -0
- package/templates/community-club/l10n/uk.json +5 -0
- package/templates/community-club/l10n/vi.json +5 -0
- package/templates/community-club/l10n/zh.json +5 -0
- package/templates/community-club/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/events-meetups/l10n/ar.json +5 -0
- package/templates/events-meetups/l10n/cs.json +5 -0
- package/templates/events-meetups/l10n/da.json +5 -0
- package/templates/events-meetups/l10n/de.json +5 -0
- package/templates/events-meetups/l10n/el.json +5 -0
- package/templates/events-meetups/l10n/es.json +5 -0
- package/templates/events-meetups/l10n/fi.json +5 -0
- package/templates/events-meetups/l10n/fr.json +5 -0
- package/templates/events-meetups/l10n/he.json +4 -0
- package/templates/events-meetups/l10n/hu.json +5 -0
- package/templates/events-meetups/l10n/id.json +5 -0
- package/templates/events-meetups/l10n/it.json +5 -0
- package/templates/events-meetups/l10n/ja.json +5 -0
- package/templates/events-meetups/l10n/ko.json +5 -0
- package/templates/events-meetups/l10n/lt.json +5 -0
- package/templates/events-meetups/l10n/nl.json +5 -0
- package/templates/events-meetups/l10n/no.json +5 -0
- package/templates/events-meetups/l10n/pl.json +5 -0
- package/templates/events-meetups/l10n/pt.json +5 -0
- package/templates/events-meetups/l10n/ru.json +5 -0
- package/templates/events-meetups/l10n/sv.json +5 -0
- package/templates/events-meetups/l10n/th.json +5 -0
- package/templates/events-meetups/l10n/tr.json +5 -0
- package/templates/events-meetups/l10n/uk.json +5 -0
- package/templates/events-meetups/l10n/vi.json +5 -0
- package/templates/events-meetups/l10n/zh.json +5 -0
- package/templates/events-meetups/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/fitness-gym/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/gym-fitness/l10n/ar.json +5 -0
- package/templates/gym-fitness/l10n/cs.json +5 -0
- package/templates/gym-fitness/l10n/da.json +5 -0
- package/templates/gym-fitness/l10n/de.json +5 -0
- package/templates/gym-fitness/l10n/el.json +5 -0
- package/templates/gym-fitness/l10n/es.json +5 -0
- package/templates/gym-fitness/l10n/fi.json +5 -0
- package/templates/gym-fitness/l10n/fr.json +5 -0
- package/templates/gym-fitness/l10n/he.json +4 -0
- package/templates/gym-fitness/l10n/hu.json +5 -0
- package/templates/gym-fitness/l10n/id.json +5 -0
- package/templates/gym-fitness/l10n/it.json +5 -0
- package/templates/gym-fitness/l10n/ja.json +5 -0
- package/templates/gym-fitness/l10n/ko.json +5 -0
- package/templates/gym-fitness/l10n/lt.json +5 -0
- package/templates/gym-fitness/l10n/nl.json +5 -0
- package/templates/gym-fitness/l10n/no.json +5 -0
- package/templates/gym-fitness/l10n/pl.json +5 -0
- package/templates/gym-fitness/l10n/pt.json +5 -0
- package/templates/gym-fitness/l10n/ru.json +5 -0
- package/templates/gym-fitness/l10n/sv.json +5 -0
- package/templates/gym-fitness/l10n/th.json +5 -0
- package/templates/gym-fitness/l10n/tr.json +5 -0
- package/templates/gym-fitness/l10n/uk.json +5 -0
- package/templates/gym-fitness/l10n/vi.json +5 -0
- package/templates/gym-fitness/l10n/zh.json +5 -0
- package/templates/gym-fitness/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/medical-services/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/nonprofit-cause/l10n/ar.json +5 -0
- package/templates/nonprofit-cause/l10n/cs.json +5 -0
- package/templates/nonprofit-cause/l10n/da.json +5 -0
- package/templates/nonprofit-cause/l10n/de.json +5 -0
- package/templates/nonprofit-cause/l10n/el.json +5 -0
- package/templates/nonprofit-cause/l10n/es.json +5 -0
- package/templates/nonprofit-cause/l10n/fi.json +5 -0
- package/templates/nonprofit-cause/l10n/fr.json +5 -0
- package/templates/nonprofit-cause/l10n/he.json +4 -0
- package/templates/nonprofit-cause/l10n/hu.json +5 -0
- package/templates/nonprofit-cause/l10n/id.json +5 -0
- package/templates/nonprofit-cause/l10n/it.json +5 -0
- package/templates/nonprofit-cause/l10n/ja.json +5 -0
- package/templates/nonprofit-cause/l10n/ko.json +5 -0
- package/templates/nonprofit-cause/l10n/lt.json +5 -0
- package/templates/nonprofit-cause/l10n/nl.json +5 -0
- package/templates/nonprofit-cause/l10n/no.json +5 -0
- package/templates/nonprofit-cause/l10n/pl.json +5 -0
- package/templates/nonprofit-cause/l10n/pt.json +5 -0
- package/templates/nonprofit-cause/l10n/ru.json +5 -0
- package/templates/nonprofit-cause/l10n/sv.json +5 -0
- package/templates/nonprofit-cause/l10n/th.json +5 -0
- package/templates/nonprofit-cause/l10n/tr.json +5 -0
- package/templates/nonprofit-cause/l10n/uk.json +5 -0
- package/templates/nonprofit-cause/l10n/vi.json +5 -0
- package/templates/nonprofit-cause/l10n/zh.json +5 -0
- package/templates/nonprofit-cause/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/personal-fitness-trainer/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/podcast-creator/l10n/ar.json +5 -0
- package/templates/podcast-creator/l10n/cs.json +5 -0
- package/templates/podcast-creator/l10n/da.json +5 -0
- package/templates/podcast-creator/l10n/de.json +5 -0
- package/templates/podcast-creator/l10n/el.json +5 -0
- package/templates/podcast-creator/l10n/es.json +5 -0
- package/templates/podcast-creator/l10n/fi.json +5 -0
- package/templates/podcast-creator/l10n/fr.json +5 -0
- package/templates/podcast-creator/l10n/he.json +4 -0
- package/templates/podcast-creator/l10n/hu.json +5 -0
- package/templates/podcast-creator/l10n/id.json +5 -0
- package/templates/podcast-creator/l10n/it.json +5 -0
- package/templates/podcast-creator/l10n/ja.json +5 -0
- package/templates/podcast-creator/l10n/ko.json +5 -0
- package/templates/podcast-creator/l10n/lt.json +5 -0
- package/templates/podcast-creator/l10n/nl.json +5 -0
- package/templates/podcast-creator/l10n/no.json +5 -0
- package/templates/podcast-creator/l10n/pl.json +5 -0
- package/templates/podcast-creator/l10n/pt.json +5 -0
- package/templates/podcast-creator/l10n/ru.json +5 -0
- package/templates/podcast-creator/l10n/sv.json +5 -0
- package/templates/podcast-creator/l10n/th.json +5 -0
- package/templates/podcast-creator/l10n/tr.json +5 -0
- package/templates/podcast-creator/l10n/uk.json +5 -0
- package/templates/podcast-creator/l10n/vi.json +5 -0
- package/templates/podcast-creator/l10n/zh.json +5 -0
- package/templates/podcast-creator/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/portfolio-creative/l10n/ar.json +5 -0
- package/templates/portfolio-creative/l10n/cs.json +5 -0
- package/templates/portfolio-creative/l10n/da.json +5 -0
- package/templates/portfolio-creative/l10n/de.json +5 -0
- package/templates/portfolio-creative/l10n/el.json +5 -0
- package/templates/portfolio-creative/l10n/es.json +5 -0
- package/templates/portfolio-creative/l10n/fi.json +5 -0
- package/templates/portfolio-creative/l10n/fr.json +5 -0
- package/templates/portfolio-creative/l10n/he.json +4 -0
- package/templates/portfolio-creative/l10n/hu.json +5 -0
- package/templates/portfolio-creative/l10n/id.json +5 -0
- package/templates/portfolio-creative/l10n/it.json +5 -0
- package/templates/portfolio-creative/l10n/ja.json +5 -0
- package/templates/portfolio-creative/l10n/ko.json +5 -0
- package/templates/portfolio-creative/l10n/lt.json +5 -0
- package/templates/portfolio-creative/l10n/nl.json +5 -0
- package/templates/portfolio-creative/l10n/no.json +5 -0
- package/templates/portfolio-creative/l10n/pl.json +5 -0
- package/templates/portfolio-creative/l10n/pt.json +5 -0
- package/templates/portfolio-creative/l10n/ru.json +5 -0
- package/templates/portfolio-creative/l10n/sv.json +5 -0
- package/templates/portfolio-creative/l10n/th.json +5 -0
- package/templates/portfolio-creative/l10n/tr.json +5 -0
- package/templates/portfolio-creative/l10n/uk.json +5 -0
- package/templates/portfolio-creative/l10n/vi.json +5 -0
- package/templates/portfolio-creative/l10n/zh.json +5 -0
- package/templates/portfolio-creative/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/restaurant/l10n/ar.json +5 -0
- package/templates/restaurant/l10n/cs.json +5 -0
- package/templates/restaurant/l10n/da.json +5 -0
- package/templates/restaurant/l10n/de.json +5 -0
- package/templates/restaurant/l10n/el.json +5 -0
- package/templates/restaurant/l10n/es.json +5 -0
- package/templates/restaurant/l10n/fi.json +5 -0
- package/templates/restaurant/l10n/fr.json +5 -0
- package/templates/restaurant/l10n/he.json +4 -0
- package/templates/restaurant/l10n/hu.json +5 -0
- package/templates/restaurant/l10n/id.json +5 -0
- package/templates/restaurant/l10n/it.json +5 -0
- package/templates/restaurant/l10n/ja.json +5 -0
- package/templates/restaurant/l10n/ko.json +5 -0
- package/templates/restaurant/l10n/lt.json +5 -0
- package/templates/restaurant/l10n/nl.json +5 -0
- package/templates/restaurant/l10n/no.json +5 -0
- package/templates/restaurant/l10n/pl.json +5 -0
- package/templates/restaurant/l10n/pt.json +5 -0
- package/templates/restaurant/l10n/ru.json +5 -0
- package/templates/restaurant/l10n/sv.json +5 -0
- package/templates/restaurant/l10n/th.json +5 -0
- package/templates/restaurant/l10n/tr.json +5 -0
- package/templates/restaurant/l10n/uk.json +5 -0
- package/templates/restaurant/l10n/vi.json +5 -0
- package/templates/restaurant/l10n/zh.json +5 -0
- package/templates/restaurant/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/retail-store/l10n/ar.json +5 -0
- package/templates/retail-store/l10n/cs.json +5 -0
- package/templates/retail-store/l10n/da.json +5 -0
- package/templates/retail-store/l10n/de.json +5 -0
- package/templates/retail-store/l10n/el.json +5 -0
- package/templates/retail-store/l10n/es.json +5 -0
- package/templates/retail-store/l10n/fi.json +5 -0
- package/templates/retail-store/l10n/fr.json +5 -0
- package/templates/retail-store/l10n/he.json +4 -0
- package/templates/retail-store/l10n/hu.json +5 -0
- package/templates/retail-store/l10n/id.json +5 -0
- package/templates/retail-store/l10n/it.json +5 -0
- package/templates/retail-store/l10n/ja.json +5 -0
- package/templates/retail-store/l10n/ko.json +5 -0
- package/templates/retail-store/l10n/lt.json +5 -0
- package/templates/retail-store/l10n/nl.json +5 -0
- package/templates/retail-store/l10n/no.json +5 -0
- package/templates/retail-store/l10n/pl.json +5 -0
- package/templates/retail-store/l10n/pt.json +5 -0
- package/templates/retail-store/l10n/ru.json +5 -0
- package/templates/retail-store/l10n/sv.json +5 -0
- package/templates/retail-store/l10n/th.json +5 -0
- package/templates/retail-store/l10n/tr.json +5 -0
- package/templates/retail-store/l10n/uk.json +5 -0
- package/templates/retail-store/l10n/vi.json +5 -0
- package/templates/retail-store/l10n/zh.json +5 -0
- package/templates/retail-store/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/salon-spa/tier5-src/_shared/weekly-goal.ts +7 -3
- package/templates/yoga-studio/l10n/ar.json +5 -0
- package/templates/yoga-studio/l10n/cs.json +5 -0
- package/templates/yoga-studio/l10n/da.json +5 -0
- package/templates/yoga-studio/l10n/de.json +5 -0
- package/templates/yoga-studio/l10n/el.json +5 -0
- package/templates/yoga-studio/l10n/es.json +5 -0
- package/templates/yoga-studio/l10n/fi.json +5 -0
- package/templates/yoga-studio/l10n/fr.json +5 -0
- package/templates/yoga-studio/l10n/he.json +4 -0
- package/templates/yoga-studio/l10n/hu.json +5 -0
- package/templates/yoga-studio/l10n/id.json +5 -0
- package/templates/yoga-studio/l10n/it.json +5 -0
- package/templates/yoga-studio/l10n/ja.json +5 -0
- package/templates/yoga-studio/l10n/ko.json +5 -0
- package/templates/yoga-studio/l10n/lt.json +5 -0
- package/templates/yoga-studio/l10n/nl.json +5 -0
- package/templates/yoga-studio/l10n/no.json +5 -0
- package/templates/yoga-studio/l10n/pl.json +5 -0
- package/templates/yoga-studio/l10n/pt.json +5 -0
- package/templates/yoga-studio/l10n/ru.json +5 -0
- package/templates/yoga-studio/l10n/sv.json +5 -0
- package/templates/yoga-studio/l10n/th.json +5 -0
- package/templates/yoga-studio/l10n/tr.json +5 -0
- package/templates/yoga-studio/l10n/uk.json +5 -0
- package/templates/yoga-studio/l10n/vi.json +5 -0
- package/templates/yoga-studio/l10n/zh.json +5 -0
- package/templates/yoga-studio/tier5-src/_shared/weekly-goal.ts +7 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// A page's groups newsfeed (`groups_feed_section`) as a registrable service: the latest posts across the site's public groups, newest first.
|
|
2
|
+
// groupIds -> only those groups (unset: every public group the site publishes),
|
|
3
|
+
// limit -> at most N posts in all (the source's "postNumber").
|
|
4
|
+
// It is the single-group feed (group-feed-section.ts) read for several groups and merged: the same post rows, and the same rule that a group
|
|
5
|
+
// which is not public is never read, so no post of a private group reaches the page. A public group whose feed Wix refuses the viewer
|
|
6
|
+
// (401/403: the feed read is a member scope) adds nothing; when every group refuses, the section says posts are for members.
|
|
7
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe groups-newsfeed.json).
|
|
8
|
+
import { defineService } from "@himalaya/state";
|
|
9
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
10
|
+
import { memberAccess } from "./member-access.js";
|
|
11
|
+
import { queryGroups, type WixGroup } from "@himalaya/wix-groups";
|
|
12
|
+
import { listFeedItems } from "@himalaya/wix-social-feed";
|
|
13
|
+
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
14
|
+
import { isRefusal, postRow, type GroupFeedRow } from "./group-feed-section.js";
|
|
15
|
+
|
|
16
|
+
export interface GroupsNewsfeedOptions {
|
|
17
|
+
/** Show only these groups' posts. */
|
|
18
|
+
groupIds?: string[];
|
|
19
|
+
/** Show at most this many posts. */
|
|
20
|
+
limit?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface NewsfeedRow extends GroupFeedRow {
|
|
24
|
+
/** The group the post is in: the row names it and opens it. */
|
|
25
|
+
groupId: string; groupName: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GroupsNewsfeedState {
|
|
29
|
+
status: "loading" | "ready" | "error";
|
|
30
|
+
rows: NewsfeedRow[];
|
|
31
|
+
/** Why the posts are not shown ("" when they are): every group's feed refused the viewer. */
|
|
32
|
+
restrictedText: string;
|
|
33
|
+
emptyText: string;
|
|
34
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean; noEmpty: boolean; noRestricted: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The most posts one section reads, as the single-group feed. */
|
|
38
|
+
const MAX_POSTS = 20;
|
|
39
|
+
/** The most groups whose feed one section reads: one read each, so a site with many groups is cut here and the section says so. */
|
|
40
|
+
export const NEWSFEED_GROUPS_MAX = 5;
|
|
41
|
+
const GROUP_PAGE = 100;
|
|
42
|
+
|
|
43
|
+
/** A group the viewer may read the posts of: the group screen lets anyone join only a public group (an unknown status counts as public there too). */
|
|
44
|
+
const isPublic = (group: WixGroup): boolean => { const kind = (group.privacyStatus || "UNKNOWN").toLowerCase(); return kind === "public" || kind === "unknown"; };
|
|
45
|
+
|
|
46
|
+
export function registerGroupsNewsfeedSection(serviceName: string, options: GroupsNewsfeedOptions = {}) {
|
|
47
|
+
const view = (status: GroupsNewsfeedState["status"], parts: { rows?: NewsfeedRow[]; restrictedText?: string } = {}): GroupsNewsfeedState => {
|
|
48
|
+
const rows = parts.rows ?? [], restrictedText = parts.restrictedText ?? "";
|
|
49
|
+
const empty = status === "ready" && !rows.length && !restrictedText;
|
|
50
|
+
return {
|
|
51
|
+
status, rows, restrictedText, emptyText: empty ? copyParam("feed.emptyText", "Nothing has been posted yet — start the conversation.") : "",
|
|
52
|
+
notLoading: status !== "loading", notErrored: status !== "error", noRows: !rows.length, noEmpty: !empty, noRestricted: !restrictedText,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const session = hostSessionFromGlobal();
|
|
56
|
+
// The viewer changed: the rows already published are the previous viewer's, so they go at once, before the read for the new one finishes.
|
|
57
|
+
const restart = () => { void service.clear(); void service.load(); };
|
|
58
|
+
// Only the newest load may answer, and only for the viewer who started it: a feed read for one member is never shown to the next.
|
|
59
|
+
let sequence = 0;
|
|
60
|
+
const service = defineService<GroupsNewsfeedState, { load: (state: GroupsNewsfeedState, arg?: unknown) => Promise<GroupsNewsfeedState | undefined>; clear: () => Promise<GroupsNewsfeedState> }>(serviceName, {
|
|
61
|
+
state: view("loading"),
|
|
62
|
+
// The posts are member-scoped: never written to disk and restored for the next person on the device.
|
|
63
|
+
notHydrated: Object.keys(view("loading")) as Array<keyof GroupsNewsfeedState>,
|
|
64
|
+
actions: {
|
|
65
|
+
clear: async () => view("loading"),
|
|
66
|
+
load: async (_state, arg) => {
|
|
67
|
+
stashCopy(arg);
|
|
68
|
+
const seq = ++sequence;
|
|
69
|
+
const viewer = await memberAccess();
|
|
70
|
+
const sameViewer = async () => { const now = await memberAccess(); return seq === sequence && now.email === viewer.email && now.scope === viewer.scope; };
|
|
71
|
+
try {
|
|
72
|
+
const response = await queryGroups({ paging: { limit: GROUP_PAGE, offset: 0 } });
|
|
73
|
+
const all = ((response.groups ?? []) as WixGroup[]).filter((group) => group.id);
|
|
74
|
+
const chosen = options.groupIds?.length ? options.groupIds.flatMap((id) => all.find((group) => group.id === id) ?? []) : all;
|
|
75
|
+
const groups = chosen.filter(isPublic).slice(0, NEWSFEED_GROUPS_MAX);
|
|
76
|
+
const limit = Math.min(options.limit ?? MAX_POSTS, MAX_POSTS);
|
|
77
|
+
const reads = await Promise.allSettled(groups.map((group) => listFeedItems(group.id, limit)));
|
|
78
|
+
if (!(await sameViewer())) { if (seq === sequence) restart(); return undefined; }
|
|
79
|
+
const now = Date.now(), posts: Array<{ row: NewsfeedRow; at: number }> = [];
|
|
80
|
+
let refused = 0, failed: unknown;
|
|
81
|
+
reads.forEach((read, i) => {
|
|
82
|
+
const group = groups[i]!, groupName = (group.name || copyParam("groups.groupFallbackName", "Group")).trim();
|
|
83
|
+
if (read.status === "rejected") { if (isRefusal(read.reason)) refused++; else failed = read.reason; return; }
|
|
84
|
+
const profiles = read.value.profiles ?? [];
|
|
85
|
+
for (const item of read.value.feedItems ?? []) {
|
|
86
|
+
if (item.feedItemId) posts.push({ row: { ...postRow(item, profiles, now), groupId: group.id, groupName }, at: Date.parse(String(item.created ?? item.createdAt ?? "")) || 0 });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
// A group whose feed failed for another reason hides the posts of the rest only when nothing else answered: one broken group does not blank the feed.
|
|
90
|
+
if (failed !== undefined && !posts.length) throw failed;
|
|
91
|
+
const rows = posts.sort((a, b) => b.at - a.at).slice(0, limit).map((post) => post.row);
|
|
92
|
+
const allRefused = !rows.length && groups.length > 0 && refused === groups.length;
|
|
93
|
+
return view("ready", { rows, restrictedText: allRefused ? copyParam("groupFeed.restrictedText", "Posts are shown to the group's members.") : "" });
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (seq !== sequence) return undefined;
|
|
96
|
+
console.warn("groups_newsfeed_section: the groups' posts could not be read", error);
|
|
97
|
+
return view("error");
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
// Signing in or out on another screen changes who the feed is read for.
|
|
103
|
+
session.subscribe(restart);
|
|
104
|
+
return service;
|
|
105
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// A page's loyalty offering (`loyalty_offering_section`) as a registrable service: what the rewards program offers, read from the public
|
|
2
|
+
// program, rewards, earning rules and tiers (no sign-in): one block per tier when the tiers program is on, else the base offering.
|
|
3
|
+
// It builds its rows with the same `buildOfferings` the Rewards screen uses, then flattens them (tier heading, "Ways to earn points",
|
|
4
|
+
// "Rewards", the items) into ONE list a descriptor can bind without nesting lists. The first OFFERING_TIER_LIMIT tiers show: the Rewards
|
|
5
|
+
// screen shows them all.
|
|
6
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe loyalty-offering.json).
|
|
7
|
+
import { defineService } from "@himalaya/state";
|
|
8
|
+
import { getLoyaltyProgram, getLoyaltyTiersProgram, listLoyaltyEarningRules, listLoyaltyRewards } from "@himalaya/wix-loyalty";
|
|
9
|
+
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
10
|
+
import { buildOfferings, visibleOfferings, type OfferingGroup } from "./loyalty-offerings.js";
|
|
11
|
+
|
|
12
|
+
export interface LoyaltyOfferingOptions {
|
|
13
|
+
/** The business's ISO currency, for the rules and rewards priced in money; none leaves those lines as "details unavailable". */
|
|
14
|
+
currency?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface OfferingListRow {
|
|
18
|
+
id: string; title: string; subtitle: string; meta: string;
|
|
19
|
+
isTier: boolean; isLabel: boolean; isItem: boolean; noTier: boolean; noLabel: boolean; noItem: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface LoyaltyOfferingState {
|
|
23
|
+
status: "loading" | "ready" | "error";
|
|
24
|
+
rows: OfferingListRow[];
|
|
25
|
+
/** "Rewards": the label of the button that opens the Rewards screen. */
|
|
26
|
+
viewLabel: string;
|
|
27
|
+
inactiveText: string; emptyText: string;
|
|
28
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean; noInactive: boolean; noEmpty: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const row = (id: string, parts: Partial<OfferingListRow>, kind: "tier" | "label" | "item"): OfferingListRow => ({
|
|
32
|
+
id, title: "", subtitle: "", meta: "", ...parts,
|
|
33
|
+
isTier: kind === "tier", isLabel: kind === "label", isItem: kind === "item", noTier: kind !== "tier", noLabel: kind !== "label", noItem: kind !== "item",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** The tiers' blocks as one flat list. A heading is only there when the block has what it heads. */
|
|
37
|
+
export function flattenOfferings(groups: OfferingGroup[]): OfferingListRow[] {
|
|
38
|
+
return groups.flatMap((group) => [
|
|
39
|
+
...(group.hideTitle ? [] : [row(`tier:${group.id}`, { title: group.name, subtitle: group.description, meta: group.threshold }, "tier")]),
|
|
40
|
+
...(group.hideEarning ? [] : [row(`earn-label:${group.id}`, { title: copyParam("loyalty.waysToEarn", "Ways to earn points") }, "label"),
|
|
41
|
+
...group.earningRules.map((rule) => row(`earn:${group.id}:${rule.id}`, { title: rule.name, subtitle: rule.subtitle }, "item"))]),
|
|
42
|
+
...(group.hideRewards ? [] : [row(`reward-label:${group.id}`, { title: copyParam("loyalty.rewardsHeading", "Rewards") }, "label"),
|
|
43
|
+
...group.rewards.map((reward) => row(`reward:${group.id}:${reward.id}`, { title: reward.name, subtitle: reward.subtitle }, "item"))]),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function registerLoyaltyOfferingSection(serviceName: string, options: LoyaltyOfferingOptions = {}) {
|
|
48
|
+
const view = (status: LoyaltyOfferingState["status"], parts: { rows?: OfferingListRow[]; inactiveText?: string } = {}): LoyaltyOfferingState => {
|
|
49
|
+
const rows = parts.rows ?? [], inactiveText = parts.inactiveText ?? "";
|
|
50
|
+
const empty = status === "ready" && !rows.length && !inactiveText;
|
|
51
|
+
return {
|
|
52
|
+
status, rows, viewLabel: copyParam("loyalty.viewRewards", "View rewards"), inactiveText,
|
|
53
|
+
emptyText: empty ? copyParam("loyalty.emptyText", "No rewards to redeem yet.") : "",
|
|
54
|
+
notLoading: status !== "loading", notErrored: status !== "error", noRows: !rows.length, noInactive: !inactiveText, noEmpty: !empty,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
// Only the newest load may answer.
|
|
58
|
+
let sequence = 0;
|
|
59
|
+
return defineService<LoyaltyOfferingState, { load: (state: LoyaltyOfferingState, arg?: unknown) => Promise<LoyaltyOfferingState | undefined> }>(serviceName, {
|
|
60
|
+
state: view("loading"),
|
|
61
|
+
// The offering is public, but its copy follows the app's language: it is read again each time the screen opens.
|
|
62
|
+
notHydrated: Object.keys(view("loading")) as Array<keyof LoyaltyOfferingState>,
|
|
63
|
+
actions: {
|
|
64
|
+
load: async (_state, arg) => {
|
|
65
|
+
stashCopy(arg);
|
|
66
|
+
const seq = ++sequence;
|
|
67
|
+
try {
|
|
68
|
+
const [program, rewards, rules, tiers] = await Promise.allSettled([getLoyaltyProgram(), listLoyaltyRewards(), listLoyaltyEarningRules(), getLoyaltyTiersProgram()]);
|
|
69
|
+
if (seq !== sequence) return undefined;
|
|
70
|
+
const source = program.status === "fulfilled" ? program.value.loyaltyProgram ?? program.value.program : undefined;
|
|
71
|
+
if (!source || !["ACTIVE", "DRAFT", "PAUSED"].includes(source.status ?? "")) throw new Error("Loyalty program response is unavailable");
|
|
72
|
+
if (source.status !== "ACTIVE" || source.premiumFeatures?.loyaltyProgram === false) return view("ready", { inactiveText: copyParam("loyalty.inactive", "The rewards program isn't available right now.") });
|
|
73
|
+
if (rewards.status === "rejected" && rules.status === "rejected") throw new Error("Loyalty catalog is unavailable");
|
|
74
|
+
// The program's own name for a point, or none: with none the label says "point" or "points" by the count.
|
|
75
|
+
const unit = (source.pointDefinition?.customName ?? "").trim();
|
|
76
|
+
const tiered = tiers.status === "fulfilled" && tiers.value.programSettings?.status === "ACTIVE" && source.premiumFeatures?.tiers !== false;
|
|
77
|
+
const groups = buildOfferings(tiered && tiers.status === "fulfilled" ? tiers.value : undefined, rewards.status === "fulfilled" ? rewards.value.rewards ?? [] : [],
|
|
78
|
+
rules.status === "fulfilled" ? rules.value.earningRules ?? [] : [], unit, options.currency ?? "");
|
|
79
|
+
return view("ready", { rows: flattenOfferings(visibleOfferings(groups, false)) });
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (seq !== sequence) return undefined;
|
|
82
|
+
console.warn("loyalty_offering_section: the rewards program could not be read", error);
|
|
83
|
+
return view("error");
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// A page's loyalty status (`loyalty_status_section`) as a registrable service: the signed-in member's points and tier, or a sign-in card for a
|
|
2
|
+
// visitor. The balance is private, so it is read only for a member whose identity the host proves (the same condition the Rewards screen
|
|
3
|
+
// applies), never written to disk, and dropped at once when the viewer changes. A read that fails is an error with its retry, never a
|
|
4
|
+
// guessed number.
|
|
5
|
+
// Not shown (the Rewards screen shows them): the points' expiry and the "Rewards available (N)" line, which need the member's coupons and
|
|
6
|
+
// referral rewards read beside the balance.
|
|
7
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe loyalty-status.json).
|
|
8
|
+
import { defineService } from "@himalaya/state";
|
|
9
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
10
|
+
import { getCurrentMemberLoyaltyAccount, getLoyaltyProgram, getLoyaltyTiersProgram, type WixLoyaltyTiersProgram } from "@himalaya/wix-loyalty";
|
|
11
|
+
import { assertMemberAccess, memberAccess } from "./member-access.js";
|
|
12
|
+
import { copyParam, copyTemplate, stashCopy } from "./himi-copy.js";
|
|
13
|
+
import { pointLabel } from "./loyalty-offerings.js";
|
|
14
|
+
|
|
15
|
+
export interface LoyaltyStatusState {
|
|
16
|
+
status: "loading" | "ready" | "error";
|
|
17
|
+
/** The card's heading and the visitor's sign-in card, as the Rewards screen words them. */
|
|
18
|
+
cardTitle: string; guestTitle: string; guestBody: string; signInLabel: string;
|
|
19
|
+
/** "1,250 points" and "Gold tier"; "" when unknown (the tiers program is off, or its read failed). */
|
|
20
|
+
points: string; tier: string;
|
|
21
|
+
/** Why there are no points to show ("" when there are): the rewards program is off, or the app cannot read them securely. */
|
|
22
|
+
message: string;
|
|
23
|
+
notLoading: boolean; notErrored: boolean; noGuest: boolean; noCard: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The member's tier name; "" when the tiers program is not ACTIVE or the tier is unknown. No tier id is the base tier, whose name is in the program settings. */
|
|
27
|
+
function tierName(tiers: WixLoyaltyTiersProgram | undefined, tierId: string | undefined): string {
|
|
28
|
+
if (tiers?.programSettings?.status !== "ACTIVE") return "";
|
|
29
|
+
if (!tierId) return (tiers.programSettings.baseTierDefinition?.name ?? "").trim();
|
|
30
|
+
return (tiers.tiers?.find((tier) => tier.id === tierId)?.tierDefinition?.name ?? "").trim();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function registerLoyaltyStatusSection(serviceName: string, _options: object = {}) {
|
|
34
|
+
const view = (status: LoyaltyStatusState["status"], parts: { guest?: boolean; points?: string; tier?: string; message?: string } = {}): LoyaltyStatusState => {
|
|
35
|
+
const guest = parts.guest === true, card = status === "ready" && !guest;
|
|
36
|
+
return {
|
|
37
|
+
status, cardTitle: copyParam("loyalty.myPoints", "My points"), guestTitle: copyParam("loyalty.signInTitle", "See your points"),
|
|
38
|
+
guestBody: copyParam("loyalty.signInBody", "Sign in to see your rewards balance."), signInLabel: copyParam("loyalty.signInCta", "Sign in"),
|
|
39
|
+
points: parts.points ?? "", tier: parts.tier ?? "", message: parts.message ?? "",
|
|
40
|
+
notLoading: status !== "loading", notErrored: status !== "error", noGuest: !(status === "ready" && guest), noCard: !card,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const session = hostSessionFromGlobal();
|
|
44
|
+
// The viewer changed: the points already published are the previous viewer's, so they go at once, before the read for the new one finishes.
|
|
45
|
+
const restart = () => { void service.clear(); void service.load(); };
|
|
46
|
+
let sequence = 0;
|
|
47
|
+
const service = defineService<LoyaltyStatusState, { load: (state: LoyaltyStatusState, arg?: unknown) => Promise<LoyaltyStatusState | undefined>; clear: () => Promise<LoyaltyStatusState> }>(serviceName, {
|
|
48
|
+
state: view("loading"),
|
|
49
|
+
// Points are member-scoped: never written to disk and restored for the next person on the device.
|
|
50
|
+
notHydrated: Object.keys(view("loading")) as Array<keyof LoyaltyStatusState>,
|
|
51
|
+
actions: {
|
|
52
|
+
clear: async () => view("loading"),
|
|
53
|
+
load: async (_state, arg) => {
|
|
54
|
+
stashCopy(arg);
|
|
55
|
+
const seq = ++sequence;
|
|
56
|
+
const member = await memberAccess();
|
|
57
|
+
if (seq !== sequence) return undefined;
|
|
58
|
+
if (!member.email) return view("ready", { guest: true });
|
|
59
|
+
// The same condition the Rewards screen applies before it reads a balance: a host that cannot prove the member to Wix reads none.
|
|
60
|
+
const supported = !!member.scope && ((globalThis as { himalaya?: { readLifecycleVersion?: number } }).himalaya?.readLifecycleVersion ?? 0) >= 1;
|
|
61
|
+
if (!supported) return view("ready", { message: copyParam("loyalty.updateApp", "Update the app to see your points securely.") });
|
|
62
|
+
try {
|
|
63
|
+
const [program, account, tiers] = await Promise.allSettled([getLoyaltyProgram(), getCurrentMemberLoyaltyAccount(), getLoyaltyTiersProgram()]);
|
|
64
|
+
await assertMemberAccess(member);
|
|
65
|
+
if (seq !== sequence) return undefined;
|
|
66
|
+
const source = program.status === "fulfilled" ? program.value.loyaltyProgram ?? program.value.program : undefined;
|
|
67
|
+
if (!source) throw new Error("Loyalty program response is unavailable");
|
|
68
|
+
if (source.status !== "ACTIVE" || source.premiumFeatures?.loyaltyProgram === false) return view("ready", { message: copyParam("loyalty.inactive", "The rewards program isn't available right now.") });
|
|
69
|
+
if (account.status === "rejected") throw account.reason;
|
|
70
|
+
const balance = account.value.account?.points?.balance;
|
|
71
|
+
if (typeof balance !== "number" || !Number.isFinite(balance)) return view("ready", { message: copyParam("loyalty.pointsUnavailable", "Your points aren't available yet.") });
|
|
72
|
+
const unit = (source.pointDefinition?.customName ?? "").trim();
|
|
73
|
+
const tier = tiers.status === "fulfilled" && source.premiumFeatures?.tiers !== false ? tierName(tiers.value, account.value.account?.tier?.id || undefined) : "";
|
|
74
|
+
return view("ready", { points: pointLabel(balance, unit), tier: tier ? copyTemplate("loyalty.memberTier", "{tier} tier", { tier }) : "" });
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (seq !== sequence) return undefined;
|
|
77
|
+
// The viewer changed while the read was out: the new viewer's load answers, not this one.
|
|
78
|
+
if ((error as Error | undefined)?.name === "MemberAccessChanged") { restart(); return undefined; }
|
|
79
|
+
console.warn("loyalty_status_section: the member's points could not be read", error);
|
|
80
|
+
return view("error");
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
// Signing in or out on another screen changes whose points the section shows.
|
|
86
|
+
session.subscribe(restart);
|
|
87
|
+
return service;
|
|
88
|
+
}
|
|
@@ -26,6 +26,8 @@ export interface MembersDirectoryOptions {
|
|
|
26
26
|
showFollow?: boolean;
|
|
27
27
|
/** A letter heading above each initial's group. Default on. */
|
|
28
28
|
letterBands?: boolean;
|
|
29
|
+
/** A horizontal rail (`member_horizontal_list_section`): no search or paging, the first `limit` members of the first page only. */
|
|
30
|
+
rail?: { limit: number; /** Keep only the members who hold a badge (the source's "members-with-badges"). */ onlyWithBadges?: boolean };
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/** A 40pt row avatar, at 3x: a Wix media reference becomes a fetchable, avatar-sized URL. */
|
|
@@ -65,7 +67,8 @@ function name(m: WixMember): string {
|
|
|
65
67
|
interface Extras { badges: Map<string, Chip[]>; following: Set<string> | undefined; /** "Active 4h ago" / "Last seen …" per member from the One App members service, and the members it answered for. */ activity: { texts: Map<string, string>; known: Set<string> } | undefined }
|
|
66
68
|
|
|
67
69
|
export function registerMembersDirectory(serviceName: string, options: MembersDirectoryOptions = {}) {
|
|
68
|
-
const
|
|
70
|
+
const rail = options.rail;
|
|
71
|
+
const letterBands = options.letterBands !== false && !rail;
|
|
69
72
|
let directoryAccess: ReadAccess | undefined;
|
|
70
73
|
// Set once the reader has typed a search: from then on the field stays mounted, even while a cleared search
|
|
71
74
|
// reloads the full directory (no rows, no query yet), so it never unmounts and loses focus mid-edit.
|
|
@@ -190,8 +193,11 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
|
|
|
190
193
|
signedIn = !!access.member.email;
|
|
191
194
|
const extras = await extrasFor(response.members, signedIn);
|
|
192
195
|
const now = Date.now();
|
|
196
|
+
const rows = response.members.map(member => row(member, extras, now));
|
|
197
|
+
// A rail shows the first few matching members of this one page: it never pages, and a badge filter cannot see past the page read.
|
|
198
|
+
if (rail) return { items: (rail.onlyWithBadges ? rows.filter(item => item.hasBadges) : rows).slice(0, rail.limit), total, nextCursor: "" };
|
|
193
199
|
return {
|
|
194
|
-
items:
|
|
200
|
+
items: rows, total,
|
|
195
201
|
nextCursor: response.members.length && (total === undefined ? response.members.length === PAGE_SIZE : next < total) ? String(next) : "",
|
|
196
202
|
};
|
|
197
203
|
},
|
|
@@ -217,7 +223,7 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
|
|
|
217
223
|
notLoading: !(loading && !page.items.length),
|
|
218
224
|
// A successful empty SEARCH keeps its field reachable (to clear the query); a directory that is
|
|
219
225
|
// loading or truly empty (no query, no rows) has nothing to search.
|
|
220
|
-
hideSearch: failed || (!page.items.length && !page.criteria.query && !searched),
|
|
226
|
+
hideSearch: !!rail || failed || (!page.items.length && !page.criteria.query && !searched),
|
|
221
227
|
actionMessage: notice,
|
|
222
228
|
};
|
|
223
229
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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 weekly streak and their all-time sessions. The source
|
|
3
|
+
// reads a private fitness service; this reads the same member-scoped bookings as My Bookings (himi_bookings) and counts with the
|
|
4
|
+
// same rule as its "This week" card (`weekly-goal.ts`: a CONFIRMED booking that already took place; Wix attendance is owner-scoped,
|
|
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`; its members may set their own, which a visitor cannot read),
|
|
7
|
+
// showTotal -> the all-time row (the source's `totalNumberOfSessions.show`).
|
|
8
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe performance-tracker.json).
|
|
9
|
+
import { defineService } from "@himalaya/state";
|
|
10
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
11
|
+
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
12
|
+
import { formatNumber } from "./engine-intl.js";
|
|
13
|
+
import { fetchMemberBookings } from "./member-bookings.js";
|
|
14
|
+
import { memberAccess, memberAccessDenied, memberChanged } from "./member-access.js";
|
|
15
|
+
import { parseWeeklyGoal, weeklyGoalProgress } from "./weekly-goal.js";
|
|
16
|
+
import { DEFAULT_WEEKLY_GOAL, MAX_ALL_TIME_SESSIONS, MAX_PAGES, allTimeSessions, sessionsInWeek, streakMayBeLonger, weekRange, weeklyStreak } from "./performance-tracker-weeks.js";
|
|
17
|
+
|
|
18
|
+
export interface PerformanceTrackerOptions {
|
|
19
|
+
/** The weekly session goal. Not a goal in [1, 21]: the source's default of 2. */
|
|
20
|
+
goal?: number;
|
|
21
|
+
/** Show the all-time sessions row (default true, as the source). */
|
|
22
|
+
showTotal?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PerformanceTrackerState {
|
|
26
|
+
status: "loading" | "ready" | "error";
|
|
27
|
+
/** A guest, or a member Wix refused: the section asks to sign in instead of reading. */
|
|
28
|
+
signedOut: boolean;
|
|
29
|
+
/** "Nov 16 – Nov 22". */
|
|
30
|
+
weekRange: string;
|
|
31
|
+
/** "1 of 2 sessions this week". */
|
|
32
|
+
goalLabel: string;
|
|
33
|
+
/** "1 more to reach your weekly goal". */
|
|
34
|
+
remainingLabel: string;
|
|
35
|
+
/** 0..1, the ring's fill. */
|
|
36
|
+
progress: number;
|
|
37
|
+
/** "1/2", inside the ring. */
|
|
38
|
+
ringText: string;
|
|
39
|
+
streak: string; streakLabel: string;
|
|
40
|
+
/** "500+" past the source's cap. */
|
|
41
|
+
total: string; totalLabel: string;
|
|
42
|
+
notLoading: boolean; notErrored: boolean; notSignedOut: boolean;
|
|
43
|
+
/** Nothing to show yet: loading, failed or signed out. */
|
|
44
|
+
noContent: boolean;
|
|
45
|
+
/** The all-time row is hidden: no content, or the source turned it off. */
|
|
46
|
+
noTotal: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function registerPerformanceTrackerSection(serviceName: string, options: PerformanceTrackerOptions = {}) {
|
|
50
|
+
const goal = parseWeeklyGoal(options.goal) || DEFAULT_WEEKLY_GOAL;
|
|
51
|
+
const showTotal = options.showTotal !== false;
|
|
52
|
+
const blank = { goalLabel: "", remainingLabel: "", progress: 0, ringText: "", streak: "", total: "" };
|
|
53
|
+
const view = (status: PerformanceTrackerState["status"], signedOut: boolean, fields: Partial<typeof blank> = {}, now?: number): PerformanceTrackerState => {
|
|
54
|
+
const noContent = !(status === "ready" && !signedOut);
|
|
55
|
+
return {
|
|
56
|
+
// No clock read at registration (a worker boots deterministically): the range is set by the load.
|
|
57
|
+
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
|
+
notLoading: status !== "loading", notErrored: status !== "error", notSignedOut: !signedOut,
|
|
61
|
+
noContent, noTotal: noContent || !showTotal,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const session = hostSessionFromGlobal();
|
|
65
|
+
// Only the newest load may answer: a guest read that finishes after the member signed in must not overwrite the member's progress.
|
|
66
|
+
let sequence = 0;
|
|
67
|
+
const initial = view("loading", false);
|
|
68
|
+
// The member changed: the progress already published is the previous member's, so it goes at once.
|
|
69
|
+
const restart = () => { void service.clear(); void service.load(); };
|
|
70
|
+
const service = defineService<PerformanceTrackerState, { load: (state: PerformanceTrackerState, arg?: unknown) => Promise<PerformanceTrackerState | undefined>; clear: () => Promise<PerformanceTrackerState> }>(serviceName, {
|
|
71
|
+
state: initial,
|
|
72
|
+
// 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 PerformanceTrackerState>,
|
|
74
|
+
actions: {
|
|
75
|
+
clear: async () => initial,
|
|
76
|
+
load: async (_state, arg) => {
|
|
77
|
+
stashCopy(arg);
|
|
78
|
+
const seq = ++sequence;
|
|
79
|
+
let member: Awaited<ReturnType<typeof memberAccess>> | undefined;
|
|
80
|
+
try {
|
|
81
|
+
member = await memberAccess();
|
|
82
|
+
if (seq !== sequence) return undefined;
|
|
83
|
+
if (!member.email) return view("ready", true);
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
const nowIso = new Date(now).toISOString();
|
|
86
|
+
const read = (cursor: string) => fetchMemberBookings({ query: "", filter: "value:Past", sort: "za", savedIds: [] }, cursor, nowIso, member);
|
|
87
|
+
let page = await read("");
|
|
88
|
+
const rows = [...page.items];
|
|
89
|
+
for (let pages = 1; pages < MAX_PAGES && page.nextCursor; pages++) { page = await read(page.nextCursor); rows.push(...page.items); }
|
|
90
|
+
// Older bookings the page cap left unread: the streak and the all-time total are then "at least", never a silent shortfall.
|
|
91
|
+
const unreadRemain = Boolean(page.nextCursor);
|
|
92
|
+
if (seq !== sequence) return undefined;
|
|
93
|
+
const progress = weeklyGoalProgress(sessionsInWeek(rows, now, 0), goal);
|
|
94
|
+
const total = allTimeSessions(rows, now);
|
|
95
|
+
const streak = weeklyStreak(rows, now, goal);
|
|
96
|
+
return view("ready", false, {
|
|
97
|
+
goalLabel: progress.label, remainingLabel: progress.remainingLabel, progress: progress.fraction,
|
|
98
|
+
ringText: `${formatNumber(progress.done)}/${formatNumber(progress.goal)}`,
|
|
99
|
+
streak: `${formatNumber(streak)}${streakMayBeLonger(rows, now, goal, streak, unreadRemain) ? "+" : ""}`,
|
|
100
|
+
total: total > MAX_ALL_TIME_SESSIONS ? `${formatNumber(MAX_ALL_TIME_SESSIONS)}+` : `${formatNumber(total)}${unreadRemain ? "+" : ""}`,
|
|
101
|
+
}, now);
|
|
102
|
+
} catch (error) {
|
|
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);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
// Signing in or out on another screen changes the progress this section shows.
|
|
118
|
+
session.subscribe(restart);
|
|
119
|
+
return service;
|
|
120
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// What a performance tracker counts, as pure functions over a member's bookings (no network, no clock read: `now` is an argument), so
|
|
2
|
+
// the rules are unit-tested directly. A session is what My Bookings' "This week" card counts (`isHeldSession` in `weekly-goal.ts`):
|
|
3
|
+
// the section and that card can never disagree.
|
|
4
|
+
import { formatMonthDay } from "./engine-intl.js";
|
|
5
|
+
import type { MemberBookingRow } from "./member-bookings.js";
|
|
6
|
+
import { isHeldSession, weekStartMs, weeklySessionsDone } from "./weekly-goal.js";
|
|
7
|
+
|
|
8
|
+
/** The source's default weekly goal. */
|
|
9
|
+
export const DEFAULT_WEEKLY_GOAL = 2;
|
|
10
|
+
/** The source shows "500+" past this many all-time sessions. */
|
|
11
|
+
export const MAX_ALL_TIME_SESSIONS = 500;
|
|
12
|
+
/** The source looks back one year for the streak. */
|
|
13
|
+
export const STREAK_WEEKS = 52;
|
|
14
|
+
/** 11 pages of 50 past bookings: enough to tell "500 or fewer" from "more", and to reach a year back. */
|
|
15
|
+
export const MAX_PAGES = 11;
|
|
16
|
+
|
|
17
|
+
/** Monday 00:00 local, `weeksBack` weeks before the week `now` is in (DST-safe: calendar days, not 7 * 24 h). */
|
|
18
|
+
const weekStartBack = (now: number, weeksBack: number): number => {
|
|
19
|
+
const d = new Date(weekStartMs(now));
|
|
20
|
+
d.setDate(d.getDate() - 7 * weeksBack);
|
|
21
|
+
return d.getTime();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Sessions held in the week `weeksBack` weeks before `now`'s (0 = this week, up to `now`). */
|
|
25
|
+
export function sessionsInWeek(rows: readonly MemberBookingRow[], now: number, weeksBack: number): number {
|
|
26
|
+
// A millisecond before the next Monday is still in that week, and `weeklySessionsDone` takes its week from the instant it is given.
|
|
27
|
+
return weeklySessionsDone(rows, weeksBack === 0 ? now : weekStartBack(now, weeksBack - 1) - 1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Consecutive weeks that met `goal`, newest first. The week still running counts once it has met the goal and never breaks the
|
|
32
|
+
* streak while it has not: the member still has days left.
|
|
33
|
+
*/
|
|
34
|
+
export function weeklyStreak(rows: readonly MemberBookingRow[], now: number, goal: number): number {
|
|
35
|
+
const current = sessionsInWeek(rows, now, 0);
|
|
36
|
+
let streak = 0;
|
|
37
|
+
for (let back = current >= goal ? 0 : 1; back < STREAK_WEEKS; back++) {
|
|
38
|
+
if ((back === 0 ? current : sessionsInWeek(rows, now, back)) < goal) break;
|
|
39
|
+
streak++;
|
|
40
|
+
}
|
|
41
|
+
return streak;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether `streak` may be longer than the rows show: the read stopped at the page cap with older bookings unread, and the run of weeks
|
|
46
|
+
* reaches the oldest week those rows cover (an older week the rows do not hold looks empty and would end the run early).
|
|
47
|
+
*/
|
|
48
|
+
export function streakMayBeLonger(rows: readonly MemberBookingRow[], now: number, goal: number, streak: number, unreadRemain: boolean): boolean {
|
|
49
|
+
if (!unreadRemain) return false;
|
|
50
|
+
const starts = rows.map((row) => Date.parse(row.start)).filter(Number.isFinite);
|
|
51
|
+
if (!starts.length) return false;
|
|
52
|
+
const week = 7 * 24 * 3600 * 1000;
|
|
53
|
+
const oldestBack = Math.round((weekStartMs(now) - weekStartMs(Math.min(...starts))) / week);
|
|
54
|
+
const firstWeek = sessionsInWeek(rows, now, 0) >= goal ? 0 : 1;
|
|
55
|
+
// A run that ended at the 52-week look-back ended by the source's own limit: older bookings cannot lengthen it.
|
|
56
|
+
if (firstWeek + streak >= STREAK_WEEKS) return false;
|
|
57
|
+
return firstWeek + streak >= oldestBack;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Sessions held, all time (one per booking id). */
|
|
61
|
+
export function allTimeSessions(rows: readonly MemberBookingRow[], now: number): number {
|
|
62
|
+
return new Set(rows.filter((row) => isHeldSession(row, now)).map((row) => row.id || `${row.start}|${row.title}`)).size;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** "Nov 16 – Nov 22": Monday to Sunday of the week `now` is in. */
|
|
66
|
+
export function weekRange(now: number): string {
|
|
67
|
+
const start = new Date(weekStartMs(now));
|
|
68
|
+
const end = new Date(start);
|
|
69
|
+
end.setDate(end.getDate() + 6);
|
|
70
|
+
return `${formatMonthDay(start)} – ${formatMonthDay(end)}`;
|
|
71
|
+
}
|