@wix/himalaya-cli 0.1747.0 → 0.1748.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +34 -8
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +45 -18
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +36 -14
- package/dist/cli.mjs +2498 -1816
- package/guides/one-app-to-himi-app.md +11 -6
- package/guides/wix-business-context.md +25 -1
- package/guides/wix-site-to-himi-app.md +2 -1
- package/package.json +2 -2
- package/templates/beauty-salon/l10n/fr.json +25 -5
- package/templates/beauty-salon/l10n/he.json +20 -4
- package/templates/beauty-salon/recipes/blog-hero.json +95 -0
- package/templates/beauty-salon/recipes/blog-list-thumb-start.json +177 -147
- package/templates/beauty-salon/recipes/blog-list.json +172 -142
- package/templates/beauty-salon/recipes/events-inline-list.json +30 -5
- package/templates/beauty-salon/recipes/events-inline.json +30 -5
- package/templates/beauty-salon/recipes/faq-list.json +503 -0
- package/templates/beauty-salon/recipes/groups-list.json +196 -0
- package/templates/beauty-salon/recipes/products-carousel.json +141 -0
- package/templates/beauty-salon/recipes/products-grid.json +143 -0
- package/templates/beauty-salon/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/beauty-salon/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/beauty-salon/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/beauty-salon/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/beauty-salon/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/beauty-salon/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/beauty-salon/tier5-src/_shared/products-section.ts +76 -0
- package/templates/beauty-salon/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/branded-lite/l10n/fr.json +10 -5
- package/templates/branded-lite/l10n/he.json +8 -4
- package/templates/branded-lite/recipes/blog-hero.json +95 -0
- package/templates/branded-lite/recipes/blog-list-thumb-start.json +177 -147
- package/templates/branded-lite/recipes/blog-list.json +172 -142
- package/templates/branded-lite/recipes/events-inline-list.json +30 -5
- package/templates/branded-lite/recipes/events-inline.json +30 -5
- package/templates/branded-lite/recipes/faq-list.json +503 -0
- package/templates/branded-lite/recipes/groups-list.json +196 -0
- package/templates/branded-lite/recipes/products-carousel.json +141 -0
- package/templates/branded-lite/recipes/products-grid.json +143 -0
- package/templates/branded-lite/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/branded-lite/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/branded-lite/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/branded-lite/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/branded-lite/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/branded-lite/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/branded-lite/tier5-src/_shared/products-section.ts +76 -0
- package/templates/branded-lite/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-faq/index.ts +5 -369
- package/templates/brandy/README.md +46 -5
- package/templates/brandy/config.ts +11 -0
- package/templates/brandy/himalaya.template.json +1 -1
- package/templates/community-club/l10n/fr.json +25 -5
- package/templates/community-club/l10n/he.json +20 -4
- package/templates/community-club/recipes/blog-hero.json +95 -0
- package/templates/community-club/recipes/blog-list-thumb-start.json +177 -147
- package/templates/community-club/recipes/blog-list.json +172 -142
- package/templates/community-club/recipes/events-inline-list.json +30 -5
- package/templates/community-club/recipes/events-inline.json +30 -5
- package/templates/community-club/recipes/faq-list.json +503 -0
- package/templates/community-club/recipes/groups-list.json +196 -0
- package/templates/community-club/recipes/products-carousel.json +141 -0
- package/templates/community-club/recipes/products-grid.json +143 -0
- package/templates/community-club/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/community-club/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/community-club/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/community-club/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/community-club/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/community-club/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/community-club/tier5-src/_shared/products-section.ts +76 -0
- package/templates/community-club/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/events-meetups/l10n/fr.json +25 -5
- package/templates/events-meetups/l10n/he.json +20 -4
- package/templates/events-meetups/recipes/blog-hero.json +95 -0
- package/templates/events-meetups/recipes/blog-list-thumb-start.json +177 -147
- package/templates/events-meetups/recipes/blog-list.json +172 -142
- package/templates/events-meetups/recipes/events-inline-list.json +30 -5
- package/templates/events-meetups/recipes/events-inline.json +30 -5
- package/templates/events-meetups/recipes/faq-list.json +503 -0
- package/templates/events-meetups/recipes/groups-list.json +196 -0
- package/templates/events-meetups/recipes/products-carousel.json +141 -0
- package/templates/events-meetups/recipes/products-grid.json +143 -0
- package/templates/events-meetups/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/events-meetups/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/events-meetups/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/events-meetups/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/events-meetups/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/events-meetups/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/events-meetups/tier5-src/_shared/products-section.ts +76 -0
- package/templates/events-meetups/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/gym-fitness/l10n/fr.json +25 -5
- package/templates/gym-fitness/l10n/he.json +20 -4
- package/templates/gym-fitness/recipes/blog-hero.json +95 -0
- package/templates/gym-fitness/recipes/blog-list-thumb-start.json +177 -147
- package/templates/gym-fitness/recipes/blog-list.json +172 -142
- package/templates/gym-fitness/recipes/events-inline-list.json +30 -5
- package/templates/gym-fitness/recipes/events-inline.json +30 -5
- package/templates/gym-fitness/recipes/faq-list.json +503 -0
- package/templates/gym-fitness/recipes/groups-list.json +196 -0
- package/templates/gym-fitness/recipes/products-carousel.json +141 -0
- package/templates/gym-fitness/recipes/products-grid.json +143 -0
- package/templates/gym-fitness/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/gym-fitness/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/gym-fitness/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/gym-fitness/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/gym-fitness/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/gym-fitness/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/gym-fitness/tier5-src/_shared/products-section.ts +76 -0
- package/templates/gym-fitness/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/nonprofit-cause/l10n/fr.json +25 -5
- package/templates/nonprofit-cause/l10n/he.json +20 -4
- package/templates/nonprofit-cause/recipes/blog-hero.json +95 -0
- package/templates/nonprofit-cause/recipes/blog-list-thumb-start.json +177 -147
- package/templates/nonprofit-cause/recipes/blog-list.json +172 -142
- package/templates/nonprofit-cause/recipes/events-inline-list.json +30 -5
- package/templates/nonprofit-cause/recipes/events-inline.json +30 -5
- package/templates/nonprofit-cause/recipes/faq-list.json +503 -0
- package/templates/nonprofit-cause/recipes/groups-list.json +196 -0
- package/templates/nonprofit-cause/recipes/products-carousel.json +141 -0
- package/templates/nonprofit-cause/recipes/products-grid.json +143 -0
- package/templates/nonprofit-cause/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/nonprofit-cause/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/nonprofit-cause/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/nonprofit-cause/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/nonprofit-cause/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/nonprofit-cause/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/nonprofit-cause/tier5-src/_shared/products-section.ts +76 -0
- package/templates/nonprofit-cause/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/podcast-creator/l10n/fr.json +35 -5
- package/templates/podcast-creator/l10n/he.json +28 -4
- package/templates/podcast-creator/recipes/blog-hero.json +95 -0
- package/templates/podcast-creator/recipes/blog-list-thumb-start.json +177 -147
- package/templates/podcast-creator/recipes/blog-list.json +172 -142
- package/templates/podcast-creator/recipes/events-inline-list.json +30 -5
- package/templates/podcast-creator/recipes/events-inline.json +30 -5
- package/templates/podcast-creator/recipes/faq-list.json +503 -0
- package/templates/podcast-creator/recipes/groups-list.json +196 -0
- package/templates/podcast-creator/recipes/products-carousel.json +141 -0
- package/templates/podcast-creator/recipes/products-grid.json +143 -0
- package/templates/podcast-creator/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/podcast-creator/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/podcast-creator/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/podcast-creator/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/podcast-creator/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/podcast-creator/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/podcast-creator/tier5-src/_shared/products-section.ts +76 -0
- package/templates/podcast-creator/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/portfolio-creative/l10n/fr.json +25 -5
- package/templates/portfolio-creative/l10n/he.json +20 -4
- package/templates/portfolio-creative/recipes/blog-hero.json +95 -0
- package/templates/portfolio-creative/recipes/blog-list-thumb-start.json +177 -147
- package/templates/portfolio-creative/recipes/blog-list.json +172 -142
- package/templates/portfolio-creative/recipes/events-inline-list.json +30 -5
- package/templates/portfolio-creative/recipes/events-inline.json +30 -5
- package/templates/portfolio-creative/recipes/faq-list.json +503 -0
- package/templates/portfolio-creative/recipes/groups-list.json +196 -0
- package/templates/portfolio-creative/recipes/products-carousel.json +141 -0
- package/templates/portfolio-creative/recipes/products-grid.json +143 -0
- package/templates/portfolio-creative/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/portfolio-creative/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/portfolio-creative/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/portfolio-creative/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/portfolio-creative/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/portfolio-creative/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/portfolio-creative/tier5-src/_shared/products-section.ts +76 -0
- package/templates/portfolio-creative/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/restaurant/l10n/fr.json +35 -5
- package/templates/restaurant/l10n/he.json +28 -4
- package/templates/restaurant/recipes/blog-hero.json +95 -0
- package/templates/restaurant/recipes/blog-list-thumb-start.json +177 -147
- package/templates/restaurant/recipes/blog-list.json +172 -142
- package/templates/restaurant/recipes/events-inline-list.json +30 -5
- package/templates/restaurant/recipes/events-inline.json +30 -5
- package/templates/restaurant/recipes/faq-list.json +503 -0
- package/templates/restaurant/recipes/groups-list.json +196 -0
- package/templates/restaurant/recipes/products-carousel.json +141 -0
- package/templates/restaurant/recipes/products-grid.json +143 -0
- package/templates/restaurant/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/restaurant/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/restaurant/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/restaurant/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/restaurant/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/restaurant/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/restaurant/tier5-src/_shared/products-section.ts +76 -0
- package/templates/restaurant/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/retail-store/l10n/fr.json +25 -5
- package/templates/retail-store/l10n/he.json +20 -4
- package/templates/retail-store/recipes/blog-hero.json +95 -0
- package/templates/retail-store/recipes/blog-list-thumb-start.json +177 -147
- package/templates/retail-store/recipes/blog-list.json +172 -142
- package/templates/retail-store/recipes/events-inline-list.json +30 -5
- package/templates/retail-store/recipes/events-inline.json +30 -5
- package/templates/retail-store/recipes/faq-list.json +503 -0
- package/templates/retail-store/recipes/groups-list.json +196 -0
- package/templates/retail-store/recipes/products-carousel.json +141 -0
- package/templates/retail-store/recipes/products-grid.json +143 -0
- package/templates/retail-store/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/retail-store/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/retail-store/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/retail-store/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/retail-store/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/retail-store/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/retail-store/tier5-src/_shared/products-section.ts +76 -0
- package/templates/retail-store/tier5-src/_shared/programs-section.ts +2 -2
- package/templates/yoga-studio/l10n/fr.json +35 -5
- package/templates/yoga-studio/l10n/he.json +28 -4
- package/templates/yoga-studio/recipes/blog-hero.json +95 -0
- package/templates/yoga-studio/recipes/blog-list-thumb-start.json +177 -147
- package/templates/yoga-studio/recipes/blog-list.json +172 -142
- package/templates/yoga-studio/recipes/events-inline-list.json +30 -5
- package/templates/yoga-studio/recipes/events-inline.json +30 -5
- package/templates/yoga-studio/recipes/faq-list.json +503 -0
- package/templates/yoga-studio/recipes/groups-list.json +196 -0
- package/templates/yoga-studio/recipes/products-carousel.json +141 -0
- package/templates/yoga-studio/recipes/products-grid.json +143 -0
- package/templates/yoga-studio/tier5-src/_shared/blog-list.ts +9 -9
- package/templates/yoga-studio/tier5-src/_shared/events-inline.ts +7 -5
- package/templates/yoga-studio/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/yoga-studio/tier5-src/_shared/groups-section.ts +110 -0
- package/templates/yoga-studio/tier5-src/_shared/member-row-extras.ts +10 -2
- package/templates/yoga-studio/tier5-src/_shared/members-directory.ts +9 -5
- package/templates/yoga-studio/tier5-src/_shared/products-section.ts +76 -0
- package/templates/yoga-studio/tier5-src/_shared/programs-section.ts +2 -2
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// The FAQ as a registrable service: one worker for the himi_faq screen and for a migrated page's FAQ section.
|
|
2
|
+
// registerFaqList(name) -> the screen: every question, search, categories (the himi_faq bundle is this call);
|
|
3
|
+
// registerFaqList(name, options) -> a section: `limit` (the source's NumberOfFAQs), `showCategories`, `firstOpen`, `oneAtATime`, `showSearch`.
|
|
4
|
+
// State and flags are the screen's own (`loadingHidden`, `errorHidden`, ...), so the faq-list recipe and the himi_faq descriptor bind the same names.
|
|
5
|
+
import { defineService } from "@himalaya/state";
|
|
6
|
+
import {
|
|
7
|
+
queryCategories,
|
|
8
|
+
queryQuestionEntries,
|
|
9
|
+
type WixCategory,
|
|
10
|
+
type WixQuestionEntry,
|
|
11
|
+
} from "@himalaya/wix-faq";
|
|
12
|
+
import { openRichLink } from "../_shared/rich-content-link.js";
|
|
13
|
+
import { richBody, ROW_IMAGE_WIDTH } from "../_shared/rich-body.js";
|
|
14
|
+
|
|
15
|
+
interface FaqQuestion {
|
|
16
|
+
id: string;
|
|
17
|
+
categoryId: string;
|
|
18
|
+
question: string;
|
|
19
|
+
/** The PLAIN_TEXT answer: the RichContent fallback, and what shows with no trusted document. */
|
|
20
|
+
answer: string;
|
|
21
|
+
/** [rico] #3372 — the RICH_CONTENT answer as ONE document string, used ONLY when its text matches the plain
|
|
22
|
+
* answer (a legacy DraftJS record converts unreliably); "" otherwise. */
|
|
23
|
+
answerJson: string;
|
|
24
|
+
/** answerJson !== "" — gates the plain answer, because RichContent draws nothing for "". */
|
|
25
|
+
hasAnswerJson: boolean;
|
|
26
|
+
sortOrder?: number;
|
|
27
|
+
status: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface FaqCategory {
|
|
31
|
+
id: string;
|
|
32
|
+
title: string;
|
|
33
|
+
sortOrder?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface QuestionRow {
|
|
37
|
+
id: string;
|
|
38
|
+
title: string;
|
|
39
|
+
answer: string;
|
|
40
|
+
answerJson: string;
|
|
41
|
+
hasAnswerJson: boolean;
|
|
42
|
+
expanded: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface CategorySection {
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
questions: QuestionRow[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface FaqDisplayRow extends QuestionRow {
|
|
52
|
+
categoryTitle: string;
|
|
53
|
+
categoryHeaderHidden: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface FaqState {
|
|
57
|
+
status: "loading" | "ready" | "error" | "forbidden" | "notInstalled";
|
|
58
|
+
categories: FaqCategory[];
|
|
59
|
+
questions: FaqQuestion[];
|
|
60
|
+
sections: CategorySection[];
|
|
61
|
+
rows: FaqDisplayRow[];
|
|
62
|
+
query: string;
|
|
63
|
+
expandedIds: string[];
|
|
64
|
+
otherTitle: string;
|
|
65
|
+
loadingHidden: boolean;
|
|
66
|
+
contentHidden: boolean;
|
|
67
|
+
emptyHidden: boolean;
|
|
68
|
+
errorHidden: boolean;
|
|
69
|
+
forbiddenHidden: boolean;
|
|
70
|
+
notInstalledHidden: boolean;
|
|
71
|
+
/** The section's search field is off (the source's showSearchBar is false). */
|
|
72
|
+
searchHidden: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** What a source FAQ section sets. Every option defaults to what the himi_faq screen does. */
|
|
76
|
+
export interface FaqListOptions {
|
|
77
|
+
/** Show at most this many questions (the source's NumberOfFAQs). */
|
|
78
|
+
limit?: number;
|
|
79
|
+
/** false: no category headers. */
|
|
80
|
+
showCategories?: boolean;
|
|
81
|
+
/** Open the first question when the list first loads. */
|
|
82
|
+
firstOpen?: boolean;
|
|
83
|
+
/** Opening a question closes the others. */
|
|
84
|
+
oneAtATime?: boolean;
|
|
85
|
+
/** false: no search field. */
|
|
86
|
+
showSearch?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const PAGE_SIZE = 100;
|
|
90
|
+
|
|
91
|
+
/** Caps on the static pairs, matching `BRANDED_LITE_FAQ_LIMITS` in the app contract. The
|
|
92
|
+
* param is re-bounded here because a worker must not trust a descriptor it did not build. */
|
|
93
|
+
const STATIC_LIMITS = { pairs: 20, question: 200, answer: 1500 } as const;
|
|
94
|
+
const STATIC_CATEGORY: FaqCategory = { id: "himi-static-faq", title: "" };
|
|
95
|
+
|
|
96
|
+
/** The site's own FAQ pairs — questions it publishes as page sections rather than
|
|
97
|
+
* through the Wix FAQ app, carried in by `site analyze --apply` as the `staticFaq` onAppear
|
|
98
|
+
* param (a JSON string: action params are string-valued). They are the FALLBACK: shown only
|
|
99
|
+
* when the FAQ app yields no visible question, so an owner-edited Wix FAQ always wins. */
|
|
100
|
+
|
|
101
|
+
function parseStaticFaq(raw: unknown): FaqQuestion[] {
|
|
102
|
+
let pairs: unknown = raw;
|
|
103
|
+
if (typeof raw === "string") {
|
|
104
|
+
try {
|
|
105
|
+
pairs = JSON.parse(raw);
|
|
106
|
+
} catch {
|
|
107
|
+
// A malformed param is a DESCRIPTOR bug, not an empty FAQ: there is no fallback to
|
|
108
|
+
// offer, so the screen shows exactly what the Wix FAQ read says — its content, its
|
|
109
|
+
// empty card, or its error card — rather than pretending the site has no questions.
|
|
110
|
+
pairs = undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!Array.isArray(pairs)) return [];
|
|
114
|
+
const out: FaqQuestion[] = [];
|
|
115
|
+
for (const pair of pairs) {
|
|
116
|
+
if (out.length >= STATIC_LIMITS.pairs) break;
|
|
117
|
+
const row = pair && typeof pair === "object" ? pair as { q?: unknown; a?: unknown } : {};
|
|
118
|
+
const question = typeof row.q === "string" ? row.q.trim().slice(0, STATIC_LIMITS.question) : "";
|
|
119
|
+
const answer = typeof row.a === "string" ? row.a.trim().slice(0, STATIC_LIMITS.answer) : "";
|
|
120
|
+
if (!question || !answer) continue;
|
|
121
|
+
out.push({
|
|
122
|
+
id: `himi-static-faq-${out.length}`,
|
|
123
|
+
categoryId: STATIC_CATEGORY.id,
|
|
124
|
+
question,
|
|
125
|
+
answer,
|
|
126
|
+
// The site's own pairs are plain strings: there is no document to render.
|
|
127
|
+
answerJson: "",
|
|
128
|
+
hasAnswerJson: false,
|
|
129
|
+
sortOrder: out.length,
|
|
130
|
+
status: "VISIBLE",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function sortByWixOrder<T extends { id: string; sortOrder?: number }>(left: T, right: T): number {
|
|
137
|
+
const a = Number.isFinite(left.sortOrder) ? left.sortOrder! : Number.POSITIVE_INFINITY;
|
|
138
|
+
const b = Number.isFinite(right.sortOrder) ? right.sortOrder! : Number.POSITIVE_INFINITY;
|
|
139
|
+
return a - b || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function uniqueById<T extends { id: string }>(rows: T[]): T[] {
|
|
143
|
+
return [...new Map(rows.filter((row) => row.id).map((row) => [row.id, row])).values()];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function sectionsFor(state: Pick<FaqState, "categories" | "questions" | "query" | "expandedIds" | "otherTitle">, limit?: number): CategorySection[] {
|
|
147
|
+
const needle = state.query.trim().toLowerCase();
|
|
148
|
+
const visible = state.questions
|
|
149
|
+
.filter((row) => row.status.toUpperCase() !== "HIDDEN")
|
|
150
|
+
.filter((row) => !needle || `${row.question}\n${row.answer}`.toLowerCase().includes(needle))
|
|
151
|
+
.sort(sortByWixOrder)
|
|
152
|
+
.slice(0, limit ?? Number.POSITIVE_INFINITY);
|
|
153
|
+
const expanded = new Set(state.expandedIds);
|
|
154
|
+
const known = new Set(state.categories.map((category) => category.id));
|
|
155
|
+
const row = (question: FaqQuestion): QuestionRow => ({
|
|
156
|
+
id: question.id,
|
|
157
|
+
title: question.question,
|
|
158
|
+
answer: question.answer,
|
|
159
|
+
answerJson: question.answerJson,
|
|
160
|
+
hasAnswerJson: question.hasAnswerJson,
|
|
161
|
+
expanded: expanded.has(question.id),
|
|
162
|
+
});
|
|
163
|
+
const sections = state.categories
|
|
164
|
+
.slice()
|
|
165
|
+
.sort(sortByWixOrder)
|
|
166
|
+
.map((category) => ({
|
|
167
|
+
id: category.id,
|
|
168
|
+
title: category.title,
|
|
169
|
+
questions: visible.filter((question) => question.categoryId === category.id).map(row),
|
|
170
|
+
}))
|
|
171
|
+
.filter((section) => section.questions.length > 0);
|
|
172
|
+
const orphaned = visible.filter((question) => !known.has(question.categoryId));
|
|
173
|
+
if (orphaned.length) sections.push({ id: "other", title: state.otherTitle, questions: orphaned.map(row) });
|
|
174
|
+
return sections;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function ready(state: FaqState, options: FaqListOptions = {}): FaqState {
|
|
178
|
+
const sections = sectionsFor(state, options.limit);
|
|
179
|
+
const rows = sections.flatMap((section) => section.questions.map((question, index) => ({
|
|
180
|
+
...question,
|
|
181
|
+
categoryTitle: section.title,
|
|
182
|
+
// An untitled section (the static fallback's) has no header to show.
|
|
183
|
+
categoryHeaderHidden: options.showCategories === false || index !== 0 || !section.title,
|
|
184
|
+
})));
|
|
185
|
+
return {
|
|
186
|
+
...state,
|
|
187
|
+
status: "ready",
|
|
188
|
+
sections,
|
|
189
|
+
rows,
|
|
190
|
+
loadingHidden: true,
|
|
191
|
+
contentHidden: sections.length === 0,
|
|
192
|
+
emptyHidden: sections.length > 0,
|
|
193
|
+
errorHidden: true,
|
|
194
|
+
forbiddenHidden: true,
|
|
195
|
+
notInstalledHidden: true,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function failure(state: FaqState, status: FaqState["status"]): FaqState {
|
|
200
|
+
return {
|
|
201
|
+
...state,
|
|
202
|
+
status,
|
|
203
|
+
categories: [],
|
|
204
|
+
questions: [],
|
|
205
|
+
sections: [],
|
|
206
|
+
rows: [],
|
|
207
|
+
loadingHidden: true,
|
|
208
|
+
contentHidden: true,
|
|
209
|
+
emptyHidden: true,
|
|
210
|
+
errorHidden: status !== "error",
|
|
211
|
+
forbiddenHidden: status !== "forbidden",
|
|
212
|
+
notInstalledHidden: status !== "notInstalled",
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function httpStatus(error: unknown): number | undefined {
|
|
217
|
+
if (!error || typeof error !== "object") return undefined;
|
|
218
|
+
const row = error as { status?: unknown; statusCode?: unknown; response?: { status?: unknown }; message?: unknown };
|
|
219
|
+
for (const value of [row.status, row.statusCode, row.response?.status]) {
|
|
220
|
+
if (typeof value === "number") return value;
|
|
221
|
+
}
|
|
222
|
+
const match = typeof row.message === "string" ? row.message.match(/\b(403|428)\b/) : null;
|
|
223
|
+
return match ? Number(match[1]) : undefined;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function allCategories(): Promise<FaqCategory[]> {
|
|
227
|
+
const rows: FaqCategory[] = [];
|
|
228
|
+
const seen = new Set<string>();
|
|
229
|
+
let cursor = "";
|
|
230
|
+
do {
|
|
231
|
+
const response = await queryCategories({ query: { cursorPaging: { limit: PAGE_SIZE, ...(cursor ? { cursor } : {}) } } });
|
|
232
|
+
rows.push(...(response.categories ?? []).map((category: WixCategory) => ({
|
|
233
|
+
id: category.id ?? "",
|
|
234
|
+
title: (category.title ?? "").trim() || "Other",
|
|
235
|
+
...(typeof category.sortOrder === "number" ? { sortOrder: category.sortOrder } : {}),
|
|
236
|
+
})));
|
|
237
|
+
const next = response.pagingMetadata?.cursors?.next ?? "";
|
|
238
|
+
if (!next || seen.has(next)) break;
|
|
239
|
+
seen.add(next);
|
|
240
|
+
cursor = next;
|
|
241
|
+
} while (cursor);
|
|
242
|
+
return uniqueById(rows);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** The answer's text with every whitespace run collapsed to one space: PLAIN_TEXT and a document's plain text
|
|
246
|
+
* may separate blocks differently ("\n" vs "\n\n"), and that is not a garbled conversion, but a space inside
|
|
247
|
+
* the text is content ("New York" is not "NewYork"). */
|
|
248
|
+
const normalizeSpace = (text: string): string => text.replace(/\s+/g, " ").trim();
|
|
249
|
+
|
|
250
|
+
/** [rico] #3372 — the RICH_CONTENT answer as a document string, trusted ONLY when its text matches the
|
|
251
|
+
* PLAIN_TEXT answer. Wix converts a legacy DraftJS answer to Ricos unreliably, and the plain answer is
|
|
252
|
+
* the one a visitor has always been shown, so a document that disagrees with it is dropped. */
|
|
253
|
+
function richAnswer(plain: string, rich: unknown): string {
|
|
254
|
+
// richBody encodes FIRST, so a document past the viewer's limits (too deep included) is rejected without an
|
|
255
|
+
// unbounded plain-text walk, and gives "". Answers render in a list, so their media are list-sized.
|
|
256
|
+
const { bodyJson, bodyText } = richBody(rich, "", ROW_IMAGE_WIDTH);
|
|
257
|
+
return bodyJson && normalizeSpace(bodyText) === normalizeSpace(plain) ? bodyJson : "";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Every question entry in one content format, following THAT query's own cursors: a cursor belongs to the
|
|
261
|
+
* request that returned it, so the two formats never share one. */
|
|
262
|
+
async function entriesIn(contentFormat: "PLAIN_TEXT" | "RICH_CONTENT"): Promise<WixQuestionEntry[]> {
|
|
263
|
+
const rows: WixQuestionEntry[] = [];
|
|
264
|
+
const seen = new Set<string>();
|
|
265
|
+
let cursor = "";
|
|
266
|
+
do {
|
|
267
|
+
const response = await queryQuestionEntries({
|
|
268
|
+
query: {
|
|
269
|
+
cursorPaging: { limit: PAGE_SIZE, ...(cursor ? { cursor } : {}) },
|
|
270
|
+
filter: { status: { $in: ["VISIBLE", "UNKNOWN"] } },
|
|
271
|
+
},
|
|
272
|
+
contentFormat,
|
|
273
|
+
});
|
|
274
|
+
rows.push(...(response.questionEntries ?? []));
|
|
275
|
+
const next = response.pagingMetadata?.cursors?.next ?? "";
|
|
276
|
+
if (!next || seen.has(next)) break;
|
|
277
|
+
seen.add(next);
|
|
278
|
+
cursor = next;
|
|
279
|
+
} while (cursor);
|
|
280
|
+
return rows;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function allQuestions(): Promise<FaqQuestion[]> {
|
|
284
|
+
// Both formats are read in parallel, each paged on its own. PLAIN_TEXT is the list; a RICH_CONTENT read
|
|
285
|
+
// that fails only costs the documents — every answer keeps its plain text.
|
|
286
|
+
const [plain, rich] = await Promise.all([
|
|
287
|
+
entriesIn("PLAIN_TEXT"),
|
|
288
|
+
entriesIn("RICH_CONTENT").catch(() => [] as WixQuestionEntry[]),
|
|
289
|
+
]);
|
|
290
|
+
const richById = new Map(rich.map((question: WixQuestionEntry) => [question.id ?? "", question.richContent]));
|
|
291
|
+
const rows = plain.map((question: WixQuestionEntry) => {
|
|
292
|
+
const answer = (question.plainText ?? "").trim();
|
|
293
|
+
const answerJson = richAnswer(answer, richById.get(question.id ?? ""));
|
|
294
|
+
return {
|
|
295
|
+
id: question.id ?? "",
|
|
296
|
+
categoryId: question.categoryId ?? "",
|
|
297
|
+
question: (question.question ?? "").trim(),
|
|
298
|
+
answer,
|
|
299
|
+
answerJson,
|
|
300
|
+
hasAnswerJson: answerJson !== "",
|
|
301
|
+
...(typeof question.sortOrder === "number" ? { sortOrder: question.sortOrder } : {}),
|
|
302
|
+
status: question.status ?? "UNKNOWN",
|
|
303
|
+
};
|
|
304
|
+
}).filter((question) =>
|
|
305
|
+
question.id && question.question && question.status.toUpperCase() !== "HIDDEN",
|
|
306
|
+
);
|
|
307
|
+
return uniqueById(rows);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const INITIAL: FaqState = {
|
|
311
|
+
status: "loading",
|
|
312
|
+
categories: [],
|
|
313
|
+
questions: [],
|
|
314
|
+
sections: [],
|
|
315
|
+
rows: [],
|
|
316
|
+
query: "",
|
|
317
|
+
expandedIds: [],
|
|
318
|
+
otherTitle: "Other",
|
|
319
|
+
loadingHidden: false,
|
|
320
|
+
contentHidden: true,
|
|
321
|
+
emptyHidden: true,
|
|
322
|
+
errorHidden: true,
|
|
323
|
+
forbiddenHidden: true,
|
|
324
|
+
notInstalledHidden: true,
|
|
325
|
+
searchHidden: false,
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export function registerFaqList(serviceName: string, options: FaqListOptions = {}) {
|
|
329
|
+
/** The site's own FAQ pairs: the FALLBACK shown only when the FAQ app yields no visible question (see parseStaticFaq). */
|
|
330
|
+
let staticQuestions: FaqQuestion[] = [];
|
|
331
|
+
const initial: FaqState = { ...INITIAL, searchHidden: options.showSearch === false };
|
|
332
|
+
let latestState = initial;
|
|
333
|
+
let loadGeneration = 0;
|
|
334
|
+
/** The reader opened or closed a question: `firstOpen` then stops deciding what is open. */
|
|
335
|
+
let touched = false;
|
|
336
|
+
|
|
337
|
+
const settle = (state: FaqState): FaqState => ready(state, options);
|
|
338
|
+
|
|
339
|
+
/** The site's pairs as a ready state, or undefined when there are none to fall back to. */
|
|
340
|
+
function staticFallback(state: FaqState): FaqState | undefined {
|
|
341
|
+
if (!staticQuestions.length) return undefined;
|
|
342
|
+
return settle({ ...state, categories: [STATIC_CATEGORY], questions: staticQuestions });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function commit(state: FaqState): FaqState {
|
|
346
|
+
latestState = state;
|
|
347
|
+
return state;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function loadFaq(state: FaqState, arg?: { otherCategory?: string; staticFaq?: unknown }): Promise<FaqState> {
|
|
351
|
+
latestState = state;
|
|
352
|
+
// Only when the caller passed the param: `retry` is dispatched with no params and must keep
|
|
353
|
+
// the pairs the screen's onAppear delivered.
|
|
354
|
+
if (arg && "staticFaq" in arg) staticQuestions = parseStaticFaq(arg.staticFaq);
|
|
355
|
+
const generation = ++loadGeneration;
|
|
356
|
+
try {
|
|
357
|
+
const [categories, questions] = await Promise.all([allCategories(), allQuestions()]);
|
|
358
|
+
if (generation !== loadGeneration) return latestState;
|
|
359
|
+
const otherTitle = String(arg?.otherCategory ?? latestState.otherTitle).trim() || latestState.otherTitle;
|
|
360
|
+
let live = settle({ ...latestState, categories, questions, otherTitle });
|
|
361
|
+
const first = live.sections[0]?.questions[0]?.id;
|
|
362
|
+
if (options.firstOpen && !touched && !live.expandedIds.length && first) live = settle({ ...live, expandedIds: [first] });
|
|
363
|
+
// The Wix FAQ app answered but holds nothing a visitor can see — the site's own pairs,
|
|
364
|
+
// when it has any, instead of an empty state over a site whose FAQ is right there.
|
|
365
|
+
if (questions.length === 0) return commit(staticFallback(live) ?? live);
|
|
366
|
+
return commit(live);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
if (generation !== loadGeneration) return latestState;
|
|
369
|
+
console.warn("faq_list: the questions could not be read", error);
|
|
370
|
+
const status = httpStatus(error);
|
|
371
|
+
// No FAQ app (428), no visitor access (403) or a failed read: a site whose FAQ is page
|
|
372
|
+
// content still has an FAQ to show, so its pairs replace the failure card.
|
|
373
|
+
const fallback = staticFallback(latestState);
|
|
374
|
+
if (fallback) return commit(fallback);
|
|
375
|
+
return commit(failure(latestState, status === 403 ? "forbidden" : status === 428 ? "notInstalled" : "error"));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return defineService(serviceName, {
|
|
380
|
+
state: initial,
|
|
381
|
+
actions: {
|
|
382
|
+
load: loadFaq,
|
|
383
|
+
retry: loadFaq,
|
|
384
|
+
search: (state: FaqState, arg?: { value?: string }) => commit(settle({ ...state, query: String(arg?.value ?? "").slice(0, 256) })),
|
|
385
|
+
toggle: (state: FaqState, arg?: { id?: string }) => {
|
|
386
|
+
const id = String(arg?.id ?? "");
|
|
387
|
+
if (!id || !state.questions.some((question) => question.id === id)) return state;
|
|
388
|
+
touched = true;
|
|
389
|
+
const open = state.expandedIds.includes(id);
|
|
390
|
+
const expandedIds = open
|
|
391
|
+
? state.expandedIds.filter((candidate) => candidate !== id)
|
|
392
|
+
: options.oneAtATime ? [id] : [...state.expandedIds, id];
|
|
393
|
+
return commit(settle({ ...state, expandedIds }));
|
|
394
|
+
},
|
|
395
|
+
// [rico] #3372 — an answer RichContent's on_link: `{ url }` of the tapped link. Only http(s), mailto and
|
|
396
|
+
// tel links reach open_url; the FAQ has no message line, so a refused link simply does nothing.
|
|
397
|
+
openLink: async (state: FaqState, arg?: unknown) => {
|
|
398
|
+
await openRichLink(arg);
|
|
399
|
+
return state;
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export { sectionsFor, httpStatus, parseStaticFaq };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// A page's groups section as a registrable service: the One App groups list, driven by the source section's settings.
|
|
2
|
+
// groupIds -> only those groups, in that order (unset: every group the site publishes),
|
|
3
|
+
// limit -> at most N groups, and `noMore` is false when there are more (the section's "View All" button shows then).
|
|
4
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe groups-list.json).
|
|
5
|
+
import { defineService } from "@himalaya/state";
|
|
6
|
+
import { queryGroups, type WixGroup } from "@himalaya/wix-groups";
|
|
7
|
+
import { groupImage } from "./himi-media.js";
|
|
8
|
+
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
9
|
+
import { groupMemberCount } from "./group-member-count.js";
|
|
10
|
+
import { descriptionBody } from "./rich-body.js";
|
|
11
|
+
|
|
12
|
+
export interface GroupsSectionOptions {
|
|
13
|
+
/** Show only these groups, in this order. */
|
|
14
|
+
groupIds?: string[];
|
|
15
|
+
/** Show at most this many groups. */
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GroupRow {
|
|
20
|
+
id: string; title: string; subtitle: string; meta: string; hasMeta: boolean; noMeta: boolean;
|
|
21
|
+
image: string; initial: string; hasImage: boolean; noImage: boolean;
|
|
22
|
+
/** The group screen a row opens; the row binds `id` as its nav param. */
|
|
23
|
+
detailScreenId: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GroupsSectionState {
|
|
27
|
+
status: "loading" | "ready" | "error";
|
|
28
|
+
rows: GroupRow[];
|
|
29
|
+
emptyText: string;
|
|
30
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean; noEmpty: boolean;
|
|
31
|
+
/** false when the site has more groups than the section shows. */
|
|
32
|
+
noMore: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The most groups one query reads. */
|
|
36
|
+
/** The row's 72pt thumbnail at 3x: the shared list size (1000px) would fetch and decode far more pixels than it shows. */
|
|
37
|
+
const GROUP_THUMB = { width: 216, height: 216, quality: 85 };
|
|
38
|
+
const QUERY_LIMIT = 100;
|
|
39
|
+
/** The most groups one section reads (10 pages): a site beyond it is shown as "has more" instead of silently cut. */
|
|
40
|
+
const MAX_GROUPS = 1000;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Pages of groups, read by offset until the section has what it needs: every chosen group, one more than its limit (enough to know
|
|
44
|
+
* there is more), or the end of the site's groups. `truncated` is true only when the cap stopped the read with groups left.
|
|
45
|
+
*/
|
|
46
|
+
async function readGroups(chosen: string[] | undefined, limit: number | undefined): Promise<{ groups: WixGroup[]; truncated: boolean }> {
|
|
47
|
+
const groups: WixGroup[] = [];
|
|
48
|
+
for (let offset = 0; ; offset = groups.length) {
|
|
49
|
+
const response = await queryGroups({ paging: { limit: QUERY_LIMIT, offset } });
|
|
50
|
+
const page = (response.groups ?? []) as WixGroup[];
|
|
51
|
+
groups.push(...page);
|
|
52
|
+
const total = response.metaData?.total;
|
|
53
|
+
if (page.length < QUERY_LIMIT || (typeof total === "number" && groups.length >= total)) return { groups, truncated: false };
|
|
54
|
+
if (chosen?.length ? chosen.every((id) => groups.some((group) => group.id === id)) : limit !== undefined && groups.length > limit) return { groups, truncated: false };
|
|
55
|
+
if (groups.length >= MAX_GROUPS) return { groups, truncated: true };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function snippet(value: string): string {
|
|
60
|
+
const text = value.replace(/\s+/g, " ");
|
|
61
|
+
return text.length > 140 ? `${text.slice(0, 139).trimEnd()}…` : text;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function groupRow(group: WixGroup): GroupRow {
|
|
65
|
+
const title = (group.name || copyParam("groups.groupFallbackName", "Group")).trim();
|
|
66
|
+
const count = group.membersCount ?? group.memberCount;
|
|
67
|
+
const image = groupImage(group, GROUP_THUMB);
|
|
68
|
+
const teaser = descriptionBody(group.teaser).bodyText;
|
|
69
|
+
const body = descriptionBody(group.description, teaser).bodyText;
|
|
70
|
+
const meta = count == null ? "" : groupMemberCount(count);
|
|
71
|
+
return {
|
|
72
|
+
id: group.id || title, title,
|
|
73
|
+
subtitle: snippet(teaser) || snippet(body) || copyParam("groups.subtitleFallback", "Join the conversation."),
|
|
74
|
+
meta, hasMeta: !!meta, noMeta: !meta,
|
|
75
|
+
image, initial: (title[0] || "G").toUpperCase(), hasImage: Boolean(image), noImage: !image,
|
|
76
|
+
detailScreenId: "himi_group",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function registerGroupsSection(serviceName: string, options: GroupsSectionOptions = {}) {
|
|
81
|
+
const view = (status: GroupsSectionState["status"], rows: GroupRow[], more: boolean): GroupsSectionState => ({
|
|
82
|
+
status, rows,
|
|
83
|
+
emptyText: status === "ready" && !rows.length ? copyParam("groups.emptyText", "No groups are published yet.") : "",
|
|
84
|
+
notLoading: status !== "loading", notErrored: status !== "error",
|
|
85
|
+
noRows: !rows.length, noEmpty: !(status === "ready" && !rows.length),
|
|
86
|
+
noMore: !more,
|
|
87
|
+
});
|
|
88
|
+
return defineService<GroupsSectionState, { load: (state: GroupsSectionState, arg?: unknown) => Promise<GroupsSectionState> }>(serviceName, {
|
|
89
|
+
state: view("loading", [], false),
|
|
90
|
+
actions: {
|
|
91
|
+
load: async (_state, arg) => {
|
|
92
|
+
stashCopy(arg);
|
|
93
|
+
try {
|
|
94
|
+
const read = await readGroups(options.groupIds, options.limit);
|
|
95
|
+
let groups = read.groups;
|
|
96
|
+
if (options.groupIds?.length) {
|
|
97
|
+
// The chosen groups, in the source's order; one that no longer exists is simply absent.
|
|
98
|
+
const byId = new Map(groups.map((group) => [group.id, group]));
|
|
99
|
+
groups = options.groupIds.flatMap((id) => byId.get(id) ?? []);
|
|
100
|
+
}
|
|
101
|
+
const shown = options.limit !== undefined ? groups.slice(0, options.limit) : groups;
|
|
102
|
+
return view("ready", shown.map(groupRow), read.truncated || shown.length < groups.length);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.warn("groups_section: the groups could not be read", error);
|
|
105
|
+
return view("error", [], false);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -110,13 +110,21 @@ async function readBadges(ids: string[], tenant: string): Promise<Map<string, Ba
|
|
|
110
110
|
|
|
111
111
|
/** memberId → "Active 11h ago" etc., for the members the One App service knows and has something to say about.
|
|
112
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>> {
|
|
113
|
+
export async function readActivity(ids: string[]): Promise<Map<string, string>> {
|
|
114
|
+
return (await readMemberActivity(ids)).texts;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The same read, plus the members the service answered for: one it answered for with nothing to say (never opened the app) is
|
|
118
|
+
* known and shows no line, which is different from one it did not answer for at all. */
|
|
119
|
+
export async function readMemberActivity(ids: string[]): Promise<{ texts: Map<string, string>; known: Set<string> }> {
|
|
114
120
|
const texts = new Map<string, string>();
|
|
121
|
+
const known = new Set<string>();
|
|
115
122
|
for (const activity of await queryMemberActivity(ids)) {
|
|
123
|
+
known.add(activity.id);
|
|
116
124
|
const text = activityText(activity);
|
|
117
125
|
if (text) texts.set(activity.id, text);
|
|
118
126
|
}
|
|
119
|
-
return texts;
|
|
127
|
+
return { texts, known };
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
async function readFollowed(ids: string[], access: ReadAccess): Promise<Set<string>> {
|
|
@@ -10,7 +10,7 @@ import { createCollectionQuery } from "./collection-query.js";
|
|
|
10
10
|
import { readAccess, assertReadAccess, readAccessDenied, type ReadAccess } from "./member-read.js";
|
|
11
11
|
import { memberAccessChanged } from "./member-access.js";
|
|
12
12
|
// The paged badge-assignments read (POST /badges/v4/assignments/query; the generated listMembersBadgeIds route answers 404 live).
|
|
13
|
-
import { badgesByMember } from "./member-row-extras.js";
|
|
13
|
+
import { badgesByMember, readMemberActivity } from "./member-row-extras.js";
|
|
14
14
|
import { withEmptyFlags } from "./empty-flags.js";
|
|
15
15
|
import { stashCopy, copyParam, copyTemplate, copyPlural } from "./himi-copy.js";
|
|
16
16
|
import { activityLine, badgeToken } from "./members-directory-view.js";
|
|
@@ -62,7 +62,7 @@ function name(m: WixMember): string {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/** What the page's extra reads found: unknown stays absent. */
|
|
65
|
-
interface Extras { badges: Map<string, Chip[]>; following: Set<string> | undefined }
|
|
65
|
+
interface Extras { badges: Map<string, Chip[]>; following: Set<string> | undefined; /** "Active 4h ago" / "Last seen …" per member from the One App members service, and the members it answered for. */ activity: { texts: Map<string, string>; known: Set<string> } | undefined }
|
|
66
66
|
|
|
67
67
|
export function registerMembersDirectory(serviceName: string, options: MembersDirectoryOptions = {}) {
|
|
68
68
|
const letterBands = options.letterBands !== false;
|
|
@@ -98,13 +98,15 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
|
|
|
98
98
|
async function extrasFor(members: WixMember[], member: boolean): Promise<Extras> {
|
|
99
99
|
const ids = members.map((m) => m.id);
|
|
100
100
|
const badges = new Map<string, Chip[]>();
|
|
101
|
-
const [badgeRead, followRead] = await Promise.allSettled([
|
|
101
|
+
const [badgeRead, followRead, activityRead] = await Promise.allSettled([
|
|
102
102
|
options.showBadges ? Promise.all([badgeDefinitions(), badgesByMember(ids)]) : Promise.resolve(undefined),
|
|
103
103
|
options.showFollow && member ? getMyFollowing(ids) : Promise.resolve(undefined),
|
|
104
|
+
options.showActivity ? readMemberActivity(ids) : Promise.resolve(undefined),
|
|
104
105
|
]);
|
|
105
106
|
// A badge or follow read that fails leaves its chips off the rows; the list itself still loads.
|
|
106
107
|
if (badgeRead.status === "rejected") console.warn("members_directory: the badges could not be read", badgeRead.reason);
|
|
107
108
|
if (followRead.status === "rejected") console.warn("members_directory: the follow state could not be read", followRead.reason);
|
|
109
|
+
if (activityRead.status === "rejected") console.warn("members_directory: the activity could not be read", activityRead.reason);
|
|
108
110
|
if (badgeRead.status === "fulfilled" && badgeRead.value) {
|
|
109
111
|
const [catalog, held] = badgeRead.value;
|
|
110
112
|
for (const [memberId, badgeIds] of held) {
|
|
@@ -112,13 +114,15 @@ export function registerMembersDirectory(serviceName: string, options: MembersDi
|
|
|
112
114
|
if (chips.length) badges.set(memberId, chips);
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
|
-
return { badges, following: followRead.status === "fulfilled" ? followRead.value : undefined };
|
|
117
|
+
return { badges, following: followRead.status === "fulfilled" ? followRead.value : undefined, activity: activityRead.status === "fulfilled" ? activityRead.value : undefined };
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
function row(m: WixMember, extras: Extras, now: number): Row {
|
|
119
121
|
const n = name(m);
|
|
120
122
|
const role = options.showRole ? copyParam("members.roleMember", "Member") : "";
|
|
121
|
-
|
|
123
|
+
// The One App members service answers "Active 4h ago" / "Last seen …" for the page. A member it answered for with nothing to say shows no line;
|
|
124
|
+
// the login date is only for a member it did not answer for (an older native build refuses the route).
|
|
125
|
+
const activity = !options.showActivity ? "" : extras.activity?.known.has(m.id) ? extras.activity.texts.get(m.id) ?? "" : activityLine(m.lastLoginDate, now);
|
|
122
126
|
const roleLine = [role, activity].filter(Boolean).join(" · ");
|
|
123
127
|
const chips = extras.badges.get(m.id) ?? [];
|
|
124
128
|
const shown = chips.slice(0, BADGE_SLOTS);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// A page's products section as a registrable service: the first products of a source collection, as tiles that open the product.
|
|
2
|
+
// categoryId -> the source section's collection (unset: the whole catalog, the "All Products" collection),
|
|
3
|
+
// limit -> how many tiles (the section is a rail or a short grid, not the shop); `noMore` is false when the collection has more,
|
|
4
|
+
// which is when the section's See All button (to the shop, on this collection) shows.
|
|
5
|
+
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipes products-carousel / products-grid).
|
|
6
|
+
import { defineService } from "@himalaya/state";
|
|
7
|
+
import { searchStoreProducts, productImage, productPrice, type StoreProduct } from "./himi-store.js";
|
|
8
|
+
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
9
|
+
|
|
10
|
+
export interface ProductsSectionOptions {
|
|
11
|
+
/** The source collection's id; unset reads the whole catalog. */
|
|
12
|
+
categoryId?: string;
|
|
13
|
+
/** How many products to show. */
|
|
14
|
+
limit?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ProductRow {
|
|
18
|
+
id: string; name: string; price: string;
|
|
19
|
+
image: string; initial: string; hasImage: boolean; noImage: boolean;
|
|
20
|
+
/** The product screen a tile opens; the tile binds `id` as its nav param. */
|
|
21
|
+
detailScreenId: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ProductsSectionState {
|
|
25
|
+
status: "loading" | "ready" | "error";
|
|
26
|
+
rows: ProductRow[];
|
|
27
|
+
emptyText: string;
|
|
28
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean; noEmpty: boolean;
|
|
29
|
+
/** false when the collection has more products than the section shows. */
|
|
30
|
+
noMore: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const DEFAULT_LIMIT = 8;
|
|
34
|
+
/** A 156pt tile at 3x: the shared list size (1000px) would ship far more pixels than a rail shows. */
|
|
35
|
+
const TILE_IMAGE = { width: 480, height: 480, quality: 85 };
|
|
36
|
+
|
|
37
|
+
function rowOf(product: StoreProduct): ProductRow {
|
|
38
|
+
const name = (product.name ?? "").trim();
|
|
39
|
+
const image = productImage(product, TILE_IMAGE);
|
|
40
|
+
return {
|
|
41
|
+
id: product.id ?? "", name, price: productPrice(product),
|
|
42
|
+
image, initial: (name[0] ?? "#").toUpperCase(), hasImage: !!image, noImage: !image,
|
|
43
|
+
detailScreenId: "himi_product",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function registerProductsSection(serviceName: string, options: ProductsSectionOptions = {}) {
|
|
48
|
+
const limit = options.limit ?? DEFAULT_LIMIT;
|
|
49
|
+
const view = (status: ProductsSectionState["status"], rows: ProductRow[], more: boolean): ProductsSectionState => ({
|
|
50
|
+
status, rows,
|
|
51
|
+
emptyText: status === "ready" && !rows.length
|
|
52
|
+
? options.categoryId ? copyParam("shop.emptyCategoryText", "No products in this category yet.") : copyParam("shop.emptyText", "No products are published yet.")
|
|
53
|
+
: "",
|
|
54
|
+
notLoading: status !== "loading", notErrored: status !== "error",
|
|
55
|
+
noRows: !rows.length, noEmpty: !(status === "ready" && !rows.length),
|
|
56
|
+
noMore: !more,
|
|
57
|
+
});
|
|
58
|
+
return defineService<ProductsSectionState, { load: (state: ProductsSectionState, arg?: unknown) => Promise<ProductsSectionState> }>(serviceName, {
|
|
59
|
+
state: view("loading", [], false),
|
|
60
|
+
actions: {
|
|
61
|
+
load: async (_state, arg) => {
|
|
62
|
+
stashCopy(arg);
|
|
63
|
+
try {
|
|
64
|
+
const response = await searchStoreProducts({ limit, ...(options.categoryId ? { categoryId: options.categoryId } : {}) });
|
|
65
|
+
const rows = (response.products ?? []).filter((product) => product.id).slice(0, limit).map(rowOf);
|
|
66
|
+
const total = response.pagingMetadata?.total;
|
|
67
|
+
const more = response.pagingMetadata?.hasNext === true || (typeof total === "number" && total > rows.length);
|
|
68
|
+
return view("ready", rows, more);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.warn("products_section: the products could not be read", error);
|
|
71
|
+
return view("error", [], false);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|