@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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Privacy — the Public profile switch and the blocked members list. The switch saves at once
|
|
2
|
+
// (joinCommunity / leaveCommunity), so this modal has no Save. Turning it off asks first, because
|
|
3
|
+
// the member also leaves the site's community; turning it on does not. A member record with no
|
|
4
|
+
// privacy status shows no switch, only a notice.
|
|
5
|
+
import { defineService } from "@himalaya/state";
|
|
6
|
+
import { alert } from "@himalaya/ui";
|
|
7
|
+
import { getMyMember, joinCommunity, leaveCommunity } from "@himalaya/wix-members";
|
|
8
|
+
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
9
|
+
import { svc as blockedMembers } from "./blocked-members.js";
|
|
10
|
+
import {
|
|
11
|
+
businessNameOf, clean, fetchMember, isSignedOut, loadErrorVariant, sameAccess, signedOutError, type WixMemberResponse,
|
|
12
|
+
} from "./shared.js";
|
|
13
|
+
|
|
14
|
+
interface S {
|
|
15
|
+
phase: "loading" | "ready" | "error" | "signedOut";
|
|
16
|
+
errorVariant: "offline" | "server";
|
|
17
|
+
memberId: string;
|
|
18
|
+
memberEmail: string;
|
|
19
|
+
memberScope: string;
|
|
20
|
+
businessName: string;
|
|
21
|
+
/** "Choose if other members of {business} can see your profile." */
|
|
22
|
+
description: string;
|
|
23
|
+
/** The API returned PUBLIC or PRIVATE. Otherwise the switch is replaced by a notice. */
|
|
24
|
+
privacyKnown: boolean;
|
|
25
|
+
privacyUnknown: boolean;
|
|
26
|
+
isPublic: boolean;
|
|
27
|
+
statusLine: string;
|
|
28
|
+
busy: boolean;
|
|
29
|
+
/** A switch change that did not save. */
|
|
30
|
+
errorText: string;
|
|
31
|
+
noErrorText: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const EMPTY: S = {
|
|
35
|
+
phase: "loading", errorVariant: "server", memberId: "", memberEmail: "", memberScope: "", businessName: "",
|
|
36
|
+
description: "", privacyKnown: false, privacyUnknown: true, isPublic: false, statusLine: "", busy: false,
|
|
37
|
+
errorText: "", noErrorText: true,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function statusLine(isPublic: boolean): string {
|
|
41
|
+
return isPublic
|
|
42
|
+
? copyParam("accountSettings.publicProfileOn", "Other members can see your profile.")
|
|
43
|
+
: copyParam("accountSettings.publicProfileOff", "Only you can see your profile.");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function withStatus(s: S, privacyStatus: unknown): S {
|
|
47
|
+
const status = clean(privacyStatus).toUpperCase();
|
|
48
|
+
const known = status === "PUBLIC" || status === "PRIVATE";
|
|
49
|
+
const isPublic = status === "PUBLIC";
|
|
50
|
+
return { ...s, privacyKnown: known, privacyUnknown: !known, isPublic, statusLine: known ? statusLine(isPublic) : "" };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let loadVersion = 0;
|
|
54
|
+
let mutationInFlight = false;
|
|
55
|
+
/** The member moved the switch again while a change was saving. That move is not saved, so the
|
|
56
|
+
* switch must be drawn again from the result, or it keeps showing the dropped position. */
|
|
57
|
+
let flipDropped = false;
|
|
58
|
+
|
|
59
|
+
const svc = defineService<S, {
|
|
60
|
+
load: (s: S, arg?: unknown) => Promise<S>;
|
|
61
|
+
showLoading: (s: S) => S;
|
|
62
|
+
begin: (s: S, patch: Partial<S>) => S;
|
|
63
|
+
setPublic: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
64
|
+
}>("himiBrandedAccountPrivacy", {
|
|
65
|
+
state: { ...EMPTY },
|
|
66
|
+
notHydrated: Object.keys(EMPTY) as (keyof S)[],
|
|
67
|
+
notPersisted: Object.keys(EMPTY) as (keyof S)[],
|
|
68
|
+
actions: {
|
|
69
|
+
showLoading: (s) => ({ ...EMPTY, businessName: s.businessName, description: s.description }),
|
|
70
|
+
begin: (s, patch) => ({ ...s, ...patch, noErrorText: !(patch.errorText ?? s.errorText) }),
|
|
71
|
+
load: async (_s, arg): Promise<S> => {
|
|
72
|
+
const version = ++loadVersion;
|
|
73
|
+
stashCopy(arg);
|
|
74
|
+
const businessName = businessNameOf(arg) || svc.getState().businessName;
|
|
75
|
+
const description = copyTemplate("accountSettings.privacyDescription", "Choose if other members of {business} can see your profile.", { business: businessName });
|
|
76
|
+
if (svc.getState().phase !== "loading") await svc.showLoading();
|
|
77
|
+
// The blocked members section loads with the modal; its own onAppear does the same on a device.
|
|
78
|
+
void blockedMembers.load(arg).catch(() => undefined);
|
|
79
|
+
try {
|
|
80
|
+
const { member, email, scope } = await fetchMember();
|
|
81
|
+
if (version !== loadVersion) return svc.getState();
|
|
82
|
+
return withStatus({ ...EMPTY, phase: "ready", memberId: clean(member.id), memberEmail: email, memberScope: scope, businessName, description }, member.privacyStatus);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (version !== loadVersion) return svc.getState();
|
|
85
|
+
return { ...EMPTY, businessName, description, phase: isSignedOut(error) ? "signedOut" : "error", errorVariant: loadErrorVariant(error) };
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
setPublic: async (s, arg): Promise<S | undefined> => {
|
|
89
|
+
if (s.phase !== "ready" || !s.privacyKnown || !s.memberId) return undefined;
|
|
90
|
+
if (mutationInFlight) { flipDropped = true; return undefined; }
|
|
91
|
+
const value = (arg as { value?: unknown } | undefined)?.value;
|
|
92
|
+
const wantPublic = value === true || value === "true";
|
|
93
|
+
if (wantPublic === s.isPublic) return undefined;
|
|
94
|
+
flipDropped = false;
|
|
95
|
+
// Draw the switch from `final`; after a dropped move, flip it first so the host redraws it.
|
|
96
|
+
const settle = async (final: S): Promise<S> => {
|
|
97
|
+
if (flipDropped) { flipDropped = false; await svc.begin({ isPublic: !final.isPublic }); }
|
|
98
|
+
return final;
|
|
99
|
+
};
|
|
100
|
+
mutationInFlight = true;
|
|
101
|
+
try {
|
|
102
|
+
// The switch already moved: follow it, so that a Cancel below moves it back.
|
|
103
|
+
await svc.begin({ isPublic: wantPublic, errorText: "" });
|
|
104
|
+
if (!wantPublic) {
|
|
105
|
+
let confirmed = false;
|
|
106
|
+
try {
|
|
107
|
+
const answer = await alert({
|
|
108
|
+
title: copyParam("accountSettings.makePrivateTitle", "Make your profile private?"),
|
|
109
|
+
message: copyTemplate("accountSettings.makePrivateBody", "Other members can't see your profile. You also leave the community of {business}.", { business: s.businessName }),
|
|
110
|
+
confirmLabel: copyParam("accountSettings.makePrivateConfirm", "Make private"),
|
|
111
|
+
cancelLabel: copyParam("common.cancelCta", "Cancel"),
|
|
112
|
+
});
|
|
113
|
+
confirmed = answer.confirmed;
|
|
114
|
+
} catch { /* no presenter: nothing was confirmed */ }
|
|
115
|
+
// Cancel: the switch and its status line go back to public together.
|
|
116
|
+
if (!confirmed) return await settle({ ...svc.getState(), isPublic: true, statusLine: statusLine(true) });
|
|
117
|
+
}
|
|
118
|
+
await svc.begin({ busy: true });
|
|
119
|
+
if (!(await sameAccess(s.memberEmail, s.memberScope))) throw signedOutError();
|
|
120
|
+
const response = wantPublic ? await joinCommunity() : await leaveCommunity();
|
|
121
|
+
if (response.member?.id !== s.memberId || !response.member.privacyStatus) throw new Error("The profile privacy update was not confirmed for this member.");
|
|
122
|
+
const refreshed = await getMyMember({ fieldsets: ["FULL"] }) as WixMemberResponse;
|
|
123
|
+
if (refreshed.member?.id !== s.memberId || !(await sameAccess(s.memberEmail, s.memberScope))) throw signedOutError();
|
|
124
|
+
// A stale read or a rejected write leaves the OLD status in the readback: that is not a save.
|
|
125
|
+
const status = clean(refreshed.member.privacyStatus).toUpperCase();
|
|
126
|
+
if (status !== (wantPublic ? "PUBLIC" : "PRIVATE")) throw new Error("The profile privacy update was not confirmed by the readback.");
|
|
127
|
+
return await settle({ ...withStatus(svc.getState(), status), busy: false, errorText: "", noErrorText: true });
|
|
128
|
+
} catch (error) {
|
|
129
|
+
// The member changed mid-save: show none of the previous member's privacy, only Sign in.
|
|
130
|
+
if (isSignedOut(error)) return { ...EMPTY, businessName: s.businessName, description: s.description, phase: "signedOut" };
|
|
131
|
+
const latest = svc.getState();
|
|
132
|
+
return await settle({ ...latest, isPublic: s.isPublic, statusLine: statusLine(s.isPublic), busy: false,
|
|
133
|
+
errorText: copyParam("accountSettings.privacyError", "Your privacy setting was not updated."), noErrorText: false });
|
|
134
|
+
} finally { mutationInFlight = false; }
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export { svc as privacy };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Shared by the Account settings menu and its three modals (Personal info, Login info with its
|
|
2
|
+
// Change password step, Privacy). Each modal is its own screen, so each boots this bundle in its
|
|
3
|
+
// own worker and loads the member itself: nothing here is shared state, only the checks.
|
|
4
|
+
import { dispatch } from "@himalaya/dispatch";
|
|
5
|
+
import { classifyLoadError } from "@himalaya/state";
|
|
6
|
+
import { getMyMember } from "@himalaya/wix-members";
|
|
7
|
+
import { getMyData } from "@himalaya/wix-users";
|
|
8
|
+
import { hostSiteFromInput } from "../_shared/branded-lite-hosted.js";
|
|
9
|
+
import { memberAccess } from "../_shared/member-access.js";
|
|
10
|
+
import type { MemberAccountRoutes } from "../_shared/member-account-routes.js";
|
|
11
|
+
|
|
12
|
+
export type WixMemberRecord = {
|
|
13
|
+
id?: string;
|
|
14
|
+
loginEmail?: string;
|
|
15
|
+
contact?: {
|
|
16
|
+
firstName?: string;
|
|
17
|
+
lastName?: string;
|
|
18
|
+
phones?: string[];
|
|
19
|
+
birthdate?: string;
|
|
20
|
+
company?: string;
|
|
21
|
+
jobTitle?: string;
|
|
22
|
+
customFields?: Record<string, { name?: string; value?: unknown } | undefined>;
|
|
23
|
+
};
|
|
24
|
+
profile?: { nickname?: string; title?: string; slug?: string; photo?: { id?: string; url?: string } };
|
|
25
|
+
privacyStatus?: string;
|
|
26
|
+
};
|
|
27
|
+
export type WixMemberResponse = { member?: WixMemberRecord };
|
|
28
|
+
|
|
29
|
+
export function rawText(value: unknown): string { return typeof value === "string" ? value : ""; }
|
|
30
|
+
export function clean(value: unknown): string { return rawText(value).trim(); }
|
|
31
|
+
|
|
32
|
+
export function signedOutError(): Error {
|
|
33
|
+
return Object.assign(new Error("signed_out"), { code: "signed_out" });
|
|
34
|
+
}
|
|
35
|
+
export function isSignedOut(error: unknown): boolean {
|
|
36
|
+
return (error as { code?: string } | null)?.code === "signed_out";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The load-error variant the modals' ErrorState draws: `offline` only when the request never left. */
|
|
40
|
+
export function loadErrorVariant(error: unknown): "offline" | "server" {
|
|
41
|
+
return classifyLoadError(error) === "offline" ? "offline" : "server";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The site a hosted build was opened for (`himalaya.input.__himiHostSite`), or "" when the build
|
|
45
|
+
* is not hosted. A hosted build serves many businesses, so this wins over the build's own name. */
|
|
46
|
+
export const hostedBusinessName = clean(hostSiteFromInput((globalThis as { himalaya?: { input?: unknown } }).himalaya?.input)?.name);
|
|
47
|
+
|
|
48
|
+
/** The business name each modal shows as its subtitle and in its copy: the hosted site's, else the
|
|
49
|
+
* descriptor param (the build's own business). */
|
|
50
|
+
export function businessNameOf(arg: unknown): string {
|
|
51
|
+
return hostedBusinessName || clean((arg as { businessName?: unknown } | undefined)?.businessName);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The signed-in member's own record, read with the member's token, and the identity it was read for. */
|
|
55
|
+
export async function fetchMember(siteUrlInput?: unknown): Promise<{ email: string; scope: string; siteUrl: string; member: WixMemberRecord & { id: string } }> {
|
|
56
|
+
const access = await memberAccess();
|
|
57
|
+
if (!access.email) throw signedOutError();
|
|
58
|
+
const response = await getMyMember({ fieldsets: ["FULL"] }) as WixMemberResponse;
|
|
59
|
+
if (!response.member?.id) throw new Error("The signed-in member profile is unavailable.");
|
|
60
|
+
const after = await memberAccess();
|
|
61
|
+
if (!after.email || after.email !== access.email || after.scope !== access.scope) throw signedOutError();
|
|
62
|
+
const siteUrl = clean(siteUrlInput).replace(/\/$/, "");
|
|
63
|
+
return { email: access.email, scope: access.scope, siteUrl, member: response.member as WixMemberRecord & { id: string } };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The same member is still signed in, by email, scope and member id. */
|
|
67
|
+
export async function currentMemberRecordMatches(email: string, scope: string, memberId: string): Promise<boolean> {
|
|
68
|
+
const before = await memberAccess();
|
|
69
|
+
if (!before.email || before.email !== email || before.scope !== scope) return false;
|
|
70
|
+
const response = await getMyMember({ fieldsets: ["FULL"] }) as WixMemberResponse;
|
|
71
|
+
const after = await memberAccess();
|
|
72
|
+
return response.member?.id === memberId && after.email === email && after.scope === scope;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Who is signed in: a member, nobody, or `unavailable` when the host could not say at all.
|
|
76
|
+
* `memberAccess()` reads both failures as "nobody"; the menu must not ask a member to sign in
|
|
77
|
+
* because the identity read failed. Older hosts without `memberIdentity` answer through
|
|
78
|
+
* wix-users (the same rung memberAccess uses); a host that fails both ways is unavailable. */
|
|
79
|
+
export async function memberIdentityState(): Promise<"member" | "guest" | "unavailable"> {
|
|
80
|
+
let raw: unknown;
|
|
81
|
+
let unavailable = false;
|
|
82
|
+
try { raw = await dispatch("himi.wix.memberIdentity"); }
|
|
83
|
+
catch { unavailable = true; }
|
|
84
|
+
const value = raw as { email?: unknown; signedIn?: unknown; payload?: { email?: unknown; signedIn?: unknown } } | null;
|
|
85
|
+
// A host can say a member is signed in before it has the email.
|
|
86
|
+
if (clean(value?.email ?? value?.payload?.email) || (value?.signedIn ?? value?.payload?.signedIn) === true) return "member";
|
|
87
|
+
if (!unavailable) return "guest";
|
|
88
|
+
try {
|
|
89
|
+
const profile = await getMyData();
|
|
90
|
+
return clean(profile.email ?? profile.contactEmail) ? "member" : "guest";
|
|
91
|
+
} catch {
|
|
92
|
+
return "unavailable";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Same identity by email and scope alone (no network). */
|
|
97
|
+
export async function sameAccess(email: string, scope: string): Promise<boolean> {
|
|
98
|
+
const current = await memberAccess();
|
|
99
|
+
return !!current.email && current.email === email && current.scope === scope;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** An http(s) URL split at its authority (between `//` and the first `/`, `?` or `#`). A worker has
|
|
103
|
+
* no URL global, so the authority is split by hand. */
|
|
104
|
+
const HTTP_URL = /^https?:\/\/([^/?#]*)(?:[/?#]\S*)?$/i;
|
|
105
|
+
/** A website handoff needs a real http(s) site: the documented placeholder (example.com) never counts,
|
|
106
|
+
* and neither does a URL with userinfo (`https://shop.acme.com@evil.example` opens evil.example). */
|
|
107
|
+
export function siteHandoffAvailable(siteUrl: string): boolean {
|
|
108
|
+
const match = HTTP_URL.exec(siteUrl);
|
|
109
|
+
if (!match || siteUrl.includes("\\")) return false;
|
|
110
|
+
const authority = match[1];
|
|
111
|
+
if (authority.includes("@")) return false;
|
|
112
|
+
const host = authority.replace(/:\d+$/, "").toLowerCase();
|
|
113
|
+
if (!host || /[\s:]/.test(host)) return false;
|
|
114
|
+
return host !== "example.com" && !host.endsWith(".example.com");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function memberInitials(firstName: string, lastName: string, nickname: string): string {
|
|
118
|
+
return ([firstName[0], lastName[0]].filter(Boolean).join("") || nickname.slice(0, 1) || "M").toUpperCase();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Login info's Password section.
|
|
122
|
+
* - `row`: this app changes the password (a native app on HimalayaCore 1.5.0 or later).
|
|
123
|
+
* - `notice-preview`: the web host, a preview of the app.
|
|
124
|
+
* - `notice-here`: inside another Wix app, an older binary, or an unknown platform and version. */
|
|
125
|
+
export type PasswordMode = "row" | "notice-preview" | "notice-here";
|
|
126
|
+
export function passwordMode(routes: Pick<MemberAccountRoutes, "passwordCredentials" | "webPreview">): PasswordMode {
|
|
127
|
+
if (routes.passwordCredentials) return "row";
|
|
128
|
+
return routes.webPreview ? "notice-preview" : "notice-here";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The case the Password section draws: the mode, and for a notice whether it links the website. */
|
|
132
|
+
export function passwordCase(mode: PasswordMode, siteLink: boolean): string {
|
|
133
|
+
if (mode === "row") return "row";
|
|
134
|
+
const base = mode === "notice-preview" ? "preview" : "here";
|
|
135
|
+
return siteLink ? `${base}-link` : base;
|
|
136
|
+
}
|
|
@@ -64181,7 +64181,8 @@ const SCREENS = runtimeSetting({
|
|
|
64181
64181
|
"integrity": "",
|
|
64182
64182
|
"contentType": "application/javascript+ts-bundle",
|
|
64183
64183
|
"declaredCapabilities": [
|
|
64184
|
-
"wix_api"
|
|
64184
|
+
"wix_api",
|
|
64185
|
+
"share"
|
|
64185
64186
|
],
|
|
64186
64187
|
"minBinaryVersion": "0.1.0",
|
|
64187
64188
|
"bundleVersion": "0.0.1"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// A Wix Portfolio project's free "details" rows (label + text), read the same way by every worker
|
|
2
|
+
// that shows a project: the list, the detail and a template's Home rail.
|
|
3
|
+
//
|
|
4
|
+
// Wix Portfolio has no field of its own for a location, a client, a year or a duration. Owners keep
|
|
5
|
+
// them as details with those labels. A worker maps the four known labels to their places (a
|
|
6
|
+
// location line, three fact chips) and shows any other detail as a plain row under the
|
|
7
|
+
// description. Labels match case-insensitively; a detail with no text (and no link text) is skipped.
|
|
8
|
+
import type { WixPortfolioCollection, WixPortfolioProject, WixPortfolioProjectDetail } from "@himalaya/wix-portfolio";
|
|
9
|
+
|
|
10
|
+
export interface ProjectFact { id: string; label: string; value: string; icon: string }
|
|
11
|
+
export interface ProjectDetailRow { id: string; label: string; value: string }
|
|
12
|
+
export interface ProjectDetails {
|
|
13
|
+
/** The "Location" detail ("" when the project has none). */
|
|
14
|
+
location: string;
|
|
15
|
+
/** Client, Year and Duration, in that order, only those the project has. */
|
|
16
|
+
facts: ProjectFact[];
|
|
17
|
+
/** Every other detail, in the owner's order. */
|
|
18
|
+
others: ProjectDetailRow[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The fact chips' labels and glyphs, in display order (glyphs from the icon catalog). */
|
|
22
|
+
const FACT_LABELS: Array<{ key: string; icon: string }> = [
|
|
23
|
+
{ key: "client", icon: "person" },
|
|
24
|
+
{ key: "year", icon: "calendar" },
|
|
25
|
+
{ key: "duration", icon: "clock" },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const clean = (value: unknown): string => (typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "");
|
|
29
|
+
|
|
30
|
+
function valueOf(detail: WixPortfolioProjectDetail): string {
|
|
31
|
+
return clean(detail.text) || clean(detail.link?.text);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function projectDetails(project: Pick<WixPortfolioProject, "details"> | undefined): ProjectDetails {
|
|
35
|
+
const rows = (Array.isArray(project?.details) ? project!.details : [])
|
|
36
|
+
.map((detail, i) => ({ i, label: clean(detail?.label), value: valueOf(detail ?? {}) }))
|
|
37
|
+
.filter((row) => row.label && row.value);
|
|
38
|
+
const byKey = new Map<string, { i: number; label: string; value: string }>();
|
|
39
|
+
for (const row of rows) {
|
|
40
|
+
const key = row.label.toLowerCase();
|
|
41
|
+
if (!byKey.has(key)) byKey.set(key, row);
|
|
42
|
+
}
|
|
43
|
+
const location = byKey.get("location")?.value ?? "";
|
|
44
|
+
const facts: ProjectFact[] = FACT_LABELS.flatMap(({ key, icon }) => {
|
|
45
|
+
const row = byKey.get(key);
|
|
46
|
+
return row ? [{ id: `fact-${key}`, label: row.label, value: row.value, icon }] : [];
|
|
47
|
+
});
|
|
48
|
+
const used = new Set(["location", ...FACT_LABELS.map((f) => f.key)].map((key) => byKey.get(key)?.i).filter((i) => i !== undefined));
|
|
49
|
+
const others = rows.filter((row) => !used.has(row.i)).map((row) => ({ id: `detail-${row.i}`, label: row.label, value: row.value }));
|
|
50
|
+
return { location, facts, others };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The visible collections by id ("Strategy", "Operations"…); hidden ones are left out. */
|
|
54
|
+
export function collectionNames(collections: readonly WixPortfolioCollection[] | undefined): Map<string, string> {
|
|
55
|
+
const out = new Map<string, string>();
|
|
56
|
+
for (const c of collections ?? []) {
|
|
57
|
+
const title = clean(c?.title);
|
|
58
|
+
if (c?.id && title && c.hidden !== true) out.set(c.id, title);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The project's first visible collection name ("" when it is in none). */
|
|
64
|
+
export function projectCollection(project: Pick<WixPortfolioProject, "collectionIds"> | undefined, names: Map<string, string>): { id: string; name: string } {
|
|
65
|
+
for (const id of project?.collectionIds ?? []) {
|
|
66
|
+
const name = names.get(id);
|
|
67
|
+
if (name) return { id, name };
|
|
68
|
+
}
|
|
69
|
+
return { id: "", name: "" };
|
|
70
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// the customer's own. Samples appear only in the host's explicit sample preview
|
|
5
5
|
// (_shared/branded-load-state.ts).
|
|
6
6
|
import { defineService } from "../_shared/collection-service.js";
|
|
7
|
-
import { LOADING, loaded, loadFailed, type LoadCopy, type LoadFlags } from "../_shared/branded-load-state.js";
|
|
7
|
+
import { LOADING, loaded, loadFailed, needsSignIn, type LoadCopy, type LoadFlags } from "../_shared/branded-load-state.js";
|
|
8
8
|
import { requireMemberRead, memberReadFailure } from "../_shared/member-read.js";
|
|
9
9
|
import { queryCoupons, type WixCoupon } from "@himalaya/wix-coupons";
|
|
10
10
|
import { copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
@@ -76,7 +76,18 @@ const svc = defineService<S, { load: (s: S) => Promise<S> }>("himiBrandedCoupons
|
|
|
76
76
|
const coupons = couponRows(((r as unknown as { coupons?: WixCoupon[] }).coupons) ?? []);
|
|
77
77
|
return { ...s, ...loaded("coupons", coupons, COPY) };
|
|
78
78
|
} catch (err) {
|
|
79
|
-
|
|
79
|
+
const failure = await memberReadFailure(err);
|
|
80
|
+
// Wix answers a SIGNED-IN member 401 too ("Reading coupons is not permitted": coupons are
|
|
81
|
+
// readable by the site's owner only). Signing in cannot fix that, so the member sees that
|
|
82
|
+
// offers are not shown here, never a Sign in button while signed in. A visitor's
|
|
83
|
+
// failure is memberReadFailure's sign-in error and keeps its Sign in path.
|
|
84
|
+
if (failure === err && needsSignIn(err)) {
|
|
85
|
+
const next = loaded("coupons", [] as Row[], COPY);
|
|
86
|
+
// The owner's sample preview fills the list: its rows speak for themselves, with no empty line beside them.
|
|
87
|
+
if (next.coupons.length) return { ...s, ...next };
|
|
88
|
+
return { ...s, ...next, emptyText: copyParam("coupons.memberUnavailableText", "Offers aren't shown in the app yet.") };
|
|
89
|
+
}
|
|
90
|
+
return { ...s, ...loadFailed("coupons", failure, COPY) };
|
|
80
91
|
}
|
|
81
92
|
},
|
|
82
93
|
},
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { descriptionBody } from "../_shared/rich-body.js";
|
|
2
2
|
// himi-branded-lite-portfolio — real, public Wix Portfolio projects.
|
|
3
3
|
// Empty and error states stay explicit; media IDs are normalized for every host.
|
|
4
|
+
//
|
|
5
|
+
// Collections: each row names its first visible collection (`collection`), and `collections` are
|
|
6
|
+
// the filter chips (All + each collection that holds a listed project). `projects` is the list for
|
|
7
|
+
// the chip that is on; "all" (the default) is every project, as before.
|
|
4
8
|
import { defineService } from "../_shared/collection-service.js";
|
|
5
|
-
import { listProjects, portfolioCoverRef, type WixPortfolioProject } from "@himalaya/wix-portfolio";
|
|
9
|
+
import { listCollections, listProjects, portfolioCoverRef, type WixPortfolioProject } from "@himalaya/wix-portfolio";
|
|
6
10
|
import { wixMediaUrl } from "@himalaya/wix-media";
|
|
11
|
+
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
12
|
+
import { collectionNames, projectCollection, projectDetails } from "../_shared/portfolio-details.js";
|
|
7
13
|
|
|
8
14
|
interface Row {
|
|
9
15
|
id: string;
|
|
@@ -13,7 +19,18 @@ interface Row {
|
|
|
13
19
|
initial: string;
|
|
14
20
|
hasImage: boolean;
|
|
15
21
|
noImage: boolean;
|
|
22
|
+
/** The project's collection name ("" when it is in none). */
|
|
23
|
+
collection: string;
|
|
24
|
+
collectionId: string;
|
|
25
|
+
hasCollection: boolean;
|
|
26
|
+
noCollection: boolean;
|
|
27
|
+
/** The "Location" detail ("" when none). */
|
|
28
|
+
location: string;
|
|
29
|
+
noLocation: boolean;
|
|
16
30
|
}
|
|
31
|
+
/** `notSelected` is `selected`'s inverse, so a chip row can hide its "on" variant with `hiddenWhen`. */
|
|
32
|
+
interface Chip { id: string; label: string; selected: boolean; notSelected: boolean }
|
|
33
|
+
const chipOf = (id: string, label: string, selected: boolean): Chip => ({ id, label, selected, notSelected: !selected });
|
|
17
34
|
interface S {
|
|
18
35
|
status: "loading" | "ready" | "error";
|
|
19
36
|
projects: Row[];
|
|
@@ -21,11 +38,31 @@ interface S {
|
|
|
21
38
|
isMock: boolean;
|
|
22
39
|
notMock: boolean;
|
|
23
40
|
mockBanner: string;
|
|
41
|
+
/** All + one chip per collection that holds a listed project; [] when there is none. */
|
|
42
|
+
collections: Chip[];
|
|
43
|
+
noCollections: boolean;
|
|
44
|
+
selectedCollection: string;
|
|
45
|
+
/** State gates for a screen's skeleton, error and empty components. */
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
notLoading: boolean;
|
|
48
|
+
notErrored: boolean;
|
|
49
|
+
/** False only when the read is done and found no project at all. Not `noEmpty`: the collection
|
|
50
|
+
* chrome reads a top-level `noEmpty: false` as "the domain shows its own empty state" and hides
|
|
51
|
+
* its designed one (collection-service `noEmptySource`). */
|
|
52
|
+
noEmptyProjects: boolean;
|
|
24
53
|
}
|
|
25
54
|
|
|
26
|
-
|
|
55
|
+
const gates = (status: S["status"], empty: boolean) => ({
|
|
56
|
+
isLoading: status === "loading", notLoading: status !== "loading", notErrored: status !== "error", noEmptyProjects: !(status === "ready" && empty),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const ALL = "all";
|
|
60
|
+
|
|
61
|
+
function norm(project: WixPortfolioProject, names: Map<string, string>): Row {
|
|
27
62
|
const title = (project.title || "Project").trim() || "Project";
|
|
28
63
|
const image = wixMediaUrl(portfolioCoverRef(project.coverImage));
|
|
64
|
+
const collection = projectCollection(project, names);
|
|
65
|
+
const location = projectDetails(project).location;
|
|
29
66
|
return {
|
|
30
67
|
id: project.id || project.slug || title,
|
|
31
68
|
title,
|
|
@@ -34,21 +71,65 @@ function norm(project: WixPortfolioProject): Row {
|
|
|
34
71
|
initial: (title[0] || "#").toUpperCase(),
|
|
35
72
|
hasImage: Boolean(image),
|
|
36
73
|
noImage: !image,
|
|
74
|
+
collection: collection.name,
|
|
75
|
+
collectionId: collection.id,
|
|
76
|
+
hasCollection: Boolean(collection.name),
|
|
77
|
+
noCollection: !collection.name,
|
|
78
|
+
location,
|
|
79
|
+
noLocation: !location,
|
|
37
80
|
};
|
|
38
81
|
}
|
|
39
82
|
|
|
40
|
-
|
|
41
|
-
|
|
83
|
+
/** Every row read by the last load; `projects` is this list filtered by the chip that is on. */
|
|
84
|
+
let allRows: Row[] = [];
|
|
85
|
+
|
|
86
|
+
function chipsFor(rows: Row[], names: Map<string, string>, selected: string): Chip[] {
|
|
87
|
+
const used = [...names.entries()].filter(([id]) => rows.some((row) => row.collectionId === id));
|
|
88
|
+
// One collection only: a chip row with "All" and that one says nothing.
|
|
89
|
+
if (used.length < 2) return [];
|
|
90
|
+
return [
|
|
91
|
+
chipOf(ALL, copyParam("portfolio.allChip", "All"), selected === ALL),
|
|
92
|
+
...used.map(([id, label]) => chipOf(id, label, selected === id)),
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function view(s: S, selected: string, names?: Map<string, string>): S {
|
|
97
|
+
const chips = names ? chipsFor(allRows, names, selected) : s.collections.map((chip) => chipOf(chip.id, chip.label, chip.id === selected));
|
|
98
|
+
const valid = selected === ALL || chips.some((chip) => chip.id === selected) ? selected : ALL;
|
|
99
|
+
const projects = valid === ALL ? allRows : allRows.filter((row) => row.collectionId === valid);
|
|
100
|
+
return {
|
|
101
|
+
...s,
|
|
102
|
+
projects,
|
|
103
|
+
collections: valid === selected ? chips : chips.map((chip) => chipOf(chip.id, chip.label, chip.id === ALL)),
|
|
104
|
+
noCollections: chips.length === 0,
|
|
105
|
+
selectedCollection: valid,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const svc = defineService<S, { load: (s: S, arg?: unknown) => Promise<S>; setCollection: (s: S, arg?: unknown) => S }>("himiBrandedPortfolio", {
|
|
110
|
+
state: { status: "loading", projects: [], emptyText: "", isMock: false, notMock: true, mockBanner: "", collections: [], noCollections: true, selectedCollection: ALL, ...gates("loading", true) },
|
|
42
111
|
actions: {
|
|
43
|
-
load: async (s) => {
|
|
112
|
+
load: async (s, arg) => {
|
|
113
|
+
stashCopy(arg);
|
|
44
114
|
try {
|
|
45
|
-
const response = await
|
|
46
|
-
|
|
47
|
-
|
|
115
|
+
const [response, collections] = await Promise.all([
|
|
116
|
+
listProjects(50),
|
|
117
|
+
// The chips are extra: a failed collections read leaves the list without them.
|
|
118
|
+
listCollections(100).then((r) => r.collections ?? []).catch(() => []),
|
|
119
|
+
]);
|
|
120
|
+
const names = collectionNames(collections);
|
|
121
|
+
allRows = (response.projects ?? []).filter((project) => project.hidden !== true).map((project) => norm(project, names));
|
|
122
|
+
return view({ ...s, status: "ready", emptyText: allRows.length ? "" : "No published projects are available yet.", isMock: false, notMock: true, mockBanner: "", ...gates("ready", allRows.length === 0) }, s.selectedCollection || ALL, names);
|
|
48
123
|
} catch {
|
|
49
|
-
|
|
124
|
+
allRows = [];
|
|
125
|
+
return { ...s, status: "error", projects: [], emptyText: "Portfolio projects could not be loaded. Try again.", isMock: false, notMock: true, mockBanner: "", collections: [], noCollections: true, selectedCollection: ALL, ...gates("error", true) };
|
|
50
126
|
}
|
|
51
127
|
},
|
|
128
|
+
// A chip tap: { id } — "all" or a collection id.
|
|
129
|
+
setCollection: (s, arg) => {
|
|
130
|
+
const id = (arg as { id?: unknown } | undefined)?.id;
|
|
131
|
+
return view(s, typeof id === "string" && id ? id : ALL);
|
|
132
|
+
},
|
|
52
133
|
},
|
|
53
134
|
});
|
|
54
135
|
svc.load();
|
|
@@ -2,8 +2,16 @@ import { descriptionBody } from "../_shared/rich-body.js";
|
|
|
2
2
|
// himi-branded-lite-portfolio-project — real Wix Portfolio project detail.
|
|
3
3
|
// The public project row is resolved again from Wix, then its ordered project
|
|
4
4
|
// items supply the actual image/video/text story. No sample project is invented.
|
|
5
|
+
//
|
|
6
|
+
// The project's collection (`collection`), its "Location" detail (`location`), its Client, Year and
|
|
7
|
+
// Duration details as fact chips (`facts`) and every other detail (`details`) come from the same
|
|
8
|
+
// list read (_shared/portfolio-details.ts). Each collapses when the project has none. `share`
|
|
9
|
+
// opens the system share sheet with the project's page on the site when Wix gives one, else the
|
|
10
|
+
// site's own address when the screen passes it (`siteUrl` load param); with neither, no share.
|
|
5
11
|
import { defineService } from "@himalaya/state";
|
|
6
|
-
import { listProjectItems, listProjects, portfolioCoverRef, type WixPortfolioProjectItem } from "@himalaya/wix-portfolio";
|
|
12
|
+
import { listCollections, listProjectItems, listProjects, portfolioCoverRef, type WixPortfolioProjectItem } from "@himalaya/wix-portfolio";
|
|
13
|
+
import { share as shareSheet } from "@himalaya/share";
|
|
14
|
+
import { collectionNames, projectCollection, projectDetails, type ProjectDetailRow, type ProjectFact } from "../_shared/portfolio-details.js";
|
|
7
15
|
import { wixMediaUrl, WIX_DETAIL_IMAGE } from "@himalaya/wix-media";
|
|
8
16
|
import { copyParam, stashCopy } from "../_shared/himi-copy.js";
|
|
9
17
|
import { presence, type PresenceFlags } from "../_shared/detail-presence.js";
|
|
@@ -41,8 +49,24 @@ interface State extends PresenceFlags {
|
|
|
41
49
|
noItems: boolean;
|
|
42
50
|
hideContent: boolean;
|
|
43
51
|
noEmpty: boolean;
|
|
52
|
+
collection: string;
|
|
53
|
+
noCollection: boolean;
|
|
54
|
+
location: string;
|
|
55
|
+
noLocation: boolean;
|
|
56
|
+
facts: ProjectFact[];
|
|
57
|
+
noFacts: boolean;
|
|
58
|
+
details: ProjectDetailRow[];
|
|
59
|
+
noDetails: boolean;
|
|
60
|
+
/** The project's page on the published site ("" when Wix gives none: no share). */
|
|
61
|
+
shareUrl: string;
|
|
62
|
+
noShare: boolean;
|
|
44
63
|
}
|
|
45
64
|
|
|
65
|
+
const NO_DETAILS = {
|
|
66
|
+
collection: "", noCollection: true, location: "", noLocation: true, facts: [] as ProjectFact[], noFacts: true,
|
|
67
|
+
details: [] as ProjectDetailRow[], noDetails: true, shareUrl: "", noShare: true,
|
|
68
|
+
};
|
|
69
|
+
|
|
46
70
|
function inputId(): string {
|
|
47
71
|
const input = (globalThis as { himalaya?: { input?: { id?: unknown } } }).himalaya?.input;
|
|
48
72
|
return typeof input?.id === "string" ? input.id : "";
|
|
@@ -101,15 +125,22 @@ function unavailableProject(state: State, status: "ready" | "error", id: string,
|
|
|
101
125
|
coverImage: "",
|
|
102
126
|
items: [],
|
|
103
127
|
emptyText,
|
|
128
|
+
...NO_DETAILS,
|
|
104
129
|
// A project that is not there is `missing`; one that failed to load is not — the
|
|
105
130
|
// error card speaks, and nothing claims the project was removed.
|
|
106
131
|
...presence(status === "ready" ? "missing" : "failed"),
|
|
107
132
|
});
|
|
108
133
|
}
|
|
109
134
|
|
|
110
|
-
|
|
135
|
+
/** A project page on the web (https only): the share sheet carries nothing else. */
|
|
136
|
+
function shareUrlOf(raw: unknown): string {
|
|
137
|
+
const url = typeof raw === "string" ? raw.trim() : "";
|
|
138
|
+
return /^https:\/\/[^\s]+$/i.test(url) ? url : "";
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const svc = defineService<State, { load: (state: State, arg?: unknown) => Promise<State>; share: (state: State) => Promise<State> }>("himiBrandedPortfolioProject", {
|
|
111
142
|
state: derive({
|
|
112
|
-
status: "loading", id: "", title: "", initial: "", description: "", coverImage: "", items: [], emptyText: "",
|
|
143
|
+
status: "loading", id: "", title: "", initial: "", description: "", coverImage: "", items: [], emptyText: "", ...NO_DETAILS,
|
|
113
144
|
isLoading: true, notLoading: false, isErrored: false, notErrored: true,
|
|
114
145
|
hasCover: false, noCover: true, hasItems: false, noItems: true, hideContent: true, noEmpty: true, ...presence("loading"),
|
|
115
146
|
}),
|
|
@@ -119,7 +150,11 @@ const svc = defineService<State, { load: (state: State, arg?: unknown) => Promis
|
|
|
119
150
|
const id = inputId();
|
|
120
151
|
if (!id) return unavailableProject(state, "ready", "", copyParam("portfolioProject.emptyText", "This project is no longer available."));
|
|
121
152
|
try {
|
|
122
|
-
const projects = await
|
|
153
|
+
const [projects, collections] = await Promise.all([
|
|
154
|
+
listProjects(100),
|
|
155
|
+
// The collection name is extra: a failed read leaves the project without it.
|
|
156
|
+
listCollections(100).then((r) => r.collections ?? []).catch(() => []),
|
|
157
|
+
]);
|
|
123
158
|
const project = (projects.projects ?? []).find((candidate) => candidate.id === id && candidate.hidden !== true);
|
|
124
159
|
if (!project) return unavailableProject(state, "ready", id, copyParam("portfolioProject.emptyText", "This project is no longer available."));
|
|
125
160
|
const response = await listProjectItems(id, 100);
|
|
@@ -127,6 +162,10 @@ const svc = defineService<State, { load: (state: State, arg?: unknown) => Promis
|
|
|
127
162
|
.slice()
|
|
128
163
|
.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
|
|
129
164
|
.map(row);
|
|
165
|
+
const details = projectDetails(project);
|
|
166
|
+
const collection = projectCollection(project, collectionNames(collections)).name;
|
|
167
|
+
// A site with no Portfolio page gives no project url: the site itself is what to share.
|
|
168
|
+
const shareUrl = shareUrlOf(project.url) || shareUrlOf((arg as { siteUrl?: unknown } | undefined)?.siteUrl);
|
|
130
169
|
return derive({
|
|
131
170
|
...state,
|
|
132
171
|
status: "ready",
|
|
@@ -137,12 +176,22 @@ const svc = defineService<State, { load: (state: State, arg?: unknown) => Promis
|
|
|
137
176
|
coverImage: wixMediaUrl(portfolioCoverRef(project.coverImage), WIX_DETAIL_IMAGE),
|
|
138
177
|
items,
|
|
139
178
|
emptyText: items.length ? "" : copyParam("portfolioProject.noMediaText", "This project has no published media yet."),
|
|
179
|
+
collection, noCollection: !collection,
|
|
180
|
+
location: details.location, noLocation: !details.location,
|
|
181
|
+
facts: details.facts, noFacts: details.facts.length === 0,
|
|
182
|
+
details: details.others, noDetails: details.others.length === 0,
|
|
183
|
+
shareUrl, noShare: !shareUrl,
|
|
140
184
|
...presence("found"),
|
|
141
185
|
});
|
|
142
186
|
} catch {
|
|
143
187
|
return unavailableProject(state, "error", id, copyParam("portfolioProject.errorText", "This project could not be loaded. Try again."));
|
|
144
188
|
}
|
|
145
189
|
},
|
|
190
|
+
share: async (state) => {
|
|
191
|
+
if (!state.shareUrl) return state;
|
|
192
|
+
try { await shareSheet({ subject: state.title, text: state.title, url: state.shareUrl }); } catch { /* the sheet is best-effort */ }
|
|
193
|
+
return state;
|
|
194
|
+
},
|
|
146
195
|
},
|
|
147
196
|
});
|
|
148
197
|
svc.load();
|