@wix/himalaya-cli 0.1741.0 → 0.1742.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 +161 -73
- 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,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
|
+
}
|
|
@@ -82,7 +82,7 @@ async function badgeCatalog(tenant: string): Promise<Map<string, BadgeInfo>> {
|
|
|
82
82
|
/** memberId → badge ids, for the page's members. A cursor request carries the cursor alone: the service
|
|
83
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
84
|
* partial list would show the wrong first chip and a wrong "+N". */
|
|
85
|
-
async function badgesByMember(ids: string[]): Promise<Map<string, string[]>> {
|
|
85
|
+
export async function badgesByMember(ids: string[]): Promise<Map<string, string[]>> {
|
|
86
86
|
const byMember = new Map<string, string[]>();
|
|
87
87
|
let cursor: string | undefined;
|
|
88
88
|
for (let page = 0; page < ASSIGNMENT_PAGES; page++) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The pure pieces of a members directory row: the activity line and a badge's theme color. No SDK imports, so they run
|
|
2
|
+
// (and are tested) outside a worker bundle.
|
|
3
|
+
import { copyParam, copyTemplate } from "./himi-copy.js";
|
|
4
|
+
import { formatDateMedium } from "./engine-intl.js";
|
|
5
|
+
|
|
6
|
+
const MINUTE = 60_000;
|
|
7
|
+
const HOUR = 60 * MINUTE;
|
|
8
|
+
const DAY = 24 * HOUR;
|
|
9
|
+
|
|
10
|
+
/** Theme colors a badge's own color is matched to: the descriptor takes a token name, never a hex. */
|
|
11
|
+
const TOKEN_COLORS: Array<[token: string, rgb: [number, number, number]]> = [
|
|
12
|
+
["accentPrimary", [47, 125, 225]], ["success", [46, 157, 87]], ["warning", [224, 161, 0]],
|
|
13
|
+
["danger", [214, 69, 69]], ["textSecondary", [107, 114, 128]],
|
|
14
|
+
];
|
|
15
|
+
/** The theme color closest to a badge's hex background; a color that is not a hex is the neutral one. */
|
|
16
|
+
export function badgeToken(hex: string | undefined): string {
|
|
17
|
+
const match = /^#?([0-9a-f]{6})$/i.exec((hex ?? "").trim());
|
|
18
|
+
if (!match) return "textSecondary";
|
|
19
|
+
const value = parseInt(match[1]!, 16);
|
|
20
|
+
const rgb = [(value >> 16) & 255, (value >> 8) & 255, value & 255];
|
|
21
|
+
let best = TOKEN_COLORS[0]!;
|
|
22
|
+
let bestDistance = Infinity;
|
|
23
|
+
for (const entry of TOKEN_COLORS) {
|
|
24
|
+
const distance = entry[1].reduce((sum, channel, i) => sum + (channel - rgb[i]!) ** 2, 0);
|
|
25
|
+
if (distance < bestDistance) { best = entry; bestDistance = distance; }
|
|
26
|
+
}
|
|
27
|
+
return best[0];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** "Active 11h ago" within a day, "Last seen <date>" after; "" with no login date (or one in the future). */
|
|
31
|
+
export function activityLine(lastLogin: string | undefined, now: number): string {
|
|
32
|
+
const at = lastLogin ? Date.parse(lastLogin) : NaN;
|
|
33
|
+
if (!Number.isFinite(at) || at > now) return "";
|
|
34
|
+
const age = now - at;
|
|
35
|
+
if (age < MINUTE) return copyParam("members.activeNow", "Active now");
|
|
36
|
+
if (age < HOUR) return copyTemplate("members.activeMinutes", "Active {n}m ago", { n: Math.floor(age / MINUTE) });
|
|
37
|
+
if (age < DAY) return copyTemplate("members.activeHours", "Active {n}h ago", { n: Math.floor(age / HOUR) });
|
|
38
|
+
return copyTemplate("members.lastSeen", "Last seen {date}", { date: formatDateMedium(new Date(at)) });
|
|
39
|
+
}
|