@wix/himalaya-cli 0.1954.0 → 0.1955.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.
Files changed (42) hide show
  1. package/dist/cli.mjs +137 -71
  2. package/guides/one-app-section-mappings.md +1 -1
  3. package/guides/one-app-to-himi-app.md +11 -7
  4. package/package.json +2 -2
  5. package/templates/branded-lite/l10n/ar.json +5 -0
  6. package/templates/branded-lite/l10n/cs.json +5 -0
  7. package/templates/branded-lite/l10n/da.json +5 -0
  8. package/templates/branded-lite/l10n/de.json +5 -0
  9. package/templates/branded-lite/l10n/el.json +5 -0
  10. package/templates/branded-lite/l10n/es.json +5 -0
  11. package/templates/branded-lite/l10n/fi.json +5 -0
  12. package/templates/branded-lite/l10n/fr.json +5 -0
  13. package/templates/branded-lite/l10n/he.json +5 -0
  14. package/templates/branded-lite/l10n/hu.json +5 -0
  15. package/templates/branded-lite/l10n/id.json +5 -0
  16. package/templates/branded-lite/l10n/it.json +5 -0
  17. package/templates/branded-lite/l10n/ja.json +5 -0
  18. package/templates/branded-lite/l10n/ko.json +5 -0
  19. package/templates/branded-lite/l10n/lt.json +5 -0
  20. package/templates/branded-lite/l10n/nl.json +5 -0
  21. package/templates/branded-lite/l10n/no.json +5 -0
  22. package/templates/branded-lite/l10n/pl.json +5 -0
  23. package/templates/branded-lite/l10n/pt.json +5 -0
  24. package/templates/branded-lite/l10n/ru.json +5 -0
  25. package/templates/branded-lite/l10n/sv.json +5 -0
  26. package/templates/branded-lite/l10n/th.json +5 -0
  27. package/templates/branded-lite/l10n/tr.json +5 -0
  28. package/templates/branded-lite/l10n/uk.json +5 -0
  29. package/templates/branded-lite/l10n/vi.json +5 -0
  30. package/templates/branded-lite/l10n/zh.json +5 -0
  31. package/templates/branded-lite/recipes/blog-carousel-classic.json +335 -0
  32. package/templates/branded-lite/recipes/blog-carousel-full.json +374 -0
  33. package/templates/branded-lite/recipes/events-inline-carousel.json +308 -0
  34. package/templates/branded-lite/recipes/galleries-carousel.json +51 -2
  35. package/templates/branded-lite/recipes/galleries-collage.json +51 -2
  36. package/templates/branded-lite/recipes/galleries-list.json +51 -2
  37. package/templates/branded-lite/recipes/groups-cards.json +194 -86
  38. package/templates/branded-lite/recipes/groups-list.json +209 -62
  39. package/templates/branded-lite/tier5-src/_shared/blog-list.ts +5 -1
  40. package/templates/branded-lite/tier5-src/_shared/galleries-section.ts +70 -23
  41. package/templates/branded-lite/tier5-src/_shared/groups-section.ts +297 -26
  42. package/templates/branded-lite/recipes/blog-hero.json +0 -95
@@ -1,13 +1,25 @@
1
1
  // A page's groups section as a registrable service: the One App groups list, driven by the source section's settings.
2
2
  // groupIds -> only those groups, in that order (unset: every group the site publishes),
3
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";
4
+ // Each group has the source's join control, from the group's own policy and the viewer's membership (listMemberships, as My Groups reads it):
5
+ // an open public group -> "Join group", joined in place for a member;
6
+ // a private group, or one whose access needs an admin's approval -> "Request to join", which opens the group's screen (Wix has no
7
+ // confirmed public call that submits a join request: the group screen is where its policy is explained);
8
+ // a group the member joined or asked to join -> "Joined" / "Pending request", a status rather than a control.
9
+ // A visitor's tap signs in first and then opens the group (the shared member-screen opener). A secret group is listed only to its members.
10
+ // The list's header Search (the source's `groups.openGroupsListSearch`) opens a search field in the section: it finds a group by name or
11
+ // teaser among every group the section may show, not only the first `limit` (himi_groups hides its own search on a short list).
12
+ // A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipes groups-list.json, groups-cards.json).
13
+ import { defineService, navigate, type ServiceHandle } from "@himalaya/state";
14
+ import { hostSessionFromGlobal } from "@himalaya/iap";
15
+ import { joinGroup, listMemberships, queryGroups, type WixGroup } from "@himalaya/wix-groups";
16
+ import { getMyMember } from "@himalaya/wix-members";
7
17
  import { groupImage } from "./himi-media.js";
8
18
  import { copyParam, stashCopy } from "./himi-copy.js";
9
19
  import { groupMemberCount } from "./group-member-count.js";
10
20
  import { descriptionBody } from "./rich-body.js";
21
+ import { memberIdentity } from "./himi-account.js";
22
+ import { CONTINUATION_BUDGET_MS, memberScreenNav, within } from "./member-screen.js";
11
23
 
12
24
  export interface GroupsSectionOptions {
13
25
  /** Show only these groups, in this order. */
@@ -18,11 +30,18 @@ export interface GroupsSectionOptions {
18
30
  cards?: boolean;
19
31
  }
20
32
 
33
+ /** What the viewer can do with a group: join it here, ask to join it, or nothing (already a member, or the request is pending). */
34
+ export type GroupAction = "join" | "request" | "open" | "none";
35
+
21
36
  export interface GroupRow {
22
37
  id: string; title: string; subtitle: string; meta: string; hasMeta: boolean; noMeta: boolean;
23
38
  image: string; initial: string; hasImage: boolean; noImage: boolean;
24
39
  /** The group screen a row opens; the row binds `id` as its nav param. */
25
40
  detailScreenId: string;
41
+ action: GroupAction;
42
+ /** The join control's label ("Join group", "Request to join"), and the status shown instead of it ("Joined", "Pending request"). */
43
+ actionLabel: string; noAction: boolean;
44
+ statusLabel: string; noStatus: boolean;
26
45
  }
27
46
 
28
47
  export interface GroupsSectionState {
@@ -32,32 +51,112 @@ export interface GroupsSectionState {
32
51
  notLoading: boolean; notErrored: boolean; noRows: boolean; noEmpty: boolean;
33
52
  /** false when the site has more groups than the section shows. */
34
53
  noMore: boolean;
54
+ /** What the last join did, when it did not simply succeed ("" otherwise). */
55
+ message: string; noMessage: boolean;
56
+ /** The search field: hidden until the header's Search opens it, and what was typed in it. */
57
+ noSearch: boolean; query: string;
35
58
  }
36
59
 
37
- /** The most groups one query reads. */
38
60
  /** The row's 72pt thumbnail at 3x: the shared list size (1000px) would fetch and decode far more pixels than it shows. */
39
61
  const GROUP_THUMB = { width: 216, height: 216, quality: 85 };
40
62
  /** A card's 240pt-wide cover at 3x, in the 16:9 the card crops it to. */
41
63
  const GROUP_CARD = { width: 720, height: 405, quality: 85 };
64
+ /** The most groups one query reads. */
42
65
  const QUERY_LIMIT = 100;
43
66
  /** The most groups one section reads (10 pages): a site beyond it is shown as "has more" instead of silently cut. */
44
67
  const MAX_GROUPS = 1000;
68
+ /** The most memberships one read returns (the API's own cap). */
69
+ const MEMBERSHIP_LIMIT = 100;
45
70
 
46
71
  /**
47
72
  * Pages of groups, read by offset until the section has what it needs: every chosen group, one more than its limit (enough to know
48
- * there is more), or the end of the site's groups. `truncated` is true only when the cap stopped the read with groups left.
73
+ * there is more), or the end of the site's groups. `truncated` is true only when the cap stopped the read with groups left; `ended`
74
+ * when the read reached the end of the site's groups.
49
75
  */
50
- async function readGroups(chosen: string[] | undefined, limit: number | undefined): Promise<{ groups: WixGroup[]; truncated: boolean }> {
76
+ async function readGroups(chosen: string[] | undefined, limit: number | undefined): Promise<{ groups: WixGroup[]; truncated: boolean; ended: boolean }> {
51
77
  const groups: WixGroup[] = [];
52
78
  for (let offset = 0; ; offset = groups.length) {
53
79
  const response = await queryGroups({ paging: { limit: QUERY_LIMIT, offset } });
54
80
  const page = (response.groups ?? []) as WixGroup[];
55
81
  groups.push(...page);
56
82
  const total = response.metaData?.total;
57
- if (page.length < QUERY_LIMIT || (typeof total === "number" && groups.length >= total)) return { groups, truncated: false };
58
- if (chosen?.length ? chosen.every((id) => groups.some((group) => group.id === id)) : limit !== undefined && groups.length > limit) return { groups, truncated: false };
59
- if (groups.length >= MAX_GROUPS) return { groups, truncated: true };
83
+ if (page.length < QUERY_LIMIT || (typeof total === "number" && groups.length >= total)) return { groups, truncated: false, ended: true };
84
+ if (chosen?.length ? chosen.every((id) => groups.some((group) => group.id === id)) : limit !== undefined && groups.length > limit) return { groups, truncated: false, ended: false };
85
+ if (groups.length >= MAX_GROUPS) return { groups, truncated: true, ended: false };
86
+ }
87
+ }
88
+
89
+ /** Whether a group matches what the reader typed: its name, teaser or description contains it, ignoring case (a row with no teaser
90
+ * shows its description, so what the reader sees is what is searched). */
91
+ export function matchesQuery(group: WixGroup, query: string): boolean {
92
+ const needle = query.trim().toLowerCase();
93
+ return !needle || searchText(group).includes(needle);
94
+ }
95
+
96
+ /** A group's searchable text, parsed once per group read (a description is rich content: re-parsing every group on every keystroke
97
+ * would redo up to MAX_GROUPS Ricos conversions per search). */
98
+ const searchTexts = new WeakMap<WixGroup, string>();
99
+ function searchText(group: WixGroup): string {
100
+ let text = searchTexts.get(group);
101
+ if (text === undefined) {
102
+ text = [group.name ?? "", descriptionBody(group.teaser).bodyText, descriptionBody(group.description).bodyText].join(" ").toLowerCase();
103
+ searchTexts.set(group, text);
104
+ }
105
+ return text;
106
+ }
107
+
108
+ /** The signed-in member's group memberships by group id (JOINED or PENDING). Empty for a visitor, and when the read fails: the
109
+ * rows then offer Join, and Wix answers a join by a member with the group's own policy. */
110
+ async function readMemberships(signedIn: boolean): Promise<Map<string, string>> {
111
+ const byGroup = new Map<string, string>();
112
+ if (!signedIn) return byGroup;
113
+ try {
114
+ const memberId = String((await getMyMember())?.member?.id ?? "");
115
+ if (!memberId) return byGroup;
116
+ // Page by offset, as far as the groups the section reads: a member of more than one page of groups keeps every status.
117
+ for (let offset = 0; offset < MAX_GROUPS; offset += MEMBERSHIP_LIMIT) {
118
+ const page = (await listMemberships(memberId, { limit: MEMBERSHIP_LIMIT, offset })).memberships ?? [];
119
+ for (const membership of page) {
120
+ const status = String(membership.status ?? "").toUpperCase();
121
+ if (membership.groupId && (status === "JOINED" || status === "PENDING")) byGroup.set(membership.groupId, status);
122
+ }
123
+ if (page.length < MEMBERSHIP_LIMIT) break;
124
+ }
125
+ } catch (error) {
126
+ console.warn("groups_section: the member's groups could not be read", error);
127
+ }
128
+ return byGroup;
129
+ }
130
+
131
+ const privacyOf = (group: WixGroup): string => String(group.privacyStatus ?? "").toUpperCase();
132
+
133
+ const restrictionOf = (group: WixGroup): string =>
134
+ String((group as { accessRestriction?: { type?: unknown } }).accessRestriction?.type ?? "").toUpperCase();
135
+
136
+ /** Whether joining takes a request: a private group, or one whose access an admin approves. */
137
+ export function needsApproval(group: WixGroup): boolean {
138
+ return privacyOf(group) === "PRIVATE" || restrictionOf(group) === "ADMIN_APPROVAL";
139
+ }
140
+
141
+ /** Whether joining needs something the app cannot give in place (a paid plan, an event ticket): the group screen explains it. */
142
+ export function joinsElsewhere(group: WixGroup): boolean {
143
+ const restriction = restrictionOf(group);
144
+ return !!restriction && restriction !== "UNKNOWN" && restriction !== "ADMIN_APPROVAL";
145
+ }
146
+
147
+ /** The row's control and status for this viewer: a membership wins over the group's policy. */
148
+ export function joinState(group: WixGroup, membership: string | undefined): Pick<GroupRow, "action" | "actionLabel" | "noAction" | "statusLabel" | "noStatus"> {
149
+ // The words are the stock keys that already carry them (and their translations): the programs list's "Request to join" and
150
+ // "Joined", My Groups' "Pending request", the group screen's "Join group".
151
+ if (membership === "JOINED" || membership === "PENDING") {
152
+ const statusLabel = membership === "JOINED" ? copyParam("memberPrograms.status.joined", "Joined") : copyParam("myGroups.status.pending", "Pending request");
153
+ return { action: "none", actionLabel: "", noAction: true, statusLabel, noStatus: false };
60
154
  }
155
+ const request = needsApproval(group);
156
+ const actionLabel = request ? copyParam("memberPrograms.action.request", "Request to join") : copyParam("group.joinCta", "Join group");
157
+ // "open": Join group that opens the group rather than joining in place, where Wix would refuse it (a plan or ticket is required).
158
+ const action: GroupAction = request ? "request" : joinsElsewhere(group) ? "open" : "join";
159
+ return { action, actionLabel, noAction: false, statusLabel: "", noStatus: true };
61
160
  }
62
161
 
63
162
  function snippet(value: string): string {
@@ -65,7 +164,7 @@ function snippet(value: string): string {
65
164
  return text.length > 140 ? `${text.slice(0, 139).trimEnd()}…` : text;
66
165
  }
67
166
 
68
- function groupRow(group: WixGroup, cards: boolean): GroupRow {
167
+ function groupRow(group: WixGroup, cards: boolean, membership: string | undefined): GroupRow {
69
168
  const title = (group.name || copyParam("groups.groupFallbackName", "Group")).trim();
70
169
  const count = group.membersCount ?? group.memberCount;
71
170
  const image = groupImage(group, cards ? GROUP_CARD : GROUP_THUMB);
@@ -78,37 +177,209 @@ function groupRow(group: WixGroup, cards: boolean): GroupRow {
78
177
  meta, hasMeta: !!meta, noMeta: !meta,
79
178
  image, initial: (title[0] || "G").toUpperCase(), hasImage: Boolean(image), noImage: !image,
80
179
  detailScreenId: "himi_group",
180
+ ...joinState(group, membership),
81
181
  };
82
182
  }
83
183
 
184
+ /** The session at the tap, as the member-screen opener reads it: any non-empty value is a member (a host can answer `signedIn`
185
+ * with no email yet). A read that never answers counts as a visitor, so the tap opens the sign-in rather than nothing. */
186
+ const sessionMarker = (): Promise<string> =>
187
+ within(memberIdentity().then((identity) => (identity.signedIn ? identity.email || "signed-in" : ""), () => ""), CONTINUATION_BUDGET_MS, "");
188
+
189
+ const idOf = (arg: unknown): string => typeof arg === "string" ? arg : String((arg as { id?: unknown } | undefined)?.id ?? "");
190
+
191
+ const queryOf = (arg: unknown): string => {
192
+ if (typeof arg === "string") return arg;
193
+ const value = (arg as { value?: unknown; text?: unknown } | undefined)?.value ?? (arg as { text?: unknown } | undefined)?.text;
194
+ return typeof value === "string" ? value : "";
195
+ };
196
+
197
+ type Actions = {
198
+ load: (state: GroupsSectionState, arg?: unknown) => Promise<GroupsSectionState | undefined>;
199
+ clear: () => Promise<GroupsSectionState>;
200
+ join: (state: GroupsSectionState, arg?: unknown) => Promise<GroupsSectionState | undefined>;
201
+ toggleSearch: (state: GroupsSectionState) => GroupsSectionState;
202
+ search: (state: GroupsSectionState, arg?: unknown) => Promise<GroupsSectionState | undefined>;
203
+ };
204
+
205
+ /** The search field and the last join's message, carried from one state to the next. */
206
+ interface Ui { message?: string; query?: string; searchOpen?: boolean }
207
+
84
208
  export function registerGroupsSection(serviceName: string, options: GroupsSectionOptions = {}) {
85
- const view = (status: GroupsSectionState["status"], rows: GroupRow[], more: boolean): GroupsSectionState => ({
86
- status, rows,
87
- emptyText: status === "ready" && !rows.length ? copyParam("groups.emptyText", "No groups are published yet.") : "",
88
- notLoading: status !== "loading", notErrored: status !== "error",
89
- noRows: !rows.length, noEmpty: !(status === "ready" && !rows.length),
90
- noMore: !more,
91
- });
92
- return defineService<GroupsSectionState, { load: (state: GroupsSectionState, arg?: unknown) => Promise<GroupsSectionState> }>(serviceName, {
209
+ const view = (status: GroupsSectionState["status"], rows: GroupRow[], more: boolean, ui: Ui = {}): GroupsSectionState => {
210
+ const message = ui.message ?? "", query = ui.query ?? "", empty = status === "ready" && !rows.length;
211
+ return {
212
+ status, rows,
213
+ emptyText: !empty ? "" : query.trim() ? copyParam("groups.searchEmptyText", "No groups match your search.") : copyParam("groups.emptyText", "No groups are published yet."),
214
+ notLoading: status !== "loading", notErrored: status !== "error",
215
+ noRows: !rows.length, noEmpty: !empty,
216
+ noMore: !more,
217
+ message, noMessage: !message,
218
+ noSearch: ui.searchOpen !== true, query,
219
+ };
220
+ };
221
+ const uiOf = (state: GroupsSectionState): Ui => ({ query: state.query, searchOpen: !state.noSearch });
222
+ // Set by the first load (the section's onAppear): a section on a page nobody opened does not reload on every sign-in.
223
+ let appeared = false;
224
+ // What the last load read, for a search: the groups the section may show (no secret group outside its members, only the chosen
225
+ // ones), whether that is all of them, and the viewer's memberships (a join adds to them).
226
+ let pool: WixGroup[] = [];
227
+ let complete = false;
228
+ let truncated = false;
229
+ let memberships = new Map<string, string>();
230
+ const visible = (groups: WixGroup[]): WixGroup[] => {
231
+ // A secret group is listed only to its own members: a read that returns one to anyone else does not put it on the page.
232
+ const shown = groups.filter((group) => privacyOf(group) !== "SECRET" || memberships.get(group.id) === "JOINED");
233
+ if (!options.groupIds?.length) return shown;
234
+ // The chosen groups, in the source's order; one that no longer exists is simply absent.
235
+ const byId = new Map(shown.map((group) => [group.id, group]));
236
+ return options.groupIds.flatMap((id) => byId.get(id) ?? []);
237
+ };
238
+ const rowsOf = (groups: WixGroup[]): GroupRow[] => groups.map((group) => groupRow(group, options.cards === true, memberships.get(group.id)));
239
+ /** The section's own rows: the first `limit` groups, and whether there are more. A read that stopped past the limit had more
240
+ * groups to read, even when a secret one among those it read leaves exactly `limit` to show. */
241
+ const listed = (): { rows: GroupRow[]; more: boolean } => {
242
+ const shown = options.limit !== undefined ? pool.slice(0, options.limit) : pool;
243
+ return { rows: rowsOf(shown), more: truncated || !complete || shown.length < pool.length };
244
+ };
245
+ const matching = (query: string): GroupRow[] => rowsOf(pool.filter((group) => matchesQuery(group, query)));
246
+ // Only the newest load answers: a slow read for the previous viewer never lands over the next one's rows. Only the newest search
247
+ // answers too, so a slow first search never replaces what the reader typed after it.
248
+ let sequence = 0;
249
+ let searches = 0;
250
+ // The full read in flight, and the load it belongs to: a newer load starts its own rather than awaiting one it will discard.
251
+ let completing: { seq: number; read: Promise<void> } | undefined;
252
+ /** Every group the section may show, read once when a search needs more than the first `limit`. A failed read keeps what was read. */
253
+ const readAll = (): Promise<void> => {
254
+ if (completing?.seq === sequence) return completing.read;
255
+ const seq = sequence;
256
+ const read = (async () => {
257
+ try {
258
+ const all = await readGroups(options.groupIds, undefined);
259
+ if (seq !== sequence) return;
260
+ pool = visible(all.groups); truncated = all.truncated; complete = true;
261
+ } catch (error) {
262
+ console.warn("groups_section: the groups to search could not be read", error);
263
+ } finally { if (completing?.seq === seq) completing = undefined; }
264
+ })();
265
+ completing = { seq, read };
266
+ return read;
267
+ };
268
+ const joining = new Set<string>();
269
+ // Joins Wix confirmed while a load was reading: the load's membership read may predate them, so they win over it.
270
+ const confirmed = new Map<string, string>();
271
+ // Moves when the viewer changes (`clear`, on a sign-in or out): a join answered for the previous viewer is dropped.
272
+ let viewers = 0;
273
+ /** Every state key: the rows carry the viewer's memberships (and a member's secret groups). */
274
+ const KEYS = Object.keys(view("loading", [], false)) as Array<keyof GroupsSectionState>;
275
+ // Annotated: the actions read `service.getState()`, so an inferred type would refer to itself (TS7022 under the strict check).
276
+ const service: ServiceHandle<GroupsSectionState> & { clear: () => Promise<GroupsSectionState>; load: () => Promise<GroupsSectionState> } =
277
+ defineService<GroupsSectionState, Actions>(serviceName, {
93
278
  state: view("loading", [], false),
279
+ // Never written to disk nor restored from it for the next person on the device.
280
+ notHydrated: KEYS,
281
+ notPersisted: KEYS,
94
282
  actions: {
283
+ clear: async () => {
284
+ // The viewer changed: nothing read for the previous one is kept, their groups included.
285
+ viewers++; memberships = new Map(); confirmed.clear(); pool = []; complete = false; truncated = false;
286
+ return view("loading", [], false);
287
+ },
95
288
  load: async (_state, arg) => {
96
289
  stashCopy(arg);
290
+ appeared = true;
291
+ const seq = ++sequence;
97
292
  try {
98
- const read = await readGroups(options.groupIds, options.limit);
99
- let groups = read.groups;
100
- if (options.groupIds?.length) {
101
- // The chosen groups, in the source's order; one that no longer exists is simply absent.
102
- const byId = new Map(groups.map((group) => [group.id, group]));
103
- groups = options.groupIds.flatMap((id) => byId.get(id) ?? []);
293
+ const { signedIn } = await memberIdentity();
294
+ const [read, mine] = await Promise.all([readGroups(options.groupIds, options.limit), readMemberships(signedIn)]);
295
+ if (seq !== sequence) return undefined;
296
+ // Cleared only once a load has committed them (or the viewer changed): a load that overlapped an older one still gets them.
297
+ memberships = new Map([...mine, ...confirmed]);
298
+ confirmed.clear();
299
+ pool = visible(read.groups); truncated = read.truncated;
300
+ // Chosen groups are read until every one is found; the site's groups until the end or the cap.
301
+ complete = read.ended || read.truncated || !!options.groupIds?.length;
302
+ // The search as it is now, not as it was when the load started: a load on coming back to the page (the onAppear again)
303
+ // keeps the open search and what was typed in it, including what changed while it read.
304
+ let ui = uiOf(service.getState());
305
+ if (ui.query?.trim()) {
306
+ if (!complete) await readAll();
307
+ if (seq !== sequence) return undefined;
308
+ ui = uiOf(service.getState());
104
309
  }
105
- const shown = options.limit !== undefined ? groups.slice(0, options.limit) : groups;
106
- return view("ready", shown.map((group) => groupRow(group, options.cards === true)), read.truncated || shown.length < groups.length);
310
+ if (ui.query?.trim()) return view("ready", matching(ui.query), false, ui);
311
+ const { rows, more } = listed();
312
+ return view("ready", rows, more, { searchOpen: ui.searchOpen });
107
313
  } catch (error) {
314
+ if (seq !== sequence) return undefined;
108
315
  console.warn("groups_section: the groups could not be read", error);
109
316
  return view("error", [], false);
110
317
  }
111
318
  },
319
+ // The header's Search: opens the field, or closes it and shows the section's own rows again.
320
+ toggleSearch: (state) => {
321
+ if (state.noSearch) return view(state.status, state.rows, !state.noMore, { searchOpen: true });
322
+ searches++;
323
+ if (state.status !== "ready") return view(state.status, state.rows, !state.noMore);
324
+ const { rows, more } = listed();
325
+ return view(state.status, rows, more);
326
+ },
327
+ search: async (state, arg) => {
328
+ // Only an open field types: a debounced change that fires after Search closed it is dropped rather than reopening it.
329
+ if (state.noSearch) return undefined;
330
+ const query = queryOf(arg);
331
+ const mine = ++searches;
332
+ if (state.status !== "ready") return view(state.status, state.rows, !state.noMore, { query, searchOpen: true });
333
+ // What was typed is echoed back as is (a leading space included), so the field is never rewritten under the cursor.
334
+ if (!query.trim()) { const { rows, more } = listed(); return view("ready", rows, more, { query, searchOpen: true }); }
335
+ if (!complete) await readAll();
336
+ if (mine !== searches || service.getState().status !== "ready") return undefined;
337
+ return view("ready", matching(query), false, { query, searchOpen: true });
338
+ },
339
+ join: async (state, arg) => {
340
+ stashCopy(arg);
341
+ const row = state.rows.find((candidate) => candidate.id === idOf(arg));
342
+ if (!row || row.action === "none" || joining.has(row.id)) return undefined;
343
+ const target = { ...(arg as Record<string, unknown> | undefined ?? {}), screenId: row.detailScreenId, id: row.id };
344
+ // A visitor signs in first and lands on the group; a request opens the group, where its policy is explained. The session is
345
+ // read once, at the tap (these taps never ask for a modal sign-in, so no continuation is begun).
346
+ const session = await sessionMarker();
347
+ if (row.action !== "join" || !session) {
348
+ const nav = memberScreenNav(target, session);
349
+ return nav ? navigate(service.getState(), nav) : undefined;
350
+ }
351
+ joining.add(row.id);
352
+ const viewer = viewers;
353
+ try {
354
+ const response = await joinGroup(row.id);
355
+ const status = String((response as { membership?: { status?: unknown }; status?: unknown } | undefined)?.membership?.status
356
+ ?? (response as { status?: unknown } | undefined)?.status ?? "JOINED").toUpperCase();
357
+ if (viewer !== viewers) return undefined;
358
+ const membership = status === "PENDING" ? "PENDING" : "JOINED";
359
+ // Kept past a load that is reading right now (`confirmed`), so it never reverts the row to its old control.
360
+ memberships.set(row.id, membership);
361
+ confirmed.set(row.id, membership);
362
+ const now = service.getState();
363
+ const joined = joinState({ id: row.id }, membership);
364
+ return view(now.status, now.rows.map((candidate) => (candidate.id === row.id ? { ...candidate, ...joined } : candidate)), !now.noMore, uiOf(now));
365
+ } catch (error) {
366
+ if (viewer !== viewers) return undefined;
367
+ console.warn("groups_section: the group could not be joined", error);
368
+ const now = service.getState();
369
+ return view(now.status, now.rows, !now.noMore, { ...uiOf(now), message: copyParam("group.joinFailedMessage", "The group could not be joined. Try again.") });
370
+ } finally {
371
+ joining.delete(row.id);
372
+ }
373
+ },
112
374
  },
113
375
  });
376
+ // Signing in or out on another screen changes who the memberships are read for: the previous viewer's rows go at once.
377
+ hostSessionFromGlobal().subscribe(() => { if (!appeared) return; void service.clear(); void service.load(); });
378
+ // An older runtime restores the snapshot it already wrote, whatever `notHydrated` says: put every key back to the boot state.
379
+ if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
380
+ const live = (service as { getState?: () => GroupsSectionState | undefined }).getState?.();
381
+ const boot = view("loading", [], false);
382
+ if (live && typeof live === "object") for (const key of KEYS) (live as unknown as Record<string, unknown>)[key] = boot[key];
383
+ }
384
+ return service;
114
385
  }
@@ -1,95 +0,0 @@
1
- {
2
- "_recipe": "Blog hero: the latest posts as a snapping carousel (one post per page, page dots drawn by the renderer): cover image, then title and time under it. ONE node. Service: registerBlogList(svc, { limit }); the page worker's onAppear (on an always-mounted box around this node) calls tier5.<svc>.load.",
3
- "_placeholders": {
4
- "svc": "service name the page worker registered with registerBlogList",
5
- "id": "unique node id prefix for this section",
6
- "detailScreen": "blog post screen id, himi_blog_post"
7
- },
8
- "node": {
9
- "id": "{{id}}.hero",
10
- "body": {
11
- "package": "himalaya",
12
- "type": "Carousel",
13
- "props": {
14
- "itemsPath": "$service:{{svc}}.rows",
15
- "paged": true,
16
- "items": [
17
- {
18
- "id": "{{id}}.card",
19
- "body": {
20
- "package": "himalaya",
21
- "type": "VStack",
22
- "props": {
23
- "spacing": 8,
24
- "alignment": "leading",
25
- "children": [
26
- {
27
- "id": "{{id}}.cover",
28
- "body": {
29
- "package": "himalaya",
30
- "type": "Image",
31
- "props": {
32
- "url": "$item.cover",
33
- "initials": "$item.initial",
34
- "fillWidth": true,
35
- "height": 200,
36
- "contentMode": "fill",
37
- "contentDescription": "$item.title",
38
- "shape": "rect"
39
- }
40
- },
41
- "modifiers": {
42
- "fillMaxWidth": true,
43
- "hiddenPath": "$item.noCover"
44
- }
45
- },
46
- {
47
- "id": "{{id}}.title",
48
- "body": {
49
- "package": "himalaya",
50
- "type": "Text",
51
- "props": {
52
- "text": "$item.title",
53
- "style": "bodyEmphasis",
54
- "maxLines": 2
55
- }
56
- }
57
- },
58
- {
59
- "id": "{{id}}.meta",
60
- "body": {
61
- "package": "himalaya",
62
- "type": "Text",
63
- "props": {
64
- "text": "$item.meta",
65
- "style": "caption",
66
- "maxLines": 1,
67
- "color": "textSecondary",
68
- "collapseWhenEmpty": true
69
- }
70
- }
71
- }
72
- ]
73
- }
74
- },
75
- "modifiers": {
76
- "fillMaxWidth": true,
77
- "onTap": {
78
- "actionId": "himi.open",
79
- "params": {
80
- "screenId": "{{detailScreen}}",
81
- "id": "$item.id"
82
- }
83
- },
84
- "pressFeedback": "scale",
85
- "accessibilityLabel": "$item.title"
86
- }
87
- }
88
- ]
89
- }
90
- },
91
- "modifiers": {
92
- "hiddenPath": "$service:{{svc}}.noRows"
93
- }
94
- }
95
- }