@wix/himalaya-cli 0.1777.0 → 0.1778.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/cli.mjs +394 -61
- package/guides/one-app-section-mappings.md +5 -8
- package/guides/one-app-to-himi-app.md +21 -7
- 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,62 @@
|
|
|
1
|
+
// A blog category list as a registrable service: the One App category list section, driven by the source section's settings.
|
|
2
|
+
// categoryIds -> only those categories, in that order (unset: every category the blog has),
|
|
3
|
+
// showCount -> the "12 posts" line under each name (the source's `categoryListDisplayOptions.postsCount`).
|
|
4
|
+
// A category with no published post is left out: its row would open a list with nothing in it.
|
|
5
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe blog-categories.json).
|
|
6
|
+
import { defineService } from "@himalaya/state";
|
|
7
|
+
import { queryCategories } from "@himalaya/wix-blog";
|
|
8
|
+
import { copyPlural, stashCopy } from "./himi-copy.js";
|
|
9
|
+
|
|
10
|
+
export interface BlogCategoriesOptions {
|
|
11
|
+
/** Show only these categories, in this order. */
|
|
12
|
+
categoryIds?: string[];
|
|
13
|
+
/** Show each category's post count under its name. */
|
|
14
|
+
showCount?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CategoryRow {
|
|
18
|
+
id: string; title: string;
|
|
19
|
+
/** "12 posts"; "" when the section does not show counts or the API gave none. */
|
|
20
|
+
count: string; hasCount: boolean; noCount: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BlogCategoriesState {
|
|
24
|
+
status: "loading" | "ready" | "error";
|
|
25
|
+
rows: CategoryRow[];
|
|
26
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The most categories one query returns: a blog with more shows its first 100. */
|
|
30
|
+
const QUERY_LIMIT = 100;
|
|
31
|
+
|
|
32
|
+
export function registerBlogCategories(serviceName: string, options: BlogCategoriesOptions = {}) {
|
|
33
|
+
const view = (status: BlogCategoriesState["status"], rows: CategoryRow[]): BlogCategoriesState => ({
|
|
34
|
+
status, rows, notLoading: status !== "loading", notErrored: status !== "error", noRows: !rows.length,
|
|
35
|
+
});
|
|
36
|
+
return defineService<BlogCategoriesState, { load: (state: BlogCategoriesState, arg?: unknown) => Promise<BlogCategoriesState> }>(serviceName, {
|
|
37
|
+
state: view("loading", []),
|
|
38
|
+
actions: {
|
|
39
|
+
load: async (_state, arg) => {
|
|
40
|
+
stashCopy(arg);
|
|
41
|
+
try {
|
|
42
|
+
const response = await queryCategories({ paging: { limit: QUERY_LIMIT } });
|
|
43
|
+
const byId = new Map((response.categories ?? []).map((category) => [category.id, category]));
|
|
44
|
+
// The chosen categories in the source's order (one that no longer exists is simply absent), else the blog's own order.
|
|
45
|
+
const chosen = options.categoryIds?.length ? options.categoryIds.flatMap((id) => byId.get(id) ?? []) : [...byId.values()];
|
|
46
|
+
const rows = chosen.flatMap((category): CategoryRow[] => {
|
|
47
|
+
const title = (category.label || category.title || "").trim();
|
|
48
|
+
if (!category.id || !title || category.postCount === 0) return [];
|
|
49
|
+
// `postCount` absent (an older payload) shows no count rather than a guessed one.
|
|
50
|
+
const count = options.showCount && category.postCount !== undefined
|
|
51
|
+
? copyPlural("blogList.categoryPostCount", "{n, plural, one {# post} other {# posts}}", category.postCount) : "";
|
|
52
|
+
return [{ id: category.id, title, count, hasCount: !!count, noCount: !count }];
|
|
53
|
+
});
|
|
54
|
+
return view("ready", rows);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.warn("blog_categories: the categories could not be read", error);
|
|
57
|
+
return view("error", []);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// An event's agenda (Wix Events schedule items), as the conference screens show it: one row per
|
|
2
|
+
// visible session in start order, its time range and length in the EVENT's time zone (an
|
|
3
|
+
// attendee abroad plans by the venue's clock), its stage, and the day it falls on.
|
|
4
|
+
//
|
|
5
|
+
// Read from the visitor-readable `GET /events/v1/schedule?eventId=` — only when the event has its
|
|
6
|
+
// agenda turned on (`agendaSettings.enabled`); otherwise Wix answers for an owner only. A failed
|
|
7
|
+
// read is reported (`ok: false`) so the caller can show an error with Retry, never an empty agenda.
|
|
8
|
+
import { calendarDay, formatClock, formatWeekdayMonthDayLong } from "./engine-intl.js";
|
|
9
|
+
import { copyParam, copyTemplate } from "./himi-copy.js";
|
|
10
|
+
|
|
11
|
+
export interface AgendaSession {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
/** "9:30 AM – 10:00 AM"; "" when the item has no valid start. */
|
|
15
|
+
time: string;
|
|
16
|
+
/** "30 min", "2 hr", "1 hr 30 min"; "" when it has no valid end. */
|
|
17
|
+
duration: string;
|
|
18
|
+
/** The stage or room; "" when the item names none. */
|
|
19
|
+
place: string;
|
|
20
|
+
noPlace: boolean;
|
|
21
|
+
description: string;
|
|
22
|
+
noDescription: boolean;
|
|
23
|
+
/** The day it falls on in the event's zone, `YYYY-MM-DD` — the grouping key. */
|
|
24
|
+
dayKey: string;
|
|
25
|
+
/** "Thursday, January 12". */
|
|
26
|
+
dayLabel: string;
|
|
27
|
+
start: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type WixApi = { call: (method: string, path: string, body?: unknown) => Promise<unknown> };
|
|
31
|
+
function wixApi(): WixApi | null {
|
|
32
|
+
return (globalThis as { himalaya?: { wixApi?: WixApi } }).himalaya?.wixApi ?? null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const clean = (value: unknown): string => (typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "");
|
|
36
|
+
/** A schedule item's description is HTML ("<p>Nina Rashid, Founder of DigiArt</p>"): its text,
|
|
37
|
+
* one paragraph per line break. No DOM in a worker, so the tags are stripped by hand. */
|
|
38
|
+
export function plainText(html: unknown): string {
|
|
39
|
+
if (typeof html !== "string") return "";
|
|
40
|
+
return html
|
|
41
|
+
.replace(/<\s*br\s*\/?>/gi, "\n").replace(/<\/\s*(p|div|li|h[1-6])\s*>/gi, "\n").replace(/<[^>]*>/g, "")
|
|
42
|
+
.replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'")
|
|
43
|
+
.split("\n").map((line) => line.replace(/\s+/g, " ").trim()).filter(Boolean).join("\n");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** "1 hr 30 min" for 90 minutes, in this screen's copy. */
|
|
47
|
+
export function durationLabel(minutes: number): string {
|
|
48
|
+
if (!Number.isFinite(minutes) || minutes <= 0) return "";
|
|
49
|
+
// Round the whole length first: 4 h 59 min 58 s is "5 hr", never "4 hr 60 min".
|
|
50
|
+
const total = Math.round(minutes);
|
|
51
|
+
const h = Math.floor(total / 60), m = total % 60;
|
|
52
|
+
if (h && m) return copyTemplate("agendaCommon.durationHoursMinutes", "{h} hr {m} min", { h, m });
|
|
53
|
+
if (h) return copyTemplate("agendaCommon.durationHours", "{h} hr", { h });
|
|
54
|
+
return copyTemplate("agendaCommon.durationMinutes", "{m} min", { m });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface RawItem {
|
|
58
|
+
id?: unknown; name?: unknown; title?: unknown; hidden?: unknown; status?: unknown;
|
|
59
|
+
stageName?: unknown; description?: unknown;
|
|
60
|
+
timeSlot?: { start?: unknown; end?: unknown; timeZoneId?: unknown };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One session row from a Wix schedule item, or null for a hidden, draft or unnamed one. */
|
|
64
|
+
export function agendaSession(item: RawItem, eventZone: string): AgendaSession | null {
|
|
65
|
+
if (item.hidden === true) return null;
|
|
66
|
+
// Wix schedule items are SCHEDULED or CANCELED (a draft is a separate copy, not a status).
|
|
67
|
+
if (clean(item.status).toUpperCase() === "CANCELED") return null;
|
|
68
|
+
const id = clean(item.id), name = clean(item.name) || clean(item.title);
|
|
69
|
+
if (!id || !name) return null;
|
|
70
|
+
const zone = clean(item.timeSlot?.timeZoneId) || eventZone || undefined;
|
|
71
|
+
const start = new Date(clean(item.timeSlot?.start));
|
|
72
|
+
const end = new Date(clean(item.timeSlot?.end));
|
|
73
|
+
const hasStart = !Number.isNaN(start.getTime());
|
|
74
|
+
const hasEnd = hasStart && !Number.isNaN(end.getTime()) && end.getTime() > start.getTime();
|
|
75
|
+
const place = clean(item.stageName);
|
|
76
|
+
const description = plainText(item.description);
|
|
77
|
+
return {
|
|
78
|
+
id,
|
|
79
|
+
name,
|
|
80
|
+
time: hasStart ? (hasEnd ? `${formatClock(start, "en-US", zone)} – ${formatClock(end, "en-US", zone)}` : formatClock(start, "en-US", zone)) : "",
|
|
81
|
+
duration: hasEnd ? durationLabel((end.getTime() - start.getTime()) / 60000) : "",
|
|
82
|
+
place,
|
|
83
|
+
noPlace: !place,
|
|
84
|
+
description,
|
|
85
|
+
noDescription: !description,
|
|
86
|
+
dayKey: hasStart ? calendarDay(start, zone) : "",
|
|
87
|
+
dayLabel: hasStart ? formatWeekdayMonthDayLong(start, "en-US", zone) : copyParam("agendaCommon.dayTbd", "Time to be announced"),
|
|
88
|
+
start: hasStart ? start.getTime() : Number.MAX_SAFE_INTEGER,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type AgendaRead = { ok: true; sessions: AgendaSession[] } | { ok: false; sessions: AgendaSession[] };
|
|
93
|
+
|
|
94
|
+
/** The visible sessions of `eventId`, in start order. An agenda that is off is an empty one. */
|
|
95
|
+
export async function readAgenda(eventId: string, agendaEnabled: boolean, eventZone: string): Promise<AgendaRead> {
|
|
96
|
+
if (!eventId || !agendaEnabled) return { ok: true, sessions: [] };
|
|
97
|
+
const api = wixApi();
|
|
98
|
+
if (!api) return { ok: false, sessions: [] };
|
|
99
|
+
try {
|
|
100
|
+
// `limit` is required: without it Wix answers `total: 5` and an EMPTY `items`.
|
|
101
|
+
const res = await api.call("GET", `/events/v1/schedule?eventId=${encodeURIComponent(eventId)}&limit=100`) as { items?: RawItem[] } | null;
|
|
102
|
+
const seen = new Set<string>();
|
|
103
|
+
const sessions = (res?.items ?? [])
|
|
104
|
+
.map((item) => agendaSession(item, eventZone))
|
|
105
|
+
// One row per item id: an owner's read lists a draft and its published copy under one id.
|
|
106
|
+
.filter((row): row is AgendaSession => !!row && !seen.has(row.id) && !!seen.add(row.id))
|
|
107
|
+
// Ties by name, compared by code unit: `localeCompare` is ECMA-402, which the wrist engines lack.
|
|
108
|
+
.sort((a, b) => a.start - b.start || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
109
|
+
return { ok: true, sessions };
|
|
110
|
+
} catch {
|
|
111
|
+
return { ok: false, sessions: [] };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The event's own time zone and whether its agenda is on, from an Events v3 record. */
|
|
116
|
+
export function agendaSettingsOf(event: unknown): { enabled: boolean; zone: string } {
|
|
117
|
+
const e = event as { agendaSettings?: { enabled?: unknown }; dateAndTimeSettings?: { timeZoneId?: unknown }; scheduling?: { timeZoneId?: unknown; config?: { timeZoneId?: unknown } } } | null;
|
|
118
|
+
return {
|
|
119
|
+
enabled: e?.agendaSettings?.enabled === true,
|
|
120
|
+
zone: clean(e?.dateAndTimeSettings?.timeZoneId) || clean(e?.scheduling?.config?.timeZoneId) || clean(e?.scheduling?.timeZoneId),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// A page's Events schedule section as a registrable service: the sessions of ONE chosen event (the source section's `eventId`), in start
|
|
2
|
+
// order, each as the day and start time it runs (in the app's language, in the EVENT's time zone), its name and its stage.
|
|
3
|
+
// limit -> how many sessions (default 10); `noMore` is false when the event has more, which is when the section's View All button
|
|
4
|
+
// (to the event screen, whose full schedule lists every session) shows.
|
|
5
|
+
// The read is the one the conference agenda makes: the event with its AGENDA fieldset (without it Wix leaves `agendaSettings` out and the
|
|
6
|
+
// agenda is never read), then `GET /events/v1/schedule?eventId=` (_shared/event-agenda.ts). An event with its agenda off, or none, has no
|
|
7
|
+
// sessions: the section then hides completely (`hideSection`), title included. A failed read is `error`, never an empty schedule; an event
|
|
8
|
+
// that no longer exists (404) is an empty one.
|
|
9
|
+
// The section adds no words of its own: every row is the event's own data, and the error state is the shared section-error recipe's.
|
|
10
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe event-schedule).
|
|
11
|
+
import { defineService } from "@himalaya/state";
|
|
12
|
+
import { getEvent } from "@himalaya/wix-events";
|
|
13
|
+
import { agendaSettingsOf, readAgenda, type AgendaSession } from "./event-agenda.js";
|
|
14
|
+
import { isNotFoundError } from "./detail-presence.js";
|
|
15
|
+
import { formatClock, formatWeekdayMonthDayLong } from "./engine-intl.js";
|
|
16
|
+
import { stashCopy } from "./himi-copy.js";
|
|
17
|
+
|
|
18
|
+
export interface EventScheduleOptions {
|
|
19
|
+
/** The event whose schedule this is. */
|
|
20
|
+
eventId: string;
|
|
21
|
+
/** How many sessions to show. */
|
|
22
|
+
limit?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ScheduleRow {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
/** "Thursday, January 12 · 9:30 AM": the day and start time, in the app's language and the event's zone; a session with no start is "to be announced". */
|
|
29
|
+
when: string;
|
|
30
|
+
/** The stage or room; "" when the session names none. */
|
|
31
|
+
place: string;
|
|
32
|
+
noPlace: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface EventScheduleState {
|
|
36
|
+
status: "loading" | "ready" | "error";
|
|
37
|
+
rows: ScheduleRow[];
|
|
38
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean;
|
|
39
|
+
/** The read finished and there is nothing to show: the whole section (title included) hides. */
|
|
40
|
+
hideSection: boolean;
|
|
41
|
+
/** false when the event has more sessions than the section shows. */
|
|
42
|
+
noMore: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const DEFAULT_LIMIT = 10, MAX_LIMIT = 30;
|
|
46
|
+
|
|
47
|
+
/** `AgendaSession.start` of a session with no valid start (it sorts last). */
|
|
48
|
+
const NO_START = Number.MAX_SAFE_INTEGER;
|
|
49
|
+
|
|
50
|
+
/** The agenda module formats in en-US for the conference template; a branded app shows its own language, so the row formats the timestamp. */
|
|
51
|
+
const rowOf = (session: AgendaSession, zone: string): ScheduleRow => {
|
|
52
|
+
const date = new Date(session.start);
|
|
53
|
+
const tz = zone || undefined;
|
|
54
|
+
return {
|
|
55
|
+
id: session.id, name: session.name,
|
|
56
|
+
// A session with no valid start has no time to show: the agenda module's "Time to be announced" is English that no branded-lite
|
|
57
|
+
// catalog translates, so the line stays empty and the recipe collapses it (`collapseWhenEmpty`).
|
|
58
|
+
when: session.start === NO_START ? "" : [formatWeekdayMonthDayLong(date, undefined, tz), formatClock(date, undefined, tz)].filter(Boolean).join(" · "),
|
|
59
|
+
place: session.place, noPlace: session.noPlace,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export function registerEventScheduleSection(serviceName: string, options: EventScheduleOptions) {
|
|
64
|
+
const limit = Math.min(Math.max(Math.floor(options.limit ?? DEFAULT_LIMIT), 1), MAX_LIMIT);
|
|
65
|
+
const view = (status: EventScheduleState["status"], rows: ReadonlyArray<ScheduleRow>, more: boolean): EventScheduleState => ({
|
|
66
|
+
status, rows: [...rows],
|
|
67
|
+
notLoading: status !== "loading", notErrored: status !== "error", noRows: !rows.length,
|
|
68
|
+
hideSection: status === "ready" && !rows.length,
|
|
69
|
+
noMore: !more,
|
|
70
|
+
});
|
|
71
|
+
return defineService<EventScheduleState, { load: (state: EventScheduleState, arg?: unknown) => Promise<EventScheduleState> }>(serviceName, {
|
|
72
|
+
state: view("loading", [], false),
|
|
73
|
+
actions: {
|
|
74
|
+
load: async (_state, arg) => {
|
|
75
|
+
stashCopy(arg);
|
|
76
|
+
try {
|
|
77
|
+
if (!options.eventId) return view("ready", [], false);
|
|
78
|
+
const res = await getEvent(options.eventId, { fields: ["DETAILS", "AGENDA"] });
|
|
79
|
+
const { enabled, zone } = agendaSettingsOf((res as unknown as { event?: unknown }).event ?? res);
|
|
80
|
+
const agenda = await readAgenda(options.eventId, enabled, zone);
|
|
81
|
+
if (!agenda.ok) throw new Error("The event schedule could not be read");
|
|
82
|
+
return view("ready", agenda.sessions.slice(0, limit).map((session) => rowOf(session, zone)), agenda.sessions.length > limit);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (isNotFoundError(error)) return view("ready", [], false);
|
|
85
|
+
console.warn("event_schedule_section: the schedule could not be read", error);
|
|
86
|
+
return view("error", [], false);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -63,7 +63,7 @@ function authorOf(item: WixFeedItem, profiles: WixFeedProfile[]): { name: string
|
|
|
63
63
|
return { name: profile?.userName || named || copyParam("feed.memberFallbackName", "Member"), avatar: fromProfile || fromCreator || "" };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function postRow(item: WixFeedItem, profiles: WixFeedProfile[], now: number): GroupFeedRow {
|
|
66
|
+
export function postRow(item: WixFeedItem, profiles: WixFeedProfile[], now: number): GroupFeedRow {
|
|
67
67
|
const { name, avatar } = authorOf(item, profiles);
|
|
68
68
|
return {
|
|
69
69
|
id: item.feedItemId || "", author: name, initials: initials(name),
|
|
@@ -73,7 +73,7 @@ function postRow(item: WixFeedItem, profiles: WixFeedProfile[], now: number): Gr
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/** The feed read is a member scope: Wix answers a viewer it will not show with `HTTP 401` / `HTTP 403`. */
|
|
76
|
-
const isRefusal = (error: unknown): boolean => /\b(401|403)\b/.test(String((error as Error | undefined)?.message ?? error));
|
|
76
|
+
export const isRefusal = (error: unknown): boolean => /\b(401|403)\b/.test(String((error as Error | undefined)?.message ?? error));
|
|
77
77
|
|
|
78
78
|
export function registerGroupFeedSection(serviceName: string, options: GroupFeedOptions) {
|
|
79
79
|
const view = (status: GroupFeedState["status"], parts: { rows?: GroupFeedRow[]; groupName?: string; privacy?: string; restrictedText?: string } = {}): GroupFeedState => {
|
|
@@ -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
|
}
|