@wix/himalaya-cli 0.1741.0 → 0.1743.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/members-v1/src/index.d.ts +7 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/pricing-plans/src/index.d.ts +6 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-members.mjs +6 -0
- package/dist/cli.mjs +162 -74
- package/guides/getting-started.md +18 -7
- package/guides/himi-json-output.md +11 -0
- package/guides/himi-skill.md +18 -7
- package/guides/sdk-reference.json +11 -2
- package/guides/skill.md +24 -13
- package/package.json +2 -2
- package/templates/beauty-salon/l10n/en.json +55 -0
- package/templates/beauty-salon/l10n/fr.json +297 -0
- package/templates/beauty-salon/l10n/he.json +319 -0
- package/templates/beauty-salon/recipes/blog-list-thumb-start.json +364 -0
- package/templates/beauty-salon/recipes/blog-list.json +364 -0
- package/templates/beauty-salon/recipes/blog-see-all.json +50 -0
- package/templates/beauty-salon/recipes/events-inline-list.json +203 -0
- package/templates/beauty-salon/recipes/events-inline.json +284 -0
- package/templates/beauty-salon/recipes/members-list.json +445 -0
- package/templates/beauty-salon/recipes/plans-card.json +811 -0
- package/templates/beauty-salon/recipes/programs-card.json +254 -0
- package/templates/beauty-salon/recipes/programs-carousel.json +234 -0
- package/templates/beauty-salon/recipes/section-error.json +58 -0
- package/templates/beauty-salon/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/beauty-salon/tier5-src/_shared/event-registration.ts +86 -0
- package/templates/beauty-salon/tier5-src/_shared/events-card.ts +33 -0
- package/templates/beauty-salon/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/beauty-salon/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/beauty-salon/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/beauty-salon/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/beauty-salon/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/beauty-salon/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/beauty-salon/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/beauty-salon/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/beauty-salon/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/beauty-salon/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/branded-lite/l10n/fr.json +10 -0
- package/templates/branded-lite/l10n/he.json +88 -0
- package/templates/branded-lite/recipes/blog-list-thumb-start.json +364 -0
- package/templates/branded-lite/recipes/blog-list.json +364 -0
- package/templates/branded-lite/recipes/blog-see-all.json +50 -0
- package/templates/branded-lite/recipes/events-inline-list.json +203 -0
- package/templates/branded-lite/recipes/events-inline.json +284 -0
- package/templates/branded-lite/recipes/members-list.json +445 -0
- package/templates/branded-lite/recipes/plans-card.json +811 -0
- package/templates/branded-lite/recipes/programs-card.json +254 -0
- package/templates/branded-lite/recipes/programs-carousel.json +234 -0
- package/templates/branded-lite/recipes/section-error.json +58 -0
- package/templates/branded-lite/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/branded-lite/tier5-src/_shared/events-card.ts +33 -0
- package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/branded-lite/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/branded-lite/tier5-src/_shared/member-row-extras.ts +1 -1
- package/templates/branded-lite/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/branded-lite/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/branded-lite/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/branded-lite/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/branded-lite/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/branded-lite/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/community-club/l10n/en.json +45 -0
- package/templates/community-club/l10n/fr.json +292 -0
- package/templates/community-club/l10n/he.json +315 -0
- package/templates/community-club/recipes/blog-list-thumb-start.json +364 -0
- package/templates/community-club/recipes/blog-list.json +364 -0
- package/templates/community-club/recipes/blog-see-all.json +50 -0
- package/templates/community-club/recipes/events-inline-list.json +203 -0
- package/templates/community-club/recipes/events-inline.json +284 -0
- package/templates/community-club/recipes/members-list.json +445 -0
- package/templates/community-club/recipes/plans-card.json +811 -0
- package/templates/community-club/recipes/programs-card.json +254 -0
- package/templates/community-club/recipes/programs-carousel.json +234 -0
- package/templates/community-club/recipes/section-error.json +58 -0
- package/templates/community-club/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/community-club/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/community-club/tier5-src/_shared/events-card.ts +33 -0
- package/templates/community-club/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/community-club/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/community-club/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/community-club/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/community-club/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/community-club/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/community-club/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/community-club/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/community-club/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/community-club/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/events-meetups/l10n/en.json +45 -0
- package/templates/events-meetups/l10n/fr.json +292 -0
- package/templates/events-meetups/l10n/he.json +315 -0
- package/templates/events-meetups/recipes/blog-list-thumb-start.json +364 -0
- package/templates/events-meetups/recipes/blog-list.json +364 -0
- package/templates/events-meetups/recipes/blog-see-all.json +50 -0
- package/templates/events-meetups/recipes/events-inline-list.json +203 -0
- package/templates/events-meetups/recipes/events-inline.json +284 -0
- package/templates/events-meetups/recipes/members-list.json +445 -0
- package/templates/events-meetups/recipes/plans-card.json +811 -0
- package/templates/events-meetups/recipes/programs-card.json +254 -0
- package/templates/events-meetups/recipes/programs-carousel.json +234 -0
- package/templates/events-meetups/recipes/section-error.json +58 -0
- package/templates/events-meetups/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/events-meetups/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/events-meetups/tier5-src/_shared/events-card.ts +33 -0
- package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/events-meetups/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/events-meetups/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/events-meetups/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/events-meetups/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/events-meetups/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/events-meetups/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/events-meetups/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/events-meetups/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/events-meetups/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/gym-fitness/l10n/en.json +45 -0
- package/templates/gym-fitness/l10n/fr.json +282 -0
- package/templates/gym-fitness/l10n/he.json +307 -0
- package/templates/gym-fitness/recipes/blog-list-thumb-start.json +364 -0
- package/templates/gym-fitness/recipes/blog-list.json +364 -0
- package/templates/gym-fitness/recipes/blog-see-all.json +50 -0
- package/templates/gym-fitness/recipes/events-inline-list.json +203 -0
- package/templates/gym-fitness/recipes/events-inline.json +284 -0
- package/templates/gym-fitness/recipes/members-list.json +445 -0
- package/templates/gym-fitness/recipes/plans-card.json +811 -0
- package/templates/gym-fitness/recipes/programs-card.json +254 -0
- package/templates/gym-fitness/recipes/programs-carousel.json +234 -0
- package/templates/gym-fitness/recipes/section-error.json +58 -0
- package/templates/gym-fitness/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/gym-fitness/tier5-src/_shared/events-card.ts +33 -0
- package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/gym-fitness/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/gym-fitness/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/gym-fitness/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/gym-fitness/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/gym-fitness/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/gym-fitness/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/gym-fitness/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/gym-fitness/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/gym-fitness/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/nonprofit-cause/l10n/en.json +45 -0
- package/templates/nonprofit-cause/l10n/fr.json +267 -0
- package/templates/nonprofit-cause/l10n/he.json +295 -0
- package/templates/nonprofit-cause/recipes/blog-list-thumb-start.json +364 -0
- package/templates/nonprofit-cause/recipes/blog-list.json +364 -0
- package/templates/nonprofit-cause/recipes/blog-see-all.json +50 -0
- package/templates/nonprofit-cause/recipes/events-inline-list.json +203 -0
- package/templates/nonprofit-cause/recipes/events-inline.json +284 -0
- package/templates/nonprofit-cause/recipes/members-list.json +445 -0
- package/templates/nonprofit-cause/recipes/plans-card.json +811 -0
- package/templates/nonprofit-cause/recipes/programs-card.json +254 -0
- package/templates/nonprofit-cause/recipes/programs-carousel.json +234 -0
- package/templates/nonprofit-cause/recipes/section-error.json +58 -0
- package/templates/nonprofit-cause/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/nonprofit-cause/tier5-src/_shared/events-card.ts +33 -0
- package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/nonprofit-cause/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/nonprofit-cause/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/nonprofit-cause/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/nonprofit-cause/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/nonprofit-cause/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/nonprofit-cause/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/nonprofit-cause/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/nonprofit-cause/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/nonprofit-cause/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/podcast-creator/l10n/en.json +45 -0
- package/templates/podcast-creator/l10n/fr.json +287 -0
- package/templates/podcast-creator/l10n/he.json +311 -0
- package/templates/podcast-creator/recipes/blog-list-thumb-start.json +364 -0
- package/templates/podcast-creator/recipes/blog-list.json +364 -0
- package/templates/podcast-creator/recipes/blog-see-all.json +50 -0
- package/templates/podcast-creator/recipes/events-inline-list.json +203 -0
- package/templates/podcast-creator/recipes/events-inline.json +284 -0
- package/templates/podcast-creator/recipes/members-list.json +445 -0
- package/templates/podcast-creator/recipes/plans-card.json +811 -0
- package/templates/podcast-creator/recipes/programs-card.json +254 -0
- package/templates/podcast-creator/recipes/programs-carousel.json +234 -0
- package/templates/podcast-creator/recipes/section-error.json +58 -0
- package/templates/podcast-creator/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/podcast-creator/tier5-src/_shared/events-card.ts +33 -0
- package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/podcast-creator/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/podcast-creator/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/podcast-creator/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/podcast-creator/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/podcast-creator/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/podcast-creator/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/podcast-creator/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/podcast-creator/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/podcast-creator/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/portfolio-creative/l10n/en.json +45 -0
- package/templates/portfolio-creative/l10n/fr.json +317 -0
- package/templates/portfolio-creative/l10n/he.json +335 -0
- package/templates/portfolio-creative/recipes/blog-list-thumb-start.json +364 -0
- package/templates/portfolio-creative/recipes/blog-list.json +364 -0
- package/templates/portfolio-creative/recipes/blog-see-all.json +50 -0
- package/templates/portfolio-creative/recipes/events-inline-list.json +203 -0
- package/templates/portfolio-creative/recipes/events-inline.json +284 -0
- package/templates/portfolio-creative/recipes/members-list.json +445 -0
- package/templates/portfolio-creative/recipes/plans-card.json +811 -0
- package/templates/portfolio-creative/recipes/programs-card.json +254 -0
- package/templates/portfolio-creative/recipes/programs-carousel.json +234 -0
- package/templates/portfolio-creative/recipes/section-error.json +58 -0
- package/templates/portfolio-creative/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/portfolio-creative/tier5-src/_shared/events-card.ts +33 -0
- package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/portfolio-creative/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/portfolio-creative/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/portfolio-creative/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/portfolio-creative/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/portfolio-creative/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/portfolio-creative/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/portfolio-creative/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/portfolio-creative/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/portfolio-creative/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/restaurant/l10n/en.json +45 -0
- package/templates/restaurant/l10n/fr.json +317 -0
- package/templates/restaurant/l10n/he.json +335 -0
- package/templates/restaurant/recipes/blog-list-thumb-start.json +364 -0
- package/templates/restaurant/recipes/blog-list.json +364 -0
- package/templates/restaurant/recipes/blog-see-all.json +50 -0
- package/templates/restaurant/recipes/events-inline-list.json +203 -0
- package/templates/restaurant/recipes/events-inline.json +284 -0
- package/templates/restaurant/recipes/members-list.json +445 -0
- package/templates/restaurant/recipes/plans-card.json +811 -0
- package/templates/restaurant/recipes/programs-card.json +254 -0
- package/templates/restaurant/recipes/programs-carousel.json +234 -0
- package/templates/restaurant/recipes/section-error.json +58 -0
- package/templates/restaurant/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/restaurant/tier5-src/_shared/events-card.ts +33 -0
- package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/restaurant/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/restaurant/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/restaurant/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/restaurant/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/restaurant/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/restaurant/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/restaurant/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/restaurant/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/restaurant/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/retail-store/l10n/en.json +60 -0
- package/templates/retail-store/l10n/fr.json +342 -0
- package/templates/retail-store/l10n/he.json +355 -0
- package/templates/retail-store/recipes/blog-list-thumb-start.json +364 -0
- package/templates/retail-store/recipes/blog-list.json +364 -0
- package/templates/retail-store/recipes/blog-see-all.json +50 -0
- package/templates/retail-store/recipes/events-inline-list.json +203 -0
- package/templates/retail-store/recipes/events-inline.json +284 -0
- package/templates/retail-store/recipes/members-list.json +445 -0
- package/templates/retail-store/recipes/plans-card.json +811 -0
- package/templates/retail-store/recipes/programs-card.json +254 -0
- package/templates/retail-store/recipes/programs-carousel.json +234 -0
- package/templates/retail-store/recipes/section-error.json +58 -0
- package/templates/retail-store/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/retail-store/tier5-src/_shared/event-registration.ts +86 -0
- package/templates/retail-store/tier5-src/_shared/events-card.ts +33 -0
- package/templates/retail-store/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/retail-store/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/retail-store/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/retail-store/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/retail-store/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/retail-store/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/retail-store/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/retail-store/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/retail-store/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/retail-store/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/yoga-studio/l10n/en.json +24 -0
- package/templates/yoga-studio/l10n/fr.json +64 -0
- package/templates/yoga-studio/l10n/he.json +132 -0
- package/templates/yoga-studio/recipes/blog-list-thumb-start.json +364 -0
- package/templates/yoga-studio/recipes/blog-list.json +364 -0
- package/templates/yoga-studio/recipes/blog-see-all.json +50 -0
- package/templates/yoga-studio/recipes/events-inline-list.json +203 -0
- package/templates/yoga-studio/recipes/events-inline.json +284 -0
- package/templates/yoga-studio/recipes/members-list.json +445 -0
- package/templates/yoga-studio/recipes/plans-card.json +811 -0
- package/templates/yoga-studio/recipes/programs-card.json +254 -0
- package/templates/yoga-studio/recipes/programs-carousel.json +234 -0
- package/templates/yoga-studio/recipes/section-error.json +58 -0
- package/templates/yoga-studio/tier5-src/_shared/blog-list.ts +207 -0
- package/templates/yoga-studio/tier5-src/_shared/events-card.ts +33 -0
- package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +25 -0
- package/templates/yoga-studio/tier5-src/_shared/events-inline.ts +82 -0
- package/templates/yoga-studio/tier5-src/_shared/member-activity.ts +34 -0
- package/templates/yoga-studio/tier5-src/_shared/member-row-extras.ts +167 -0
- package/templates/yoga-studio/tier5-src/_shared/members-directory-view.ts +39 -0
- package/templates/yoga-studio/tier5-src/_shared/members-directory.ts +267 -0
- package/templates/yoga-studio/tier5-src/_shared/plan-facts.ts +87 -0
- package/templates/yoga-studio/tier5-src/_shared/plans-section.ts +106 -0
- package/templates/yoga-studio/tier5-src/_shared/programs-section.ts +728 -0
- package/templates/yoga-studio/tier5-src/_shared/relative-time.ts +21 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// A blog post list as a registrable service: the One App compact post list, driven by the source section's settings.
|
|
2
|
+
// limit unset -> follow the page cursor to the last post; limit N -> N posts and a "See All" for the same category,
|
|
3
|
+
// show.{author,date,readingTime,likes,views,comments} -> exactly what the section's displayOptions enable,
|
|
4
|
+
// relativeTime -> "2 hours ago" instead of the date,
|
|
5
|
+
// countOrder -> the icon counts in the source's order (default likes, views, comments).
|
|
6
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe blog-post-row.json).
|
|
7
|
+
import { defineService as register } from "@himalaya/state";
|
|
8
|
+
import { queryPosts, type WixPost, type WixQueryPostsRequest } from "@himalaya/wix-blog";
|
|
9
|
+
import { getPublicMember } from "@himalaya/wix-members";
|
|
10
|
+
import { stashCopy, copyParam, copyPlural } from "./himi-copy.js";
|
|
11
|
+
import { formatDateMedium } from "./engine-intl.js";
|
|
12
|
+
import { relativeTime } from "./relative-time.js";
|
|
13
|
+
import { coverOf } from "./himi-blog-post-row.js";
|
|
14
|
+
|
|
15
|
+
export type CountKey = "likes" | "views" | "comments";
|
|
16
|
+
const COUNT_KEYS: readonly CountKey[] = ["likes", "views", "comments"];
|
|
17
|
+
const ICON: Record<CountKey, string> = { likes: "heart", views: "eye", comments: "message" };
|
|
18
|
+
|
|
19
|
+
export interface BlogListOptions {
|
|
20
|
+
categoryId?: string;
|
|
21
|
+
/** Posts shown; unset follows the cursor to the last post. */
|
|
22
|
+
limit?: number;
|
|
23
|
+
show: { author?: boolean; cover?: boolean; date?: boolean; readingTime?: boolean; likes?: boolean; views?: boolean; comments?: boolean };
|
|
24
|
+
relativeTime?: boolean;
|
|
25
|
+
countOrder?: CountKey[];
|
|
26
|
+
/** The post screen a row opens. */
|
|
27
|
+
detailScreenId?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Count { key: CountKey; icon: string; value: number; text: string }
|
|
31
|
+
interface CountSlot { Icon: string; Text: string; has: boolean; no: boolean }
|
|
32
|
+
|
|
33
|
+
export interface BlogRow {
|
|
34
|
+
id: string; title: string; cover: string; hasCover: boolean; noCover: boolean; initial: string;
|
|
35
|
+
/** Time and reading time ("2 hours ago · 4 min read"). */
|
|
36
|
+
meta: string; hasMeta: boolean; noMeta: boolean;
|
|
37
|
+
authorName: string; hasAuthor: boolean; noAuthor: boolean;
|
|
38
|
+
counts: Count[]; hasCounts: boolean; noCounts: boolean;
|
|
39
|
+
count1Icon: string; count1Text: string; hasCount1: boolean; noCount1: boolean;
|
|
40
|
+
count2Icon: string; count2Text: string; hasCount2: boolean; noCount2: boolean;
|
|
41
|
+
count3Icon: string; count3Text: string; hasCount3: boolean; noCount3: boolean;
|
|
42
|
+
detailScreenId: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface BlogListState {
|
|
46
|
+
status: "loading" | "ready" | "error";
|
|
47
|
+
rows: BlogRow[];
|
|
48
|
+
/** Offset of the next page as a string; "" once the last post has loaded (scroll load-more). */
|
|
49
|
+
nextCursor: string;
|
|
50
|
+
loadingMore: boolean;
|
|
51
|
+
total: number;
|
|
52
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean; notEmpty: boolean; noSeeAll: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The METRICS fieldset names, across the post DTO versions. */
|
|
56
|
+
type Post = WixPost & {
|
|
57
|
+
metrics?: { likes?: number; comments?: number; views?: number; likeCount?: number; totalComments?: number; commentCount?: number; viewCount?: number };
|
|
58
|
+
memberId?: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const PAGE = 20;
|
|
62
|
+
/** The most posts one query returns. A limited list asks for its whole count at once, up to this. */
|
|
63
|
+
const MAX_PAGE = 100;
|
|
64
|
+
const SLOTS = 3;
|
|
65
|
+
|
|
66
|
+
function metric(post: Post, key: CountKey): number | undefined {
|
|
67
|
+
const m = post.metrics ?? {};
|
|
68
|
+
const value = key === "likes" ? m.likes ?? m.likeCount : key === "views" ? m.views ?? m.viewCount : m.comments ?? m.totalComments ?? m.commentCount;
|
|
69
|
+
return typeof value === "number" ? value : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function countText(key: CountKey, value: number): string {
|
|
73
|
+
return key === "likes" ? copyPlural("blogList.likesCount", "{n, plural, one {# like} other {# likes}}", value)
|
|
74
|
+
: key === "views" ? copyPlural("blogList.viewsCount", "{n, plural, one {# view} other {# views}}", value)
|
|
75
|
+
: copyPlural("blogList.commentsCount", "{n, plural, one {# comment} other {# comments}}", value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The icon counts a section shows, in `order`. A count the API did not return is unknown, not zero: it is left out. */
|
|
79
|
+
export function countsOf(post: Post, show: BlogListOptions["show"], order: readonly CountKey[]): Count[] {
|
|
80
|
+
const out: Count[] = [];
|
|
81
|
+
for (const key of order) {
|
|
82
|
+
if (!show[key]) continue;
|
|
83
|
+
const value = metric(post, key);
|
|
84
|
+
if (value !== undefined) out.push({ key, icon: ICON[key], value, text: countText(key, value) });
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const slotOf = (counts: Count[], index: number): CountSlot => {
|
|
90
|
+
const count = counts[index];
|
|
91
|
+
return { Icon: count?.icon ?? "", Text: count?.text ?? "", has: !!count, no: !count };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export function registerBlogList(serviceName: string, options: BlogListOptions) {
|
|
95
|
+
const order = (options.countOrder?.length ? options.countOrder : COUNT_KEYS).filter((key, i, all) => COUNT_KEYS.includes(key) && all.indexOf(key) === i);
|
|
96
|
+
const limited = typeof options.limit === "number" && options.limit > 0;
|
|
97
|
+
const detailScreenId = options.detailScreenId ?? "himi_blog_post";
|
|
98
|
+
// Author names by member id, for this service only. A failed lookup stays unknown: no placeholder name.
|
|
99
|
+
const authors = new Map<string, string>();
|
|
100
|
+
|
|
101
|
+
async function resolveAuthors(posts: Post[]): Promise<void> {
|
|
102
|
+
const ids = [...new Set(posts.map((p) => p.memberId).filter((id): id is string => !!id && !authors.has(id)))];
|
|
103
|
+
await Promise.all(ids.map(async (id) => {
|
|
104
|
+
// The PUBLIC profile only: a visitor can read it, and it carries the nickname without the login email or contact data.
|
|
105
|
+
try { authors.set(id, (await getPublicMember(id)).member.profile?.nickname ?? ""); } catch { authors.set(id, ""); }
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function rowOf(post: Post, now: number): BlogRow {
|
|
110
|
+
const show = options.show;
|
|
111
|
+
const bits: string[] = [];
|
|
112
|
+
if (show.date && post.firstPublishedDate) {
|
|
113
|
+
bits.push(options.relativeTime ? relativeTime(post.firstPublishedDate, now) : formatDateMedium(new Date(post.firstPublishedDate)));
|
|
114
|
+
}
|
|
115
|
+
if (show.readingTime && post.minutesToRead) bits.push(copyPlural("blogList.readingTime", "{n, plural, one {# min read} other {# min read}}", post.minutesToRead));
|
|
116
|
+
const counts = countsOf(post, show, order);
|
|
117
|
+
const [one, two, three] = [slotOf(counts, 0), slotOf(counts, 1), slotOf(counts, 2)];
|
|
118
|
+
// A Wix media reference becomes a fetchable, list-sized URL; the owner turning the cover off (media.displayed) leaves none.
|
|
119
|
+
const cover = show.cover === false ? "" : coverOf(post);
|
|
120
|
+
const authorName = show.author && post.memberId ? authors.get(post.memberId) ?? "" : "";
|
|
121
|
+
const title = post.title || copyParam("blogList.untitled", "Untitled post");
|
|
122
|
+
const meta = bits.filter(Boolean).join(" · ");
|
|
123
|
+
return {
|
|
124
|
+
id: post.id, title, cover, hasCover: !!cover, noCover: !cover, initial: (title[0] ?? "#").toUpperCase(),
|
|
125
|
+
meta, hasMeta: !!meta, noMeta: !meta,
|
|
126
|
+
authorName, hasAuthor: !!authorName, noAuthor: !authorName,
|
|
127
|
+
counts, hasCounts: counts.length > 0, noCounts: counts.length === 0,
|
|
128
|
+
count1Icon: one.Icon, count1Text: one.Text, hasCount1: one.has, noCount1: one.no,
|
|
129
|
+
count2Icon: two.Icon, count2Text: two.Text, hasCount2: two.has, noCount2: two.no,
|
|
130
|
+
count3Icon: three.Icon, count3Text: three.Text, hasCount3: three.has, noCount3: three.no,
|
|
131
|
+
detailScreenId,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** `more`: there are posts past `rows`. It is the page read's answer, not `next < total`: the API may omit the total. */
|
|
136
|
+
function view(status: BlogListState["status"], rows: BlogRow[], next: number, total: number, more: boolean, loadingMore = false): BlogListState {
|
|
137
|
+
return {
|
|
138
|
+
status, rows, loadingMore, total,
|
|
139
|
+
// An unlimited list follows the cursor; a limited one stops at its authored count.
|
|
140
|
+
nextCursor: !limited && more ? String(next) : "",
|
|
141
|
+
notLoading: status !== "loading", notErrored: status !== "error",
|
|
142
|
+
noRows: !rows.length, notEmpty: !(status === "ready" && !rows.length),
|
|
143
|
+
// See All only for a LIMITED list that has more posts than it shows.
|
|
144
|
+
noSeeAll: !(limited && more),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function page(offset: number): Promise<{ rows: BlogRow[]; next: number; total: number; more: boolean }> {
|
|
149
|
+
// A limited list reads its whole count (several queries when it is above the API's per-query cap); an unlimited one a page at a time.
|
|
150
|
+
const want = limited ? options.limit as number : PAGE;
|
|
151
|
+
const rows: BlogRow[] = [];
|
|
152
|
+
let at = offset;
|
|
153
|
+
let total: number | undefined;
|
|
154
|
+
/** Posts exist past what was read: by the total when the API gives one, else because the last page came back full. */
|
|
155
|
+
let more = false;
|
|
156
|
+
while (rows.length < want) {
|
|
157
|
+
const size = Math.min(want - rows.length, limited ? MAX_PAGE : PAGE);
|
|
158
|
+
const result = await queryPosts({
|
|
159
|
+
fieldsets: ["METRICS"],
|
|
160
|
+
query: {
|
|
161
|
+
filter: options.categoryId ? { categoryIds: { $hasSome: [options.categoryId] } } : {},
|
|
162
|
+
paging: { limit: size, offset: at },
|
|
163
|
+
sort: [{ fieldName: "firstPublishedDate", order: "DESC" }],
|
|
164
|
+
},
|
|
165
|
+
} as WixQueryPostsRequest & { fieldsets: string[] });
|
|
166
|
+
const posts = (result.posts ?? []) as Post[];
|
|
167
|
+
if (options.show.author) await resolveAuthors(posts);
|
|
168
|
+
const now = Date.now();
|
|
169
|
+
rows.push(...posts.map((post) => rowOf(post, now)));
|
|
170
|
+
at += posts.length;
|
|
171
|
+
total = result.pagingMetadata?.total;
|
|
172
|
+
// The total is optional in the response: without it, a full page means there may be more, a short or empty one means there is not.
|
|
173
|
+
more = total !== undefined ? at < total : posts.length === size;
|
|
174
|
+
if (!more) break;
|
|
175
|
+
}
|
|
176
|
+
return { rows, next: offset + rows.length, total: total ?? offset + rows.length, more };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const initial = view("loading", [], 0, 0, false);
|
|
180
|
+
/** This run has read the posts. A cold boot restores last session's rows as "ready"; they are revalidated once, then a re-appear keeps them. */
|
|
181
|
+
let loadedThisRun = false;
|
|
182
|
+
const reload = async (): Promise<BlogListState> => {
|
|
183
|
+
try { const p = await page(0); loadedThisRun = true; return view("ready", p.rows, p.next, p.total, p.more); }
|
|
184
|
+
catch (error) { console.warn("blog_list: the posts could not be read", error); return view("error", [], 0, 0, false); }
|
|
185
|
+
};
|
|
186
|
+
const svc = register<BlogListState, {
|
|
187
|
+
load: (state: BlogListState, arg?: unknown) => Promise<BlogListState>;
|
|
188
|
+
retry: (state: BlogListState) => Promise<BlogListState>;
|
|
189
|
+
loadMore: (state: BlogListState) => Promise<BlogListState>;
|
|
190
|
+
}>(serviceName, {
|
|
191
|
+
state: initial,
|
|
192
|
+
actions: {
|
|
193
|
+
// The screen's onAppear fires on every re-appear (back from a post): a list that has posts keeps them and its scroll position. Only an empty (nothing yet, or a failed read) list reads, so posts added while away show on return; retry always reads.
|
|
194
|
+
load: async (state, arg) => { stashCopy(arg); return loadedThisRun && state.status === "ready" && state.rows.length ? state : reload(); },
|
|
195
|
+
retry: reload,
|
|
196
|
+
loadMore: async (state) => {
|
|
197
|
+
if (!state.nextCursor || state.loadingMore) return state;
|
|
198
|
+
try {
|
|
199
|
+
const p = await page(Number(state.nextCursor));
|
|
200
|
+
return view("ready", [...state.rows, ...p.rows], p.next, p.total, p.more);
|
|
201
|
+
} catch (error) { console.warn("blog_list: the next page of posts could not be read", error); return { ...state, loadingMore: false }; }
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
// No load at registration: the page's onAppear loads (with the copy pack), so a page-hosted service reads only when its section appears.
|
|
206
|
+
return svc;
|
|
207
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Pure Events registration helpers shared by the event detail and the event list: which action an
|
|
2
|
+
// event offers, its label, and the URLs behind it. One copy, so a card and the detail screen never
|
|
3
|
+
// disagree about whether an event can be registered for.
|
|
4
|
+
import type { WixEvent } from "@himalaya/wix-events";
|
|
5
|
+
import { formatWeekdayDateTime } from "./engine-intl.js";
|
|
6
|
+
import { copyParam } from "./himi-copy.js";
|
|
7
|
+
|
|
8
|
+
function detailCopy(key: string, fallback: string): string { return copyParam(key, fallback); }
|
|
9
|
+
|
|
10
|
+
/** Registration CTA kind derived from the event's registration/eventType. */
|
|
11
|
+
export type RegistrationKind = "rsvp" | "tickets" | "external" | "none";
|
|
12
|
+
|
|
13
|
+
/** Map registration status and decoded eventType onto the CTA variant. The decoded
|
|
14
|
+
* `eventType` already folds registration.type / registration.initialType /
|
|
15
|
+
* the legacy flat `type` (decodeEvent, #478). Without a recognized type or
|
|
16
|
+
* status there is no registration action to offer. */
|
|
17
|
+
export function registrationKindOf(e: WixEvent): RegistrationKind {
|
|
18
|
+
const raw = e as unknown as { registration?: { type?: string; initialType?: string; status?: string } };
|
|
19
|
+
const value = (raw.registration?.type ?? e.eventType ?? raw.registration?.initialType ?? "").toUpperCase();
|
|
20
|
+
if (value === "NONE" || value.includes("NO_REGISTRATION")) return "none";
|
|
21
|
+
// Open statuses select the footer action, so they must also select the
|
|
22
|
+
// inventory read and action guards when type metadata is absent or stale.
|
|
23
|
+
switch (raw.registration?.status?.toUpperCase()) {
|
|
24
|
+
case "OPEN_TICKETS": return "tickets";
|
|
25
|
+
case "OPEN_EXTERNAL": return "external";
|
|
26
|
+
case "OPEN_RSVP":
|
|
27
|
+
case "OPEN_RSVP_WAITLIST_ONLY":
|
|
28
|
+
case "SCHEDULED_RSVP": return "rsvp";
|
|
29
|
+
}
|
|
30
|
+
if (value.includes("EXTERNAL")) return "external";
|
|
31
|
+
if (value.includes("TICKET")) return "tickets";
|
|
32
|
+
if (value.includes("RSVP")) return "rsvp";
|
|
33
|
+
return "none";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function eventStatus(e: WixEvent): string {
|
|
37
|
+
const raw = e as unknown as { status?: string };
|
|
38
|
+
return (raw.status ?? e.eventStatus ?? "").toUpperCase();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function registrationUi(e: WixEvent, now: number): { state: string; label: string; action: string; caption: string; notice: string } {
|
|
42
|
+
const raw = e as unknown as { registration?: { status?: string; registrationPaused?: boolean; registrationDisabled?: boolean; allowedGuestTypes?: string; rsvp?: { startDate?: string }; tickets?: { soldOut?: boolean }; external?: { url?: string } }; form?: { messages?: { registrationClosed?: { message?: string; exploreEventsActionLabel?: string }; ticketsUnavailable?: { message?: string; exploreEventsActionLabel?: string } } } };
|
|
43
|
+
const r = raw.registration ?? {};
|
|
44
|
+
const status = eventStatus(e);
|
|
45
|
+
const type = registrationKindOf(e);
|
|
46
|
+
if (status === "CANCELED") return { state: "notice", label: "", action: "", caption: "", notice: detailCopy("event.canceledNotice", "This event was canceled.") };
|
|
47
|
+
if (status === "ENDED") return { state: "notice", label: "", action: "", caption: "", notice: detailCopy("event.endedNotice", "This event has ended.") };
|
|
48
|
+
if (type === "none" || r.registrationDisabled) return { state: "none", label: "", action: "", caption: "", notice: "" };
|
|
49
|
+
const ownerClosed = raw.form?.messages?.registrationClosed?.message;
|
|
50
|
+
const ownerSold = raw.form?.messages?.ticketsUnavailable?.message;
|
|
51
|
+
if (["CLOSED_AUTOMATICALLY", "CLOSED_MANUALLY"].includes(r.status || "") || r.registrationPaused) return { state: "notice", label: "", action: "", caption: "", notice: ownerClosed || detailCopy("event.closedNotice", "Registration is closed.") };
|
|
52
|
+
if (type === "tickets" && r.tickets?.soldOut) return { state: "notice", label: "", action: "", caption: "", notice: ownerSold || detailCopy("event.soldOutNotice", "Tickets are sold out.") };
|
|
53
|
+
if (r.status === "SCHEDULED_RSVP") return { state: "scheduled", label: detailCopy("event.rsvpCta", "RSVP"), action: "", caption: detailCopy("event.opensCaption", "RSVP opens {date}.").replace("{date}", r.rsvp?.startDate ? formatWeekdayDateTime(new Date(r.rsvp.startDate)) : ""), notice: "" };
|
|
54
|
+
if (r.status === "OPEN_RSVP_WAITLIST_ONLY") return { state: "waitlist", label: detailCopy("event.waitlistCta", "Join Waitlist"), action: "himi.open", caption: detailCopy("event.fullCaption", "This event is full."), notice: "" };
|
|
55
|
+
if (r.status === "OPEN_TICKETS" || type === "tickets") return { state: "tickets", label: detailCopy("event.ticketsCta", "Buy Tickets"), action: "openTickets", caption: "", notice: "" };
|
|
56
|
+
if (r.status === "OPEN_EXTERNAL" || type === "external") return registrationUrlOf(e)
|
|
57
|
+
? { state: "external", label: detailCopy("event.externalCta", "Register"), action: "openRegistration", caption: "", notice: "" }
|
|
58
|
+
: { state: "none", label: "", action: "", caption: "", notice: "" };
|
|
59
|
+
if (type === "rsvp" && r.status === "OPEN_RSVP") return { state: "rsvp", label: detailCopy("event.rsvpCta", "RSVP"), action: "himi.open", caption: "", notice: "" };
|
|
60
|
+
if (r.status === "OPEN_RSVP" || (type === "rsvp" && !r.status)) return { state: "rsvp", label: detailCopy("event.rsvpCta", "RSVP"), action: "himi.open", caption: "", notice: "" };
|
|
61
|
+
void now;
|
|
62
|
+
return { state: "none", label: "", action: "", caption: "", notice: "" };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** External registration URL / event page URL from the raw payload ("" when absent). */
|
|
66
|
+
export function registrationUrlOf(e: WixEvent): string {
|
|
67
|
+
const raw = e as unknown as {
|
|
68
|
+
registration?: { external?: { registration?: string; url?: string } };
|
|
69
|
+
eventPageUrl?: { base?: string; path?: string } | string;
|
|
70
|
+
};
|
|
71
|
+
const external = raw.registration?.external?.registration ?? raw.registration?.external?.url;
|
|
72
|
+
if (typeof external === "string" && /^https?:\/\//i.test(external)) return external;
|
|
73
|
+
return eventPageUrlOf(e);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The event's public page URL when the payload carries one ("" otherwise). */
|
|
77
|
+
export function eventPageUrlOf(e: WixEvent): string {
|
|
78
|
+
const raw = e as unknown as { eventPageUrl?: { base?: string; path?: string } | string };
|
|
79
|
+
const page = raw.eventPageUrl;
|
|
80
|
+
if (typeof page === "string" && /^https?:\/\//i.test(page)) return page;
|
|
81
|
+
if (page && typeof page === "object" && typeof page.base === "string" && page.base) {
|
|
82
|
+
const path = typeof page.path === "string" ? page.path : "";
|
|
83
|
+
return `${page.base.replace(/\/$/, "")}${path && !path.startsWith("/") ? "/" : ""}${path}`;
|
|
84
|
+
}
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The event CARD facts shared by the events list and the inline events section: the date badge, the registration verb and
|
|
2
|
+
// the page URL for Share. One copy, so a card on a page and a card in the list never disagree about what an event offers.
|
|
3
|
+
import type { WixEvent } from "@himalaya/wix-events";
|
|
4
|
+
import type { EventRow } from "./himi-events";
|
|
5
|
+
import { eventPageUrlOf, registrationUi } from "./event-registration.js";
|
|
6
|
+
|
|
7
|
+
export interface ListEventRow extends EventRow {
|
|
8
|
+
/** "10\nNOV" for an event with a calendar date; "" for an undated one (the card then shows the day monogram). */
|
|
9
|
+
dateBadge: string; noDateBadge: boolean;
|
|
10
|
+
/** This card's verb (Register / RSVP / Buy Tickets / Join Waitlist / Free Event) from the SAME rule the detail uses; hidden when none applies. */
|
|
11
|
+
actionLabel: string; noAction: boolean;
|
|
12
|
+
/** The event page URL (when the payload carries one) for Share. */
|
|
13
|
+
shareUrl: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The month must be the three-letter abbreviation: rows cached by an older worker on an Intl-less engine can hold a
|
|
17
|
+
* whole "11/10/2030, 12:00:00 PM" there. Only an actual calendar date becomes a badge. */
|
|
18
|
+
export function withDateBadge(row: EventRow): ListEventRow {
|
|
19
|
+
const dated = typeof row.month === "string" && /^[A-Z]{3}$/.test(row.month)
|
|
20
|
+
&& /^(?:[1-9]|[12]\d|3[01])$/.test(row.day);
|
|
21
|
+
const known = row as Partial<ListEventRow>;
|
|
22
|
+
// Rows cached by an older build carry no registration data: they show no verb until a refresh, never a wrong one.
|
|
23
|
+
return { ...row, dateBadge: dated ? `${row.day}\n${row.month}` : "", noDateBadge: !dated,
|
|
24
|
+
actionLabel: known.actionLabel ?? "", noAction: known.noAction ?? true, shareUrl: known.shareUrl ?? "" };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The card's action, from the event's own registration (REGISTRATION + URLS fieldsets). Cancelled, ended, closed, sold-out and
|
|
28
|
+
* registration-less events offer none, so a card never promises "Register" where the detail refuses. */
|
|
29
|
+
export function withRegistration(raw: WixEvent, row: ListEventRow): ListEventRow {
|
|
30
|
+
const ui = registrationUi(raw, Date.now());
|
|
31
|
+
const offers = ui.state !== "notice" && ui.state !== "none" && ui.state !== "scheduled" && !!ui.label;
|
|
32
|
+
return { ...row, actionLabel: offers ? ui.label : "", noAction: !offers, shareUrl: eventPageUrlOf(raw) };
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The pure options of the inline events section. No imports: Node tests read it directly, and the worker bundle shares it.
|
|
2
|
+
|
|
3
|
+
export interface EventsInlineOptions {
|
|
4
|
+
/** How many events the section shows. Clamped to 1..10; default 3. */
|
|
5
|
+
limit?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const EVENTS_INLINE_DEFAULT_LIMIT = 3;
|
|
9
|
+
export const EVENTS_INLINE_MAX_LIMIT = 10;
|
|
10
|
+
|
|
11
|
+
/** A bad or missing limit is the default, never an error: the value arrives from a generated recipe. */
|
|
12
|
+
export function eventsInlineLimit(value: unknown): number {
|
|
13
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
14
|
+
if (!Number.isFinite(n)) return EVENTS_INLINE_DEFAULT_LIMIT;
|
|
15
|
+
return Math.min(EVENTS_INLINE_MAX_LIMIT, Math.max(1, Math.trunc(n)));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Events that have not finished: not started yet, or still running (a festival on its second day is still on). */
|
|
19
|
+
export function upcomingFilter(nowIso: string): Record<string, unknown> {
|
|
20
|
+
return {
|
|
21
|
+
status: { $ne: "DRAFT" },
|
|
22
|
+
$or: [{ "dateAndTimeSettings.startDate": { $gte: nowIso } }, { "dateAndTimeSettings.endDate": { $gte: nowIso } }],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The INLINE events section: the next few events as cards, hosted by any worker that wants them next to other sections
|
|
2
|
+
// (a page that mixes text, a button and an events list), or on its own through `himi-events-inline`. The section is data only:
|
|
3
|
+
// `eventsInlineSection(...)` in the app's events-inline section builder is the card that reads it, bound as
|
|
4
|
+
// `$service:<serviceName>.*`.
|
|
5
|
+
//
|
|
6
|
+
// What it does NOT show, on purpose: attendees. Neither a Visitor nor a Member can read an event's guest list (probed: the owner
|
|
7
|
+
// guest list 404s, the guests and rsvps queries 403), so an avatar stack would be invented. Nothing here claims otherwise.
|
|
8
|
+
import { defineService } from "@himalaya/state";
|
|
9
|
+
import { queryEvents, type WixEvent } from "@himalaya/wix-events";
|
|
10
|
+
import { share as shareSheet } from "@himalaya/share";
|
|
11
|
+
import { normalizeEvent } from "./himi-events";
|
|
12
|
+
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
13
|
+
import { withDateBadge, withRegistration, type ListEventRow } from "./events-card.js";
|
|
14
|
+
import { eventsInlineLimit, upcomingFilter, type EventsInlineOptions } from "./events-inline-options.js";
|
|
15
|
+
|
|
16
|
+
export { EVENTS_INLINE_DEFAULT_LIMIT, EVENTS_INLINE_MAX_LIMIT, eventsInlineLimit, upcomingFilter, type EventsInlineOptions } from "./events-inline-options.js";
|
|
17
|
+
|
|
18
|
+
export interface EventsInlineState {
|
|
19
|
+
status: "loading" | "ready" | "error";
|
|
20
|
+
rows: ListEventRow[];
|
|
21
|
+
/** More upcoming events exist than the section shows: the See-all link is meaningful. */
|
|
22
|
+
hasMore: boolean;
|
|
23
|
+
isLoading: boolean; notLoading: boolean;
|
|
24
|
+
isErrored: boolean; notErrored: boolean;
|
|
25
|
+
hasRows: boolean; noRows: boolean;
|
|
26
|
+
/** The empty line, "" while there are rows (the section collapses it). */
|
|
27
|
+
emptyText: string; noEmpty: boolean;
|
|
28
|
+
noMore: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function derive(state: Omit<EventsInlineState, "isLoading" | "notLoading" | "isErrored" | "notErrored" | "hasRows" | "noRows" | "noEmpty" | "noMore">): EventsInlineState {
|
|
32
|
+
const ready = state.status === "ready";
|
|
33
|
+
return {
|
|
34
|
+
...state,
|
|
35
|
+
isLoading: state.status === "loading", notLoading: state.status !== "loading",
|
|
36
|
+
isErrored: state.status === "error", notErrored: state.status !== "error",
|
|
37
|
+
hasRows: state.rows.length > 0, noRows: state.rows.length === 0,
|
|
38
|
+
noEmpty: !(ready && state.rows.length === 0),
|
|
39
|
+
noMore: !state.hasMore,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function registerEventsInline(serviceName: string, options: EventsInlineOptions = {}) {
|
|
44
|
+
const limit = eventsInlineLimit(options.limit);
|
|
45
|
+
const initial = derive({ status: "loading", rows: [], hasMore: false, emptyText: "" });
|
|
46
|
+
return defineService<EventsInlineState, {
|
|
47
|
+
load: (state: EventsInlineState, arg?: unknown) => Promise<EventsInlineState>;
|
|
48
|
+
share: (state: EventsInlineState, arg?: unknown) => Promise<EventsInlineState>;
|
|
49
|
+
}>(serviceName, {
|
|
50
|
+
state: initial,
|
|
51
|
+
actions: {
|
|
52
|
+
load: async (state, arg) => {
|
|
53
|
+
stashCopy(arg);
|
|
54
|
+
try {
|
|
55
|
+
const res = await queryEvents({
|
|
56
|
+
limit, offset: 0, fields: ["DETAILS", "REGISTRATION", "URLS"],
|
|
57
|
+
query: { filter: upcomingFilter(new Date().toISOString()),
|
|
58
|
+
sort: [{ fieldName: "dateAndTimeSettings.startDate", order: "ASC" }, { fieldName: "id", order: "ASC" }] },
|
|
59
|
+
});
|
|
60
|
+
const raw: WixEvent[] = (res.events ?? []).filter((event) => !!event.id);
|
|
61
|
+
const rows = raw.map((event) => withRegistration(event, withDateBadge(normalizeEvent(event))));
|
|
62
|
+
const total = (res as { pagingMetadata?: { total?: number } }).pagingMetadata?.total;
|
|
63
|
+
return derive({
|
|
64
|
+
status: "ready", rows, hasMore: typeof total === "number" ? total > rows.length : false,
|
|
65
|
+
emptyText: rows.length ? "" : copyParam("eventsInline.empty", "No upcoming events."),
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.warn("events_inline: the events could not be read", error);
|
|
69
|
+
return derive({ ...state, status: "error", rows: [], hasMore: false, emptyText: "" });
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
// Share one card's event: its title and date line, plus the event page when the payload carried one.
|
|
73
|
+
share: async (state, arg) => {
|
|
74
|
+
const id = typeof arg === "string" ? arg : String((arg as { id?: unknown } | undefined)?.id ?? "");
|
|
75
|
+
const row = state.rows.find((item) => item.id === id);
|
|
76
|
+
if (!row) return state;
|
|
77
|
+
try { await shareSheet({ subject: row.title, text: [row.title, row.dateLine].filter(Boolean).join(" — "), ...(row.shareUrl ? { url: row.shareUrl } : {}) }); } catch { /* the sheet is best-effort */ }
|
|
78
|
+
return state;
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The One App's "Active 11h ago" / "Last seen Apr 5, 2023" line for a member, from the same inputs and by
|
|
2
|
+
// the same rule as its member list (wix-one-app-members-area getActiveSinceText).
|
|
3
|
+
import type { WixMemberActivity } from "@himalaya/wix-members";
|
|
4
|
+
import { copyParam, copyTemplate } from "./himi-copy.js";
|
|
5
|
+
import { appLocale } from "./app-locale.js";
|
|
6
|
+
import { formatDateMedium } from "./engine-intl.js";
|
|
7
|
+
|
|
8
|
+
/** Less than this many days reads as "Active Nd ago"; from here the One App prints the date instead. */
|
|
9
|
+
const DAYS_AS_COUNT = 30;
|
|
10
|
+
|
|
11
|
+
/** "" when there is nothing to say: a member who never opened the app shows no line. */
|
|
12
|
+
export function activityText(activity: Pick<WixMemberActivity, "online" | "lastOpenApp"> | undefined): string {
|
|
13
|
+
if (!activity) return "";
|
|
14
|
+
const activeNow = () => copyParam("members.activeNow", "Active now");
|
|
15
|
+
if (activity.online) return activeNow();
|
|
16
|
+
const last = activity.lastOpenApp;
|
|
17
|
+
if (!last) return "";
|
|
18
|
+
const amount = typeof last.amount === "number" ? last.amount : 0;
|
|
19
|
+
switch (last.unit) {
|
|
20
|
+
case "min":
|
|
21
|
+
return amount === 0 ? activeNow() : copyTemplate("members.activeMinutesAgo", "Active {amount}m ago", { amount });
|
|
22
|
+
case "hour":
|
|
23
|
+
return copyTemplate("members.activeHoursAgo", "Active {amount}h ago", { amount });
|
|
24
|
+
case "day": {
|
|
25
|
+
const daysAgo = () => copyTemplate("members.activeDaysAgo", "Active {amount}d ago", { amount });
|
|
26
|
+
if ((amount && amount < DAYS_AS_COUNT) || !last.ts) return daysAgo();
|
|
27
|
+
const at = Number(last.ts);
|
|
28
|
+
if (!Number.isFinite(at)) return daysAgo();
|
|
29
|
+
return copyTemplate("members.lastSeen", "Last seen {date}", { date: formatDateMedium(new Date(at), appLocale()) });
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// What a members-directory row shows beyond name and photo: the role line, the member's badges and the
|
|
2
|
+
// Follow control. One call per page for each source, and none of it may fail the directory: a refused or
|
|
3
|
+
// failed read leaves that row element out (no chip, a plain Follow), never an error in place of the list.
|
|
4
|
+
import { query as queryBadges, queryBadgeAssignments, type WixBadge } from "@himalaya/wix-badges";
|
|
5
|
+
import { getMyMember, listFollowedMembers, queryMemberActivity } from "@himalaya/wix-members";
|
|
6
|
+
import { compareIso } from "./engine-intl.js";
|
|
7
|
+
import { copyParam } from "./himi-copy.js";
|
|
8
|
+
import { activityText } from "./member-activity.js";
|
|
9
|
+
import type { ReadAccess } from "./member-read.js";
|
|
10
|
+
|
|
11
|
+
/** The One App row draws ONE badge chip and a "+N" chip for the rest. */
|
|
12
|
+
const MAX_BADGE_CHIPS = 1;
|
|
13
|
+
const PAGE_LIMIT = 100;
|
|
14
|
+
const CATALOG_PAGES = 5;
|
|
15
|
+
const ASSIGNMENT_PAGES = 10;
|
|
16
|
+
/** The chip's text is white (`textOnAccent`); this is the least contrast it may have against the badge colour. */
|
|
17
|
+
const MIN_CONTRAST = 3;
|
|
18
|
+
|
|
19
|
+
export interface MemberRowExtras {
|
|
20
|
+
/** Role line, then the last-active line when there is one. The role line reads "Member" for everyone: the activity route
|
|
21
|
+
* also answers a role (an admin's is "ADMIN"), but the One App's wording for the other roles is not recorded here,
|
|
22
|
+
* so none is guessed. */
|
|
23
|
+
subtitle: string;
|
|
24
|
+
badgeTitle: string; badgeColor: string; noBadge: boolean;
|
|
25
|
+
badgeMore: string; noBadgeMore: boolean;
|
|
26
|
+
followLabel: string; isFollowing: boolean;
|
|
27
|
+
/** Hidden for a Visitor (who gets the sign-in variant) and on the signed-in member's own row. */
|
|
28
|
+
hideFollow: boolean;
|
|
29
|
+
/** Only a Visitor sees this one: Follow needs a member, so the tap opens sign-in. */
|
|
30
|
+
hideSignInFollow: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function followLabel(isFollowing: boolean): string {
|
|
34
|
+
return copyParam(isFollowing ? "members.followingCta" : "members.followCta", isFollowing ? "Following" : "Follow");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface BadgeInfo { title: string; color: string; rank: number }
|
|
38
|
+
|
|
39
|
+
function hexRgb(value: string | undefined): [number, number, number] | undefined {
|
|
40
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((value ?? "").trim());
|
|
41
|
+
if (!m) return undefined;
|
|
42
|
+
const h = m[1].length === 3 ? m[1].split("").map(c => c + c).join("") : m[1];
|
|
43
|
+
return [0, 2, 4].map(i => parseInt(h.slice(i, i + 2), 16)) as [number, number, number];
|
|
44
|
+
}
|
|
45
|
+
function luminance([r, g, b]: [number, number, number]): number {
|
|
46
|
+
const lin = (v: number) => { const c = v / 255; return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); };
|
|
47
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
48
|
+
}
|
|
49
|
+
/** The badge colour as `#rrggbb`, darkened until white text on it reads (a pastel chip would otherwise
|
|
50
|
+
* lose its label in one of the two themes). "" when the badge carries no usable colour, so the row's
|
|
51
|
+
* token background shows instead. */
|
|
52
|
+
export function chipColor(value: string | undefined): string {
|
|
53
|
+
let rgb = hexRgb(value);
|
|
54
|
+
if (!rgb) return "";
|
|
55
|
+
while ((1.05 / (luminance(rgb) + 0.05)) < MIN_CONTRAST && (rgb[0] || rgb[1] || rgb[2])) {
|
|
56
|
+
rgb = rgb.map(c => Math.floor(c * 0.9)) as [number, number, number];
|
|
57
|
+
}
|
|
58
|
+
return "#" + rgb.map(c => c.toString(16).padStart(2, "0")).join("");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let catalogTenant = "";
|
|
62
|
+
let catalog: Map<string, BadgeInfo> | undefined;
|
|
63
|
+
|
|
64
|
+
/** The site's badges, newest first: that is the order the One App picks a member's first chip in. */
|
|
65
|
+
async function badgeCatalog(tenant: string): Promise<Map<string, BadgeInfo>> {
|
|
66
|
+
if (catalog && catalogTenant === tenant) return catalog;
|
|
67
|
+
const badges: WixBadge[] = [];
|
|
68
|
+
let cursor: string | undefined;
|
|
69
|
+
for (let page = 0; page < CATALOG_PAGES; page++) {
|
|
70
|
+
const res = await queryBadges({ query: { cursorPaging: cursor ? { cursor } : { limit: PAGE_LIMIT } } });
|
|
71
|
+
badges.push(...(res.badges ?? []));
|
|
72
|
+
cursor = res.pagingMetadata?.hasNext ? res.pagingMetadata.cursors?.next : undefined;
|
|
73
|
+
if (!cursor) break;
|
|
74
|
+
}
|
|
75
|
+
if (cursor) throw new Error("Badge catalog is longer than the pages read");
|
|
76
|
+
const newestFirst = badges.filter(b => b.id && b.title?.trim())
|
|
77
|
+
.sort((a, b) => compareIso(String(b.createdDate ?? ""), String(a.createdDate ?? "")));
|
|
78
|
+
catalogTenant = tenant;
|
|
79
|
+
return catalog = new Map(newestFirst.map((b, rank) => [b.id as string, { title: (b.title as string).trim(), color: chipColor(b.backgroundColor), rank }]));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** memberId → badge ids, for the page's members. A cursor request carries the cursor alone: the service
|
|
83
|
+
* refuses (400) a follow-up page that repeats the filter or the limit. A page the pages cap cuts short is refused whole: a
|
|
84
|
+
* partial list would show the wrong first chip and a wrong "+N". */
|
|
85
|
+
export async function badgesByMember(ids: string[]): Promise<Map<string, string[]>> {
|
|
86
|
+
const byMember = new Map<string, string[]>();
|
|
87
|
+
let cursor: string | undefined;
|
|
88
|
+
for (let page = 0; page < ASSIGNMENT_PAGES; page++) {
|
|
89
|
+
const res = await queryBadgeAssignments({ query: cursor ? { cursorPaging: { cursor } } : { filter: { memberId: { $in: ids } }, cursorPaging: { limit: PAGE_LIMIT } } });
|
|
90
|
+
for (const a of res.badgeAssignments ?? []) {
|
|
91
|
+
if (!a.memberId || !a.badgeId) continue;
|
|
92
|
+
const held = byMember.get(a.memberId) ?? [];
|
|
93
|
+
held.push(a.badgeId); byMember.set(a.memberId, held);
|
|
94
|
+
}
|
|
95
|
+
cursor = res.pagingMetadata?.hasNext ? res.pagingMetadata.cursors?.next : undefined;
|
|
96
|
+
if (!cursor) return byMember;
|
|
97
|
+
}
|
|
98
|
+
throw new Error("Badge assignments are longer than the pages read");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function readBadges(ids: string[], tenant: string): Promise<Map<string, BadgeInfo[]>> {
|
|
102
|
+
const [known, held] = await Promise.all([badgeCatalog(tenant), badgesByMember(ids)]);
|
|
103
|
+
const result = new Map<string, BadgeInfo[]>();
|
|
104
|
+
for (const [memberId, badgeIds] of held) {
|
|
105
|
+
const badges = badgeIds.map(id => known.get(id)).filter((b): b is BadgeInfo => !!b).sort((a, b) => a.rank - b.rank);
|
|
106
|
+
if (badges.length) result.set(memberId, badges);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** memberId → "Active 11h ago" etc., for the members the One App service knows and has something to say about.
|
|
112
|
+
* An older native build refuses the route; that leaves the activity line out and nothing else. */
|
|
113
|
+
async function readActivity(ids: string[]): Promise<Map<string, string>> {
|
|
114
|
+
const texts = new Map<string, string>();
|
|
115
|
+
for (const activity of await queryMemberActivity(ids)) {
|
|
116
|
+
const text = activityText(activity);
|
|
117
|
+
if (text) texts.set(activity.id, text);
|
|
118
|
+
}
|
|
119
|
+
return texts;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function readFollowed(ids: string[], access: ReadAccess): Promise<Set<string>> {
|
|
123
|
+
// Follow state is the signed-in member's own; a Visitor has none to read.
|
|
124
|
+
return access.member.email ? new Set(await listFollowedMembers(ids)) : new Set();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let selfScope = "";
|
|
128
|
+
let selfId = "";
|
|
129
|
+
async function ownMemberId(access: ReadAccess): Promise<string> {
|
|
130
|
+
if (!access.member.email) return "";
|
|
131
|
+
const scope = JSON.stringify([access.tenant, access.member.email]);
|
|
132
|
+
if (selfScope !== scope) {
|
|
133
|
+
const id = (await getMyMember({ fieldsets: ["PUBLIC"] })).member?.id ?? "";
|
|
134
|
+
// An answer without a member is not a lookup to remember: the next page asks again, so the member's own row
|
|
135
|
+
// does not keep a Follow button for the rest of the session.
|
|
136
|
+
if (!id) return "";
|
|
137
|
+
selfId = id;
|
|
138
|
+
selfScope = scope;
|
|
139
|
+
}
|
|
140
|
+
return selfId;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const attempt = async <T>(read: Promise<T>, fallback: T): Promise<T> => { try { return await read; } catch { return fallback; } };
|
|
144
|
+
|
|
145
|
+
/** The per-row extras for one page of members. Each source fails on its own. */
|
|
146
|
+
export async function memberRowExtras(ids: string[], access: ReadAccess): Promise<(id: string) => MemberRowExtras> {
|
|
147
|
+
const [badges, activity, followed, self] = await Promise.all([
|
|
148
|
+
attempt(readBadges(ids, access.tenant), new Map<string, BadgeInfo[]>()),
|
|
149
|
+
attempt(readActivity(ids), new Map<string, string>()),
|
|
150
|
+
attempt(readFollowed(ids, access), new Set<string>()),
|
|
151
|
+
attempt(ownMemberId(access), ""),
|
|
152
|
+
]);
|
|
153
|
+
const visitor = !access.member.email;
|
|
154
|
+
const role = copyParam("members.roleMember", "Member");
|
|
155
|
+
return (id) => {
|
|
156
|
+
const held = badges.get(id) ?? [];
|
|
157
|
+
const more = held.length - MAX_BADGE_CHIPS;
|
|
158
|
+
const isFollowing = followed.has(id);
|
|
159
|
+
return {
|
|
160
|
+
subtitle: [role, activity.get(id)].filter(Boolean).join(" · "),
|
|
161
|
+
badgeTitle: held[0]?.title ?? "", badgeColor: held[0]?.color ?? "", noBadge: !held.length,
|
|
162
|
+
badgeMore: more > 0 ? `+${more}` : "", noBadgeMore: more <= 0,
|
|
163
|
+
followLabel: followLabel(isFollowing), isFollowing,
|
|
164
|
+
hideFollow: visitor || id === self, hideSignInFollow: !visitor,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
}
|