@wix/himalaya-cli 0.1871.0 → 0.1873.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/dev-server/src/app-module.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/portfolio/src/index.d.ts +19 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{ab91dfb9c348c8c78f942a5b88ba90df456c5b436e135d97791d5dd95d6a40dc.bin → a9d34f09c807f1cde9ab000737f0f7b849670c37908aa47cb77889b7e01d34cb.bin} +1 -1
- package/dist/browser-plane/sw.js +9 -9
- package/dist/cli.mjs +506 -323
- package/dist/preview-assets.generated.bin +0 -0
- package/fixtures/wix-canned.json +8 -0
- package/guides/release-notes.md +18 -0
- package/guides/sdk-reference.json +8 -1
- package/package.json +2 -2
- package/template-icons/professional-services.png +0 -0
- package/templates/bare-fashion/config.ts +37 -2
- package/templates/bare-fashion/dev/index.ts +4006 -48
- package/templates/bare-fashion/himalaya.content.json +15 -0
- package/templates/bare-fashion/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/branded-lite/dev/index.ts +2 -1
- package/templates/branded-lite/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-coupons/index.ts +13 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/branded-lite/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/community-club/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/config.ts +43 -1
- package/templates/conference/dev/index.ts +4127 -0
- package/templates/conference/himalaya.content.json +18 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/conference/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/conference/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/medical-services/config.ts +42 -0
- package/templates/medical-services/dev/index.ts +4136 -0
- package/templates/medical-services/himalaya.content.json +18 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/medical-services/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/medical-services/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/portfolio-creative/dev/index.ts +2 -1
- package/templates/portfolio-creative/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio/index.ts +90 -9
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-portfolio-project/index.ts +53 -4
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/professional-services/README.md +55 -0
- package/templates/professional-services/config.ts +436 -0
- package/templates/professional-services/dev/index.ts +44772 -0
- package/templates/professional-services/himalaya.content.json +100 -0
- package/templates/professional-services/himalaya.template.json +16 -0
- package/templates/professional-services/icon.png +0 -0
- package/templates/professional-services/platforms.json +1 -0
- package/templates/professional-services/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/booking-location.ts +147 -0
- package/templates/professional-services/tier5-src/_shared/booking-session.ts +224 -0
- package/templates/professional-services/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/professional-services/tier5-src/_shared/branded-load-state.ts +109 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-copy.ts +40 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-history.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-message-model.ts +177 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-model.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-presenter.ts +587 -0
- package/templates/professional-services/tier5-src/_shared/business-chat-transport.ts +164 -0
- package/templates/professional-services/tier5-src/_shared/chat-live.ts +242 -0
- package/templates/professional-services/tier5-src/_shared/collection-contract.ts +232 -0
- package/templates/professional-services/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/professional-services/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/professional-services/tier5-src/_shared/detail-presence.ts +51 -0
- package/templates/professional-services/tier5-src/_shared/engine-intl.ts +538 -0
- package/templates/professional-services/tier5-src/_shared/event-registration.ts +86 -0
- package/templates/professional-services/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/professional-services/tier5-src/_shared/faq-list.ts +405 -0
- package/templates/professional-services/tier5-src/_shared/featured-event.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/group-member-count.ts +15 -0
- package/templates/professional-services/tier5-src/_shared/group-privacy.ts +14 -0
- package/templates/professional-services/tier5-src/_shared/guest-sign-in.ts +36 -0
- package/templates/professional-services/tier5-src/_shared/himi-account.ts +222 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-hidden.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-post-row.ts +214 -0
- package/templates/professional-services/tier5-src/_shared/himi-blog-saved.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/himi-booking-saved.ts +88 -0
- package/templates/professional-services/tier5-src/_shared/himi-bookings.ts +318 -0
- package/templates/professional-services/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/professional-services/tier5-src/_shared/himi-events.ts +92 -0
- package/templates/professional-services/tier5-src/_shared/himi-media.ts +33 -0
- package/templates/professional-services/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/professional-services/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/professional-services/tier5-src/_shared/host-events.ts +66 -0
- package/templates/professional-services/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-form.ts +106 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance-purchase.ts +235 -0
- package/templates/professional-services/tier5-src/_shared/iap-attendance.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/iap-worker.ts +127 -0
- package/templates/professional-services/tier5-src/_shared/inbox-rooms.ts +163 -0
- package/templates/professional-services/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/professional-services/tier5-src/_shared/member-access.ts +63 -0
- package/templates/professional-services/tier5-src/_shared/member-account-routes.ts +56 -0
- package/templates/professional-services/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/member-bookings.ts +107 -0
- package/templates/professional-services/tier5-src/_shared/member-read.ts +82 -0
- package/templates/professional-services/tier5-src/_shared/member-screen.ts +99 -0
- package/templates/professional-services/tier5-src/_shared/notification-target.ts +141 -0
- package/templates/professional-services/tier5-src/_shared/offset-page.ts +10 -0
- package/templates/professional-services/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/professional-services/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/professional-services/tier5-src/_shared/payment-setup.ts +6 -0
- package/templates/professional-services/tier5-src/_shared/portfolio-details.ts +70 -0
- package/templates/professional-services/tier5-src/_shared/pricing-plan-display.ts +64 -0
- package/templates/professional-services/tier5-src/_shared/relative-time.ts +21 -0
- package/templates/professional-services/tier5-src/_shared/result-snackbar.ts +26 -0
- package/templates/professional-services/tier5-src/_shared/rich-body.ts +78 -0
- package/templates/professional-services/tier5-src/_shared/rich-content-link.ts +34 -0
- package/templates/professional-services/tier5-src/_shared/sign-in-sheet.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/staff-name.ts +18 -0
- package/templates/professional-services/tier5-src/_shared/weekly-goal.ts +111 -0
- package/templates/professional-services/tier5-src/_shared/wix-bi.ts +85 -0
- package/templates/professional-services/tier5-src/_shared/wix-member-links.ts +114 -0
- package/templates/professional-services/tier5-src/_shared/wix-service-price.ts +146 -0
- package/templates/professional-services/tier5-src/business-chat/index.ts +797 -0
- package/templates/professional-services/tier5-src/business-contact/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-blog-feed/index.ts +444 -0
- package/templates/professional-services/tier5-src/himi-blog-post/index.ts +1239 -0
- package/templates/professional-services/tier5-src/himi-booking-account/index.ts +278 -0
- package/templates/professional-services/tier5-src/himi-booking-bookings/index.ts +475 -0
- package/templates/professional-services/tier5-src/himi-booking-service/index.ts +1197 -0
- package/templates/professional-services/tier5-src/himi-booking-services/index.ts +795 -0
- package/templates/professional-services/tier5-src/himi-booking-time/index.ts +1840 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-coupons/index.ts +96 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-faq/index.ts +6 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-file-share/index.ts +12 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group/index.ts +310 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-group-about/index.ts +240 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-my-groups/index.ts +237 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-notifications/index.ts +263 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-plans/index.ts +498 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio/index.ts +136 -0
- package/templates/professional-services/tier5-src/himi-branded-lite-portfolio-project/index.ts +198 -0
- package/templates/professional-services/tier5-src/himi-events-detail/index.ts +1306 -0
- package/templates/professional-services/tier5-src/himi-events-list/index.ts +171 -0
- package/templates/professional-services/tier5-src/himi-events-my-events/index.ts +227 -0
- package/templates/professional-services/tier5-src/himi-events-rsvp/index.ts +230 -0
- package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts +318 -0
- package/templates/professional-services/tier5-src/himi-professional-services-home/index.ts +772 -0
- package/templates/professional-services/tier5-src/himi-store-account/index.ts +1514 -0
- package/templates/professional-services/tier5-src/wix-spaces-coupon-detail/index.ts +43 -0
- package/templates/professional-services/tier5-src/wix-spaces-my-subscriptions/index.ts +89 -0
- package/templates/professional-services/tier5-src/wix-spaces-subscription-detail/index.ts +139 -0
- package/templates/professional-services/tokens.json +456 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +5 -1
- package/templates/salon-spa/config.ts +42 -0
- package/templates/salon-spa/dev/index.ts +4136 -0
- package/templates/salon-spa/himalaya.content.json +18 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/salon-spa/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/salon-spa/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/wholesale-store/config.ts +43 -1
- package/templates/wholesale-store/dev/index.ts +4136 -0
- package/templates/wholesale-store/himalaya.content.json +18 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/blocked-members.ts +295 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/index.ts +58 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/login-info.ts +274 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/personal-info.ts +881 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/privacy.ts +139 -0
- package/templates/wholesale-store/tier5-src/himi-branded-lite-account-settings/shared.ts +136 -0
- package/templates/wholesale-store/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +5 -1
package/templates/professional-services/tier5-src/himi-professional-services-community/index.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// Tier-5 bundle: himi-professional-services-community — the professional-services template's
|
|
2
|
+
// Community tab: the member's groups on top, the groups they have not joined below, Join in place.
|
|
3
|
+
//
|
|
4
|
+
// Reads (the same calls the shared group screens make):
|
|
5
|
+
// - every listed group: queryGroups (as himi-branded-lite-groups) — a visitor sees all of them;
|
|
6
|
+
// - the member's groups: listMemberships for their own member id + the group rows above (as
|
|
7
|
+
// himi-branded-lite-my-groups). A failed memberships read is the fallback: no My groups rail,
|
|
8
|
+
// and the list below is titled "All groups".
|
|
9
|
+
//
|
|
10
|
+
// New-posts badge. Wix Groups has no unread count, so the badge is computed on this device: the
|
|
11
|
+
// posts in a joined group's feed (listFeedItems, as himi-branded-lite-feed) created after the last
|
|
12
|
+
// time the member opened that group FROM ITS CARD here, not counting the member's own posts. The
|
|
13
|
+
// first load stores "now" and shows no badge (never a sudden "20"). Opening the group from the card
|
|
14
|
+
// stores "now" again, which clears it. Per device; a failed feed read shows no badge.
|
|
15
|
+
//
|
|
16
|
+
// A visitor's Join opens the sign-in sheet. A private group's "Request to join" opens the group's own
|
|
17
|
+
// screen (a join request is another Wix call); a secret group is never listed.
|
|
18
|
+
import { defineService, navigate } from "@himalaya/state";
|
|
19
|
+
import { joinGroup, listMemberships, queryGroups, type WixGroup, type WixGroupMembership } from "@himalaya/wix-groups";
|
|
20
|
+
import { listFeedItems } from "@himalaya/wix-social-feed";
|
|
21
|
+
import { getMyMember } from "@himalaya/wix-members";
|
|
22
|
+
import { groupImage } from "../_shared/himi-media.js";
|
|
23
|
+
import { loadMemberProfile } from "../_shared/himi-account.js";
|
|
24
|
+
import { memberAccess, assertMemberAccess, type MemberAccess } from "../_shared/member-access.js";
|
|
25
|
+
import { memberScreenOpener } from "../_shared/member-screen.js";
|
|
26
|
+
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
27
|
+
|
|
28
|
+
export const SERVICE = "himiProfessionalServicesCommunity";
|
|
29
|
+
const GROUP_SCREEN = "himi_group";
|
|
30
|
+
const SEEN_KEY = "himi.ps.community.seen";
|
|
31
|
+
const BADGE_MAX = 9;
|
|
32
|
+
|
|
33
|
+
export interface MyGroupCard { id: string; name: string; meta: string; image: string; hasImage: boolean; noImage: boolean; badge: string; noBadge: boolean; badgeA11y: string }
|
|
34
|
+
export interface SuggestedCard {
|
|
35
|
+
id: string; name: string; meta: string; image: string; hasImage: boolean; noImage: boolean;
|
|
36
|
+
actionLabel: string; canJoin: boolean; cannotJoin: boolean; joined: boolean; notJoined: boolean; busy: boolean; isPrivate: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface S {
|
|
39
|
+
status: "loading" | "ready" | "error";
|
|
40
|
+
isLoading: boolean; notLoading: boolean; errored: boolean; notErrored: boolean;
|
|
41
|
+
isMember: boolean; notMember: boolean;
|
|
42
|
+
memberInitials: string; memberImage: string; hasMemberImage: boolean; noMemberImage: boolean;
|
|
43
|
+
myGroups: MyGroupCard[]; noMyGroups: boolean;
|
|
44
|
+
suggested: SuggestedCard[]; noSuggested: boolean;
|
|
45
|
+
/** "SUGGESTED GROUPS", or "ALL GROUPS" when the member's groups could not be read. */
|
|
46
|
+
suggestedTitle: string;
|
|
47
|
+
emptyHidden: boolean;
|
|
48
|
+
message: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const BOOT: S = {
|
|
52
|
+
status: "loading", isLoading: true, notLoading: false, errored: false, notErrored: true,
|
|
53
|
+
isMember: false, notMember: true, memberInitials: "", memberImage: "", hasMemberImage: false, noMemberImage: true,
|
|
54
|
+
myGroups: [], noMyGroups: true, suggested: [], noSuggested: true, suggestedTitle: "", emptyHidden: true, message: "",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
const clean = (value: unknown): string => (typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "");
|
|
60
|
+
const strArg = (arg: unknown, key: string): string => {
|
|
61
|
+
const v = (arg as Record<string, unknown> | undefined)?.[key];
|
|
62
|
+
return typeof v === "string" ? v : "";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
interface StorageLike { getItem(key: string): string | null; setItem(key: string, value: string): void }
|
|
66
|
+
function storage(): StorageLike | undefined {
|
|
67
|
+
const host = globalThis as unknown as { himalaya?: { storage?: StorageLike }; localStorage?: StorageLike };
|
|
68
|
+
return host.himalaya?.storage ?? host.localStorage;
|
|
69
|
+
}
|
|
70
|
+
/** Last-seen times per member and group: { "<email>|<groupId>": epochMs }. */
|
|
71
|
+
function readSeen(): Record<string, number> {
|
|
72
|
+
// A device-local badge cache, not a read of the site: unreadable JSON means nothing seen yet,
|
|
73
|
+
// so every group with posts shows its badge — the safe direction.
|
|
74
|
+
let parsed: unknown = {};
|
|
75
|
+
try { parsed = JSON.parse(storage()?.getItem(SEEN_KEY) ?? "{}"); } catch { /* corrupt cache: start over */ }
|
|
76
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed as Record<string, number> : {};
|
|
77
|
+
}
|
|
78
|
+
function writeSeen(seen: Record<string, number>): void {
|
|
79
|
+
try { storage()?.setItem(SEEN_KEY, JSON.stringify(seen)); } catch { /* best-effort: the badge is per device */ }
|
|
80
|
+
}
|
|
81
|
+
const seenKey = (email: string, groupId: string) => `${email}|${groupId}`;
|
|
82
|
+
|
|
83
|
+
export function memberCountLabel(count: unknown): string {
|
|
84
|
+
const n = Number(count);
|
|
85
|
+
// A count Wix did not send (null reads 0) or a zero says nothing true about a group: no label.
|
|
86
|
+
if (!Number.isFinite(n) || n < 1) return "";
|
|
87
|
+
return n === 1 ? copyParam("community.oneMember", "1 member") : copyTemplate("community.members", "{n} members", { n: Math.floor(n) });
|
|
88
|
+
}
|
|
89
|
+
const privacyOf = (group: WixGroup) => String((group as { privacyStatus?: string }).privacyStatus ?? "PUBLIC").toUpperCase();
|
|
90
|
+
export function metaLine(group: WixGroup): string {
|
|
91
|
+
const members = memberCountLabel((group as { membersCount?: number; memberCount?: number }).membersCount ?? (group as { memberCount?: number }).memberCount);
|
|
92
|
+
const priv = privacyOf(group) === "PRIVATE";
|
|
93
|
+
// "Public" is Wix's privacy word, not a label: a public group shows its member count only.
|
|
94
|
+
// "Private" stays: it tells the visitor why the action reads "Request to join".
|
|
95
|
+
if (!members) return priv ? copyParam("group.privacyPrivate", "Private") : "";
|
|
96
|
+
return priv ? copyTemplate("community.privateMeta", "Private · {members}", { members }) : members;
|
|
97
|
+
}
|
|
98
|
+
const groupName = (group: WixGroup) => clean(group.name) || copyParam("community.groupFallbackName", "Group");
|
|
99
|
+
|
|
100
|
+
/** "3", "9+" — nothing at 0 or when the count is unknown. */
|
|
101
|
+
export function badgeLabel(count: number | undefined): string {
|
|
102
|
+
if (typeof count !== "number" || !Number.isFinite(count) || count <= 0) return "";
|
|
103
|
+
return count > BADGE_MAX ? `${BADGE_MAX}+` : String(Math.floor(count));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Posts newer than `since`, not written by `memberId`. */
|
|
107
|
+
export function newPostCount(items: Array<{ created?: string; createdAt?: string; author?: { id?: string }; createdBy?: unknown }>, since: number, memberId: string): number {
|
|
108
|
+
return items.filter((item) => {
|
|
109
|
+
const at = Date.parse(item.created ?? item.createdAt ?? "");
|
|
110
|
+
if (!Number.isFinite(at) || at <= since) return false;
|
|
111
|
+
const by = item.author?.id ?? (typeof item.createdBy === "object" && item.createdBy ? (item.createdBy as { siteMemberId?: string }).siteMemberId : "");
|
|
112
|
+
return !memberId || by !== memberId;
|
|
113
|
+
}).length;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function myCard(group: WixGroup, count: number | undefined): MyGroupCard {
|
|
117
|
+
const image = groupImage(group);
|
|
118
|
+
const badge = badgeLabel(count);
|
|
119
|
+
return {
|
|
120
|
+
id: String(group.id), name: groupName(group), meta: metaLine(group), image, hasImage: !!image, noImage: !image,
|
|
121
|
+
badge, noBadge: !badge,
|
|
122
|
+
badgeA11y: badge ? (count === 1 ? copyParam("community.oneNewPost", "1 new post") : copyTemplate("community.newPosts", "{n} new posts", { n: badge })) : "",
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function suggestedCard(group: WixGroup, joinState: "none" | "joined" | "requested" = "none"): SuggestedCard {
|
|
126
|
+
const image = groupImage(group);
|
|
127
|
+
const priv = privacyOf(group) === "PRIVATE";
|
|
128
|
+
const joined = joinState !== "none";
|
|
129
|
+
const actionLabel = joinState === "joined" ? copyParam("community.joinedLabel", "Joined")
|
|
130
|
+
: joinState === "requested" ? copyParam("community.requestedLabel", "Request sent")
|
|
131
|
+
: priv ? copyParam("community.requestCta", "Request to join") : copyParam("community.joinCta", "Join group");
|
|
132
|
+
return {
|
|
133
|
+
id: String(group.id), name: groupName(group), meta: metaLine(group), image, hasImage: !!image, noImage: !image,
|
|
134
|
+
actionLabel, canJoin: !joined, cannotJoin: joined, joined, notJoined: !joined, busy: false, isPrivate: priv,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ── Load ─────────────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
let loadSeq = 0;
|
|
141
|
+
let latest: S = BOOT;
|
|
142
|
+
const commit = (next: S): S => (latest = next);
|
|
143
|
+
const now = (): S => (svc.getState?.() as S | undefined) ?? latest;
|
|
144
|
+
const openMemberScreen = memberScreenOpener();
|
|
145
|
+
/** Who the member data on screen belongs to. */
|
|
146
|
+
let shownIdentity = "";
|
|
147
|
+
const identityOf = (m: MemberAccess | undefined): string => (m?.email ? JSON.stringify([m.email, m.scope]) : "");
|
|
148
|
+
let memberEmail = "";
|
|
149
|
+
|
|
150
|
+
interface Read { groups: WixGroup[]; memberships?: WixGroupMembership[]; memberId: string }
|
|
151
|
+
|
|
152
|
+
async function readAll(member: MemberAccess): Promise<Read> {
|
|
153
|
+
const groupsRes = await queryGroups({ paging: { limit: 50 } });
|
|
154
|
+
const groups = (((groupsRes as { groups?: WixGroup[] }).groups) ?? []).filter((g) => g?.id && privacyOf(g) !== "SECRET");
|
|
155
|
+
if (!member.email) return { groups, memberId: "" };
|
|
156
|
+
try {
|
|
157
|
+
const me = await getMyMember();
|
|
158
|
+
const memberId = String(me?.member?.id ?? "");
|
|
159
|
+
if (!memberId) return { groups, memberId: "" };
|
|
160
|
+
const res = await listMemberships(memberId, { limit: 50 });
|
|
161
|
+
const list = ((res as { memberships?: WixGroupMembership[] }).memberships ?? [])
|
|
162
|
+
.filter((m) => m?.groupId && ["JOINED", "PENDING"].includes(String(m.status ?? "").toUpperCase()));
|
|
163
|
+
return { groups, memberships: list, memberId };
|
|
164
|
+
} catch {
|
|
165
|
+
return { groups, memberId: "" };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function badges(groups: WixGroup[], email: string, memberId: string): Promise<Map<string, number | undefined>> {
|
|
170
|
+
const seen = readSeen();
|
|
171
|
+
const nowMs = Date.now();
|
|
172
|
+
let changed = false;
|
|
173
|
+
const out = new Map<string, number | undefined>();
|
|
174
|
+
await Promise.all(groups.map(async (group) => {
|
|
175
|
+
const key = seenKey(email, String(group.id));
|
|
176
|
+
const since = seen[key];
|
|
177
|
+
if (typeof since !== "number") {
|
|
178
|
+
// First load for this group on this device: start counting from now.
|
|
179
|
+
seen[key] = nowMs; changed = true; out.set(String(group.id), 0);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const feed = await listFeedItems(String(group.id), 20);
|
|
184
|
+
out.set(String(group.id), newPostCount(feed.feedItems ?? [], since, memberId));
|
|
185
|
+
} catch { out.set(String(group.id), undefined); }
|
|
186
|
+
}));
|
|
187
|
+
if (changed) writeSeen(seen);
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function load(s: S): Promise<S> {
|
|
192
|
+
const mine = ++loadSeq;
|
|
193
|
+
const who = await memberAccess().catch(() => ({ email: "", scope: "" } as MemberAccess));
|
|
194
|
+
if (shownIdentity && identityOf(who) !== shownIdentity) {
|
|
195
|
+
shownIdentity = "";
|
|
196
|
+
s = commit({ ...BOOT, status: "loading" });
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const [read, profile] = await Promise.all([readAll(who), who.email ? loadMemberProfile("").catch(() => undefined) : Promise.resolve(undefined)]);
|
|
200
|
+
if (mine !== loadSeq) return now();
|
|
201
|
+
if (who.email) { try { await assertMemberAccess(who); } catch { return now(); } }
|
|
202
|
+
const joinedIds = new Set((read.memberships ?? []).filter((m) => String(m.status).toUpperCase() === "JOINED").map((m) => String(m.groupId)));
|
|
203
|
+
const pendingIds = new Set((read.memberships ?? []).filter((m) => String(m.status).toUpperCase() === "PENDING").map((m) => String(m.groupId)));
|
|
204
|
+
const mineGroups = read.groups.filter((g) => joinedIds.has(String(g.id)));
|
|
205
|
+
const counts = who.email && read.memberships ? await badges(mineGroups, who.email, read.memberId) : new Map<string, number | undefined>();
|
|
206
|
+
if (mine !== loadSeq) return now();
|
|
207
|
+
const myGroups = mineGroups.map((g) => myCard(g, counts.get(String(g.id))));
|
|
208
|
+
const suggested = read.groups.filter((g) => !joinedIds.has(String(g.id))).map((g) => suggestedCard(g, pendingIds.has(String(g.id)) ? "requested" : "none"));
|
|
209
|
+
const isMember = !!who.email;
|
|
210
|
+
shownIdentity = identityOf(who);
|
|
211
|
+
memberEmail = who.email;
|
|
212
|
+
const fallback = isMember && !read.memberships;
|
|
213
|
+
return {
|
|
214
|
+
...s,
|
|
215
|
+
status: "ready", isLoading: false, notLoading: true, errored: false, notErrored: true,
|
|
216
|
+
isMember, notMember: !isMember,
|
|
217
|
+
memberInitials: profile?.isMember ? profile.memberInitials : "", memberImage: profile?.isMember ? profile.memberImage : "",
|
|
218
|
+
hasMemberImage: !!(profile?.isMember && profile.memberImage), noMemberImage: !(profile?.isMember && profile.memberImage),
|
|
219
|
+
myGroups, noMyGroups: myGroups.length === 0,
|
|
220
|
+
suggested, noSuggested: suggested.length === 0,
|
|
221
|
+
suggestedTitle: fallback || !isMember ? copyParam("community.allTitle", "ALL GROUPS") : copyParam("community.suggestedTitle", "SUGGESTED GROUPS"),
|
|
222
|
+
emptyHidden: read.groups.length > 0, message: "",
|
|
223
|
+
};
|
|
224
|
+
} catch {
|
|
225
|
+
if (mine !== loadSeq) return now();
|
|
226
|
+
return { ...s, status: "error", isLoading: false, notLoading: true, errored: true, notErrored: false, myGroups: [], noMyGroups: true, suggested: [], noSuggested: true, emptyHidden: true };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The member-derived keys, dropped from a persisted snapshot. */
|
|
231
|
+
export const MEMBER_KEYS: Array<keyof S> = [
|
|
232
|
+
"isMember", "notMember", "memberInitials", "memberImage", "hasMemberImage", "noMemberImage", "myGroups", "noMyGroups", "suggested", "noSuggested", "suggestedTitle", "message",
|
|
233
|
+
];
|
|
234
|
+
|
|
235
|
+
/** The load-state keys. Every other key is member data (MEMBER_KEYS), so a snapshot held only
|
|
236
|
+
* these: a worker hydrated from it said "ready" over empty lists, and the screen stayed blank
|
|
237
|
+
* until a load landed (iPhone 17 Pro: Home tab → Community tab, 2026-11-19). Not hydrated, the
|
|
238
|
+
* worker starts at BOOT: the skeleton, until `load` fills the lists. */
|
|
239
|
+
export const LOAD_KEYS: Array<keyof S> = ["status", "isLoading", "notLoading", "errored", "notErrored", "emptyHidden"];
|
|
240
|
+
|
|
241
|
+
const svc = defineService<S, {
|
|
242
|
+
load: (s: S, arg?: unknown) => Promise<S>;
|
|
243
|
+
refresh: (s: S, arg?: unknown) => Promise<S>;
|
|
244
|
+
startRetry: (s: S) => S;
|
|
245
|
+
openGroup: (s: S, arg?: unknown) => S;
|
|
246
|
+
join: (s: S, arg?: unknown) => Promise<S>;
|
|
247
|
+
setBusy: (s: S, arg?: unknown) => S;
|
|
248
|
+
openForMember: (s: S, arg?: unknown) => Promise<S>;
|
|
249
|
+
}>(SERVICE, {
|
|
250
|
+
notHydrated: [...MEMBER_KEYS, ...LOAD_KEYS],
|
|
251
|
+
notPersisted: [...MEMBER_KEYS, ...LOAD_KEYS],
|
|
252
|
+
state: BOOT,
|
|
253
|
+
actions: {
|
|
254
|
+
load: (s, arg) => { stashCopy(arg); return load(s).then(commit); },
|
|
255
|
+
refresh: async (s, arg) => {
|
|
256
|
+
stashCopy(arg);
|
|
257
|
+
if (s.status === "error") await svc.startRetry();
|
|
258
|
+
return load(now()).then(commit);
|
|
259
|
+
},
|
|
260
|
+
startRetry: (s) => commit({ ...s, status: "loading", isLoading: true, notLoading: false, errored: false, notErrored: true }),
|
|
261
|
+
// A My groups card: mark the group seen now (clears its badge), then open it.
|
|
262
|
+
openGroup: (s, arg) => {
|
|
263
|
+
const id = strArg(arg, "id");
|
|
264
|
+
if (!id) return s;
|
|
265
|
+
if (memberEmail) {
|
|
266
|
+
const seen = readSeen();
|
|
267
|
+
seen[seenKey(memberEmail, id)] = Date.now();
|
|
268
|
+
writeSeen(seen);
|
|
269
|
+
}
|
|
270
|
+
const cleared = { ...s, myGroups: s.myGroups.map((g) => (g.id === id ? { ...g, badge: "", noBadge: true, badgeA11y: "" } : g)) };
|
|
271
|
+
return navigate(commit(cleared), { screenId: GROUP_SCREEN, args: { id } });
|
|
272
|
+
},
|
|
273
|
+
setBusy: (s, arg) => {
|
|
274
|
+
const id = strArg(arg, "id");
|
|
275
|
+
return commit({ ...s, suggested: s.suggested.map((g) => (g.id === id ? { ...g, busy: true, canJoin: false, cannotJoin: true } : g)) });
|
|
276
|
+
},
|
|
277
|
+
// Join in place. A visitor gets the sign-in sheet (the screen loads again after sign-in).
|
|
278
|
+
join: async (s, arg) => {
|
|
279
|
+
stashCopy(arg);
|
|
280
|
+
const id = strArg(arg, "id");
|
|
281
|
+
const who = await memberAccess().catch(() => ({ email: "" } as MemberAccess));
|
|
282
|
+
if (!who.email) {
|
|
283
|
+
const nav = await openMemberScreen({ ...(arg as Record<string, unknown> ?? {}), screenId: "himi_ps_community" });
|
|
284
|
+
return nav ? navigate(now(), nav) : now();
|
|
285
|
+
}
|
|
286
|
+
const card = s.suggested.find((g) => g.id === id);
|
|
287
|
+
if (!card || card.joined || card.busy) return s;
|
|
288
|
+
// A private group takes a join REQUEST (another Wix call): its own screen explains how to join.
|
|
289
|
+
if (card.isPrivate) return navigate(s, { screenId: GROUP_SCREEN, args: { id } });
|
|
290
|
+
await svc.setBusy({ id });
|
|
291
|
+
try {
|
|
292
|
+
const res = await joinGroup(id);
|
|
293
|
+
const status = String((res as { membership?: { status?: string }; status?: string } | undefined)?.membership?.status ?? (res as { status?: string } | undefined)?.status ?? "JOINED").toUpperCase();
|
|
294
|
+
const current = now();
|
|
295
|
+
const label = status === "PENDING" ? copyParam("community.requestedLabel", "Request sent") : copyParam("community.joinedLabel", "Joined");
|
|
296
|
+
// The card shows "Joined" here; the group moves to My groups on the next load.
|
|
297
|
+
return commit({ ...current, message: "", suggested: current.suggested.map((g) => (g.id === id ? { ...g, actionLabel: label, joined: true, notJoined: false, canJoin: false, cannotJoin: true, busy: false } : g)) });
|
|
298
|
+
} catch {
|
|
299
|
+
const current = now();
|
|
300
|
+
return commit({ ...current, message: copyParam("community.joinFailed", "You could not join this group. Try again."), suggested: current.suggested.map((g) => (g.id === id ? { ...g, busy: false, canJoin: true, cannotJoin: false } : g)) });
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
openForMember: async (_s, arg) => {
|
|
304
|
+
const nav = await openMemberScreen(arg);
|
|
305
|
+
return nav ? navigate(now(), nav) : now();
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
|
|
310
|
+
const live = (svc as { getState?: () => S | undefined }).getState?.();
|
|
311
|
+
if (live && typeof live === "object") for (const key of [...MEMBER_KEYS, ...LOAD_KEYS]) (live as unknown as Record<string, unknown>)[key] = BOOT[key];
|
|
312
|
+
}
|
|
313
|
+
// Load on start. iOS starts a new worker for a tab root when you come back to its tab, without a
|
|
314
|
+
// new onAppear (the screen never disappeared), so a restarted worker sat on the skeleton waiting
|
|
315
|
+
// for a load that never came (iPhone 17 Pro: Home tab → Community tab, 2026-11-19). The screen's
|
|
316
|
+
// own onAppear load, with its copy, supersedes this one (loadSeq); the copy has fallbacks.
|
|
317
|
+
void svc.load();
|
|
318
|
+
export { svc };
|