@wix/himalaya-cli 0.1953.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.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/auth-providers/wix/src/index.d.ts +5 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-auth.mjs +2 -1
- package/dist/cli.mjs +224 -98
- package/guides/one-app-section-mappings.md +4 -4
- package/guides/one-app-to-himi-app.md +14 -10
- package/package.json +2 -2
- package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/beauty-salon/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/beauty-salon/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/beauty-salon/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/beauty-salon/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/beauty-salon/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/beauty-salon-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/branded-lite/l10n/ar.json +10 -0
- package/templates/branded-lite/l10n/cs.json +10 -0
- package/templates/branded-lite/l10n/da.json +10 -0
- package/templates/branded-lite/l10n/de.json +10 -0
- package/templates/branded-lite/l10n/el.json +10 -0
- package/templates/branded-lite/l10n/es.json +10 -0
- package/templates/branded-lite/l10n/fi.json +10 -0
- package/templates/branded-lite/l10n/fr.json +10 -0
- package/templates/branded-lite/l10n/he.json +9 -0
- package/templates/branded-lite/l10n/hu.json +10 -0
- package/templates/branded-lite/l10n/id.json +10 -0
- package/templates/branded-lite/l10n/it.json +10 -0
- package/templates/branded-lite/l10n/ja.json +10 -0
- package/templates/branded-lite/l10n/ko.json +10 -0
- package/templates/branded-lite/l10n/lt.json +10 -0
- package/templates/branded-lite/l10n/nl.json +10 -0
- package/templates/branded-lite/l10n/no.json +10 -0
- package/templates/branded-lite/l10n/pl.json +10 -0
- package/templates/branded-lite/l10n/pt.json +10 -0
- package/templates/branded-lite/l10n/ru.json +10 -0
- package/templates/branded-lite/l10n/sv.json +10 -0
- package/templates/branded-lite/l10n/th.json +10 -0
- package/templates/branded-lite/l10n/tr.json +10 -0
- package/templates/branded-lite/l10n/uk.json +10 -0
- package/templates/branded-lite/l10n/vi.json +10 -0
- package/templates/branded-lite/l10n/zh.json +10 -0
- package/templates/branded-lite/recipes/blog-carousel-classic.json +335 -0
- package/templates/branded-lite/recipes/blog-carousel-full.json +374 -0
- package/templates/branded-lite/recipes/class-calendar.json +707 -0
- package/templates/branded-lite/recipes/events-inline-carousel.json +308 -0
- package/templates/branded-lite/recipes/galleries-carousel.json +51 -2
- package/templates/branded-lite/recipes/galleries-collage.json +51 -2
- package/templates/branded-lite/recipes/galleries-list.json +51 -2
- package/templates/branded-lite/recipes/groups-cards.json +194 -86
- package/templates/branded-lite/recipes/groups-list.json +209 -62
- package/templates/branded-lite/recipes/upcoming-sessions.json +280 -0
- package/templates/branded-lite/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/branded-lite/tier5-src/_shared/blog-list.ts +5 -1
- package/templates/branded-lite/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/branded-lite/tier5-src/_shared/class-calendar-section.ts +280 -0
- package/templates/branded-lite/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/branded-lite/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/branded-lite/tier5-src/_shared/galleries-section.ts +70 -23
- package/templates/branded-lite/tier5-src/_shared/groups-section.ts +297 -26
- package/templates/branded-lite/tier5-src/_shared/upcoming-sessions-section.ts +121 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/brandy/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/community-club/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/community-club-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/conference/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/events-meetups/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/events-meetups-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/fitness-gym/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/fitness-gym/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/fitness-gym/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/fitness-gym/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/fitness-gym/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/gym-fitness/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/gym-fitness/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/gym-fitness/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/gym-fitness/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/gym-fitness/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/gym-fitness-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/medical-services/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/medical-services/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/nonprofit-cause/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/owner-lite/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/owner-lite/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/podcast-creator/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/portfolio-creative/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/professional-services/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/professional-services/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/restaurant/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/restaurant-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/retail-store/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/retail-store-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/salon-spa/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/salon-spa/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/salon-spa/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/salon-spa/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/wholesale-store/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/yoga-studio/tier5-src/_shared/agenda-calendar.ts +95 -0
- package/templates/yoga-studio/tier5-src/_shared/booking-session.ts +10 -0
- package/templates/yoga-studio/tier5-src/_shared/class-sessions.ts +113 -0
- package/templates/yoga-studio/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/yoga-studio/tier5-src/himi-branded-lite-agenda/index.ts +13 -146
- package/templates/yoga-studio-owner/tier5-src/_shared/engine-intl.ts +6 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-selected-site.ts +13 -0
- package/templates/branded-lite/recipes/blog-hero.json +0 -95
|
@@ -3,18 +3,24 @@
|
|
|
3
3
|
// which is when the section's See All button (to the galleries screen) shows.
|
|
4
4
|
// showName -> whether a card shows the gallery's name (the source section's `isShowName`); the accessibility label always has it.
|
|
5
5
|
// The source reads the One App's own galleries service with the MEMBER's signed instance, never hidden galleries (`withHidden=false`), and
|
|
6
|
-
// drops empty ones
|
|
7
|
-
//
|
|
8
|
-
// - a signed-out visitor gets the
|
|
6
|
+
// drops empty ones. This section reads the same list and never falls back to the public Pro Gallery list (`/progallery/v2/galleries`), which
|
|
7
|
+
// has no hidden flag:
|
|
8
|
+
// - a signed-out visitor (or a member Wix refuses) gets the sign-in state (`signedOut`), without a read: "No galleries yet" would be a claim
|
|
9
|
+
// about a list nobody read;
|
|
9
10
|
// - a member reads that service (`photography-one-app-viewer/galleries`), which a native host reaches;
|
|
10
|
-
// - where it cannot be read (the published web bridge refuses that host) the member gets the
|
|
11
|
+
// - where it cannot be read (the published web bridge refuses that host, a failed or malformed answer) the member gets the error state, never
|
|
12
|
+
// the empty one: only a list that answered with no gallery is "No galleries yet". A hidden gallery must never show.
|
|
13
|
+
// Signing in or out on another screen reads again for whoever is signed in now.
|
|
11
14
|
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipes galleries-carousel / galleries-list).
|
|
12
15
|
// `collage: true` is the source's single-gallery mode (`maxGalleries: 1`): the first gallery's name, View All, and its first five pictures as one
|
|
13
16
|
// big tile and four small ones, the last small tile carrying "+N" for the pictures past the five (recipe galleries-collage).
|
|
14
17
|
import { defineService } from "@himalaya/state";
|
|
18
|
+
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
15
19
|
import { wixMediaUrl } from "@himalaya/wix-media";
|
|
16
20
|
import { copyParam, stashCopy, copyTemplate } from "./himi-copy.js";
|
|
21
|
+
import { resetUnhydratedKeysOnOlderRuntime } from "./iap-worker.js";
|
|
17
22
|
import { memberAccess } from "./member-access.js";
|
|
23
|
+
import { isHttp401 } from "./member-read.js";
|
|
18
24
|
|
|
19
25
|
export interface GalleriesSectionOptions {
|
|
20
26
|
/** How many galleries to show. */
|
|
@@ -49,9 +55,14 @@ export interface GalleryRow {
|
|
|
49
55
|
|
|
50
56
|
export interface GalleriesSectionState {
|
|
51
57
|
status: "loading" | "ready" | "error";
|
|
58
|
+
/** A visitor, or a member Wix refused: the section asks to sign in instead of reading. */
|
|
59
|
+
signedOut: boolean;
|
|
52
60
|
rows: GalleryRow[];
|
|
61
|
+
/** "No galleries yet": only once a member's read answered with none. */
|
|
53
62
|
emptyText: string;
|
|
54
|
-
|
|
63
|
+
/** The stock galleries screen's sign-in sentence (`galleries.signInText`) and the stock Sign in button's title. */
|
|
64
|
+
signInText: string; signInLabel: string;
|
|
65
|
+
notLoading: boolean; notErrored: boolean; notSignedOut: boolean; noRows: boolean; noEmpty: boolean;
|
|
55
66
|
/** false when the site has more galleries than the section shows. */
|
|
56
67
|
noMore: boolean;
|
|
57
68
|
/** The collage's tiles: the first one, and up to four after it (both empty outside `collage`). */
|
|
@@ -158,35 +169,71 @@ export function registerGalleriesSection(serviceName: string, options: Galleries
|
|
|
158
169
|
const collage = options.collage === true;
|
|
159
170
|
const limit = collage ? 1 : Math.min(Math.max(Math.floor(options.limit ?? DEFAULT_LIMIT), 1), MAX_GALLERIES);
|
|
160
171
|
const showName = options.showName !== false;
|
|
161
|
-
const view = (status: GalleriesSectionState["status"], rows: GalleryRow[], more: boolean, tiles: { big: CollageTile[]; small: CollageTile[] } = { big: [], small: [] }): GalleriesSectionState =>
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
const view = (status: GalleriesSectionState["status"], signedOut: boolean, rows: GalleryRow[], more: boolean, tiles: { big: CollageTile[]; small: CollageTile[] } = { big: [], small: [] }): GalleriesSectionState => {
|
|
173
|
+
const empty = status === "ready" && !signedOut && !rows.length;
|
|
174
|
+
return {
|
|
175
|
+
status, signedOut, rows, bigTile: tiles.big, smallTiles: tiles.small, noCollage: !tiles.big.length,
|
|
176
|
+
emptyText: empty ? copyParam("galleries.sectionEmptyText", "No galleries yet.") : "",
|
|
177
|
+
signInText: copyParam("galleries.signInText", "Sign in to see galleries."), signInLabel: copyParam("account.signInCta", "Sign in"),
|
|
178
|
+
notLoading: status !== "loading", notErrored: status !== "error", notSignedOut: !signedOut,
|
|
179
|
+
noRows: !rows.length, noEmpty: !empty,
|
|
180
|
+
noMore: !more,
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const initial = view("loading", false, [], false);
|
|
184
|
+
// Only the newest load may answer: a visitor's load that finishes after the member signed in must not overwrite the member's list.
|
|
185
|
+
let sequence = 0;
|
|
186
|
+
// The viewer changed: what is published is the previous viewer's, so it goes at once, before the read for the new one finishes. Only a
|
|
187
|
+
// section that has loaded reads again: one page worker can register many sections, and one its screen never showed reads on its onAppear.
|
|
188
|
+
const restart = () => { if (!sequence) return; void service.clear(); void service.load(); };
|
|
189
|
+
// The list is read as one member: kept out of the worker snapshot (on a runtime that honours `notPersisted`), and never restored for
|
|
190
|
+
// the next person on the device.
|
|
191
|
+
const memberKeys = Object.keys(initial) as Array<keyof GalleriesSectionState>;
|
|
192
|
+
const service = defineService<GalleriesSectionState, { load: (state: GalleriesSectionState, arg?: unknown) => Promise<GalleriesSectionState | undefined>; clear: () => GalleriesSectionState }>(serviceName, {
|
|
193
|
+
state: initial,
|
|
194
|
+
notPersisted: memberKeys,
|
|
195
|
+
notHydrated: memberKeys,
|
|
170
196
|
actions: {
|
|
197
|
+
// A read still in flight belongs to the previous viewer: it must not publish over the cleared state. Synchronous, as in
|
|
198
|
+
// upcoming-sessions, so the bump lands before the load `restart` sends next.
|
|
199
|
+
clear: () => { ++sequence; return initial; },
|
|
171
200
|
load: async (_state, arg) => {
|
|
172
201
|
stashCopy(arg);
|
|
202
|
+
const seq = ++sequence;
|
|
173
203
|
try {
|
|
174
|
-
// The source reads as the member: a visitor has no instance for it
|
|
175
|
-
|
|
204
|
+
// The source reads as the member: a visitor has no instance for it. Strict: an identity lookup that merely failed is an error, not a visitor.
|
|
205
|
+
const member = await memberAccess({ throwOnUnavailable: true });
|
|
206
|
+
if (seq !== sequence) return undefined;
|
|
207
|
+
if (!member.signedIn) return view("ready", true, [], false);
|
|
176
208
|
const api = (globalThis as { himalaya?: { wixApi?: WixApi } }).himalaya?.wixApi;
|
|
177
209
|
if (!api) throw new Error("Wix bridge unavailable");
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return { galleries: [] as RawGallery[], more: false };
|
|
182
|
-
});
|
|
210
|
+
// A list that cannot be read is the error state, and never replaced by the public list: that one cannot tell a hidden gallery.
|
|
211
|
+
const { galleries, more } = await readGalleries(api, limit, collage ? COLLAGE_TILES : 1);
|
|
212
|
+
if (seq !== sequence) return undefined;
|
|
183
213
|
const rows = galleries.slice(0, limit).map((gallery, index) => rowOf(gallery, index, showName));
|
|
184
|
-
return view("ready", rows, more, collage && rows[0] && galleries[0] ? collageOf(galleries[0], rows[0]) : undefined);
|
|
214
|
+
return view("ready", false, rows, more, collage && rows[0] && galleries[0] ? collageOf(galleries[0], rows[0]) : undefined);
|
|
185
215
|
} catch (error) {
|
|
216
|
+
if (seq !== sequence) return undefined;
|
|
217
|
+
// Wix refusing the session (the status, HTTP 401) is a sign-in state; a 401 quoted in another status's body is not. A 403 is not: it also answers an app that is not
|
|
218
|
+
// installed, and a Sign in button would loop a member who is already signed in. Anything else is a failed read.
|
|
219
|
+
if (isHttp401(error)) return view("ready", true, [], false);
|
|
186
220
|
console.warn("galleries_section: the galleries could not be read", error);
|
|
187
|
-
return view("error", [], false);
|
|
221
|
+
return view("error", false, [], false);
|
|
188
222
|
}
|
|
189
223
|
},
|
|
190
224
|
},
|
|
191
225
|
});
|
|
226
|
+
// A runtime older than both options restores a snapshot written before this module stopped persisting: it goes before the first paint.
|
|
227
|
+
resetUnhydratedKeysOnOlderRuntime(service, initial, memberKeys);
|
|
228
|
+
// Signing in or out on another screen changes whose list the section shows. A new generation is a new identity; a notification within
|
|
229
|
+
// one (the session turning ready, a token refresh) keeps the list, as the top-bar avatar does.
|
|
230
|
+
const session = hostSessionFromGlobal();
|
|
231
|
+
let generation = session.current().generation;
|
|
232
|
+
session.subscribe(() => {
|
|
233
|
+
const now = session.current().generation;
|
|
234
|
+
if (now === generation) return;
|
|
235
|
+
generation = now;
|
|
236
|
+
restart();
|
|
237
|
+
});
|
|
238
|
+
return service;
|
|
192
239
|
}
|
|
@@ -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
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
|
|
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
|
}
|