@wix/himalaya-cli 0.1947.0 → 0.1949.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/sdk/files/src/index.d.ts +23 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/admob-ids.d.ts +4 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/index.d.ts +1 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/social-feed/src/index.d.ts +13 -4
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/video/src/display.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +8 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/files.mjs +4 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +3 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-video.mjs +4 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{da958a2a47eef7082c7892c1cc755a58bbeefcb4b617b47fde87f1ce567b3e64.bin → a8cfd0e17359578587e8937e88dedd40b46d533f08b4d2fdac4c47d5bae6f385.bin} +1 -1
- package/dist/browser-plane/sw.js +9 -9
- package/dist/cli.mjs +1906 -800
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/app-icon.md +7 -3
- package/guides/getting-started.md +6 -1
- package/guides/himi-skill.md +6 -1
- package/guides/himi-test.md +30 -1
- package/guides/one-app-section-mappings.md +1 -1
- package/guides/one-app-to-himi-app.md +23 -16
- package/guides/sdk-reference.json +28 -7
- package/guides/skill.md +1 -1
- package/package.json +2 -2
- package/templates/beauty-salon-owner/config.ts +7 -0
- package/templates/beauty-salon-owner/dev/index.ts +567 -0
- package/templates/beauty-salon-owner/himalaya.content.json +3 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/branded-lite/l10n/ar.json +21 -0
- package/templates/branded-lite/l10n/cs.json +21 -0
- package/templates/branded-lite/l10n/da.json +21 -0
- package/templates/branded-lite/l10n/de.json +21 -0
- package/templates/branded-lite/l10n/el.json +21 -0
- package/templates/branded-lite/l10n/en.json +5 -0
- package/templates/branded-lite/l10n/es.json +21 -0
- package/templates/branded-lite/l10n/fi.json +21 -0
- package/templates/branded-lite/l10n/fr.json +21 -0
- package/templates/branded-lite/l10n/he.json +21 -0
- package/templates/branded-lite/l10n/hu.json +21 -0
- package/templates/branded-lite/l10n/id.json +21 -0
- package/templates/branded-lite/l10n/it.json +21 -0
- package/templates/branded-lite/l10n/ja.json +21 -0
- package/templates/branded-lite/l10n/ko.json +21 -0
- package/templates/branded-lite/l10n/lt.json +21 -0
- package/templates/branded-lite/l10n/nl.json +21 -0
- package/templates/branded-lite/l10n/no.json +21 -0
- package/templates/branded-lite/l10n/pl.json +21 -0
- package/templates/branded-lite/l10n/pt.json +21 -0
- package/templates/branded-lite/l10n/ru.json +21 -0
- package/templates/branded-lite/l10n/sv.json +21 -0
- package/templates/branded-lite/l10n/th.json +21 -0
- package/templates/branded-lite/l10n/tr.json +21 -0
- package/templates/branded-lite/l10n/uk.json +21 -0
- package/templates/branded-lite/l10n/vi.json +21 -0
- package/templates/branded-lite/l10n/zh.json +21 -0
- package/templates/branded-lite/recipes/form-section.json +958 -0
- package/templates/branded-lite/recipes/group-feed.json +221 -3
- package/templates/branded-lite/recipes/groups-newsfeed.json +160 -2
- package/templates/branded-lite/recipes/video-library.json +475 -0
- package/templates/branded-lite/tier5-src/_shared/event-agenda.ts +15 -15
- package/templates/branded-lite/tier5-src/_shared/event-schedule-section.ts +8 -8
- package/templates/branded-lite/tier5-src/_shared/form-section.ts +640 -0
- package/templates/branded-lite/tier5-src/_shared/group-feed-section.ts +119 -7
- package/templates/branded-lite/tier5-src/_shared/groups-newsfeed-section.ts +17 -9
- package/templates/branded-lite/tier5-src/_shared/videos-section.ts +134 -2
- package/templates/branded-lite/tier5-src/himi-branded-lite-form/index.ts +4 -588
- package/templates/branded-lite/tier5-src/himi-branded-lite-video/index.ts +4 -2
- package/templates/branded-lite/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/community-club/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/community-club-owner/config.ts +7 -0
- package/templates/community-club-owner/dev/index.ts +567 -0
- package/templates/community-club-owner/himalaya.content.json +3 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/community-club-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/conference/tier5-src/_shared/event-agenda.ts +15 -15
- package/templates/conference/tier5-src/himi-conference-agenda/index.ts +3 -5
- package/templates/conference/tier5-src/himi-conference-home/index.ts +5 -6
- package/templates/conference/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/events-meetups/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/events-meetups-owner/config.ts +7 -0
- package/templates/events-meetups-owner/dev/index.ts +567 -0
- package/templates/events-meetups-owner/himalaya.content.json +3 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/events-meetups-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/gym-fitness/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/gym-fitness-owner/config.ts +7 -0
- package/templates/gym-fitness-owner/dev/index.ts +567 -0
- package/templates/gym-fitness-owner/himalaya.content.json +3 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/nonprofit-cause/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/nonprofit-cause-owner/config.ts +7 -0
- package/templates/nonprofit-cause-owner/dev/index.ts +567 -0
- package/templates/nonprofit-cause-owner/himalaya.content.json +3 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/owner-lite/config.ts +7 -0
- package/templates/owner-lite/dev/index.ts +567 -0
- package/templates/owner-lite/himalaya.content.json +3 -0
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/owner-lite/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/personal-fitness-trainer/tier5-src/himi-branded-lite-video/index.ts +4 -2
- package/templates/podcast-creator/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/podcast-creator-owner/config.ts +7 -0
- package/templates/podcast-creator-owner/dev/index.ts +567 -0
- package/templates/podcast-creator-owner/himalaya.content.json +3 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/portfolio-creative/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/portfolio-creative-owner/config.ts +7 -0
- package/templates/portfolio-creative-owner/dev/index.ts +567 -0
- package/templates/portfolio-creative-owner/himalaya.content.json +3 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/professional-services/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/restaurant/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/restaurant-owner/config.ts +7 -0
- package/templates/restaurant-owner/dev/index.ts +567 -0
- package/templates/restaurant-owner/himalaya.content.json +3 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/restaurant-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/retail-store-owner/config.ts +7 -0
- package/templates/retail-store-owner/dev/index.ts +567 -0
- package/templates/retail-store-owner/himalaya.content.json +3 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/retail-store-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
- package/templates/yoga-studio/tier5-src/himi-events-detail/index.ts +7 -6
- package/templates/yoga-studio-owner/config.ts +7 -0
- package/templates/yoga-studio-owner/dev/index.ts +567 -0
- package/templates/yoga-studio-owner/himalaya.content.json +3 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-activity.ts +151 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-availability.ts +15 -2
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-chat.ts +20 -7
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-maestro-when.ts +13 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro/index.ts +60 -11
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-activity/index.ts +228 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-maestro-history/index.ts +1 -11
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
// A group that is not public is shown the way the group screen shows it to someone who is not a member: its name, its privacy and the
|
|
5
5
|
// invitation message, and the feed is never read, so no post of a private group reaches the page. A public group whose feed Wix refuses
|
|
6
6
|
// the viewer (401/403: the feed read is a member scope) shows the same state with its own sentence.
|
|
7
|
+
// Each post has the source's Like and Share, as the feed read's permissions allow the viewer: a visitor, or a member the group does not
|
|
8
|
+
// let react, gets no Like, and the section shows a sign-in or join gate instead (`noSignInGate` / `noJoinGate`).
|
|
7
9
|
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe group-feed.json).
|
|
8
10
|
import { defineService } from "@himalaya/state";
|
|
9
11
|
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
12
|
+
import { share as shareSheet } from "@himalaya/share";
|
|
10
13
|
import { memberAccess } from "./member-access.js";
|
|
11
14
|
import { getGroup, type WixGroup } from "@himalaya/wix-groups";
|
|
12
|
-
import { listFeedItems, type WixFeedItem, type WixFeedProfile } from "@himalaya/wix-social-feed";
|
|
15
|
+
import { DEFAULT_REACTION, listFeedItems, reactToFeedItem, unreactFeedItem, type WixFeedItem, type WixFeedItemPermissions, type WixFeedProfile, type WixListFeedItemsResponse } from "@himalaya/wix-social-feed";
|
|
13
16
|
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
14
17
|
import { initials } from "./himi-text.js";
|
|
15
18
|
import { groupPrivacyLabel } from "./group-privacy.js";
|
|
@@ -27,9 +30,27 @@ export interface GroupFeedRow {
|
|
|
27
30
|
id: string; author: string; initials: string;
|
|
28
31
|
avatar: string;
|
|
29
32
|
text: string; timeLabel: string;
|
|
33
|
+
/** The group the post is in: its like is sent there. */
|
|
34
|
+
groupId: string;
|
|
35
|
+
/** The post's reaction total once Wix answered a like with one (`undefined` before: the feed's reaction list is not a total), and
|
|
36
|
+
* the tappable like: what a tap does and the total when known ("👍 Like", "👍 Unlike · 3"). */
|
|
37
|
+
likes?: number; likeLabel: string;
|
|
38
|
+
/** The viewer has liked the post: the next tap removes the like. */
|
|
39
|
+
liked: boolean;
|
|
40
|
+
/** The viewer may not react to the post: the like is hidden. */
|
|
41
|
+
noLike: boolean;
|
|
42
|
+
/** The read named the viewer's permissions and they refuse the like: the post counts toward the sign-in or join gate. */
|
|
43
|
+
gated: boolean;
|
|
44
|
+
/** The viewer may not share the post: the share is hidden. */
|
|
45
|
+
noShare: boolean;
|
|
46
|
+
/** Neither Like nor Share: the post's action row is hidden. */
|
|
47
|
+
noActions: boolean;
|
|
30
48
|
}
|
|
31
49
|
|
|
32
|
-
|
|
50
|
+
/** Which gate shows instead of the posts' Like: none while the viewer may react (or there is no post). */
|
|
51
|
+
export interface FeedGates { noSignInGate: boolean; noJoinGate: boolean }
|
|
52
|
+
|
|
53
|
+
export interface GroupFeedState extends FeedGates {
|
|
33
54
|
status: "loading" | "ready" | "error";
|
|
34
55
|
rows: GroupFeedRow[];
|
|
35
56
|
/** The group's name and privacy label, shown with the restricted state. */
|
|
@@ -38,6 +59,8 @@ export interface GroupFeedState {
|
|
|
38
59
|
restrictedText: string;
|
|
39
60
|
emptyText: string;
|
|
40
61
|
notLoading: boolean; notErrored: boolean; noRows: boolean; noEmpty: boolean; noRestricted: boolean;
|
|
62
|
+
/** The group's shortcuts (About, Members) show once the group was read. */
|
|
63
|
+
noShortcuts: boolean;
|
|
41
64
|
}
|
|
42
65
|
|
|
43
66
|
/** The most posts one section reads. */
|
|
@@ -63,26 +86,108 @@ function authorOf(item: WixFeedItem, profiles: WixFeedProfile[]): { name: string
|
|
|
63
86
|
return { name: profile?.userName || named || copyParam("feed.memberFallbackName", "Member"), avatar: fromProfile || fromCreator || "" };
|
|
64
87
|
}
|
|
65
88
|
|
|
66
|
-
|
|
89
|
+
/** The like's state and label. The words are the blog post's own Like / Unlike keys, so a translated app says them in its language. */
|
|
90
|
+
const likeFields = (liked: boolean, count: number | undefined): Pick<GroupFeedRow, "liked" | "likes" | "likeLabel"> => {
|
|
91
|
+
const verb = liked ? copyParam("blogPost.unlikeCta", "Unlike") : copyParam("blogPost.likeCta", "Like");
|
|
92
|
+
return { liked, likes: count, likeLabel: `\u{1F44D} ${verb}${count === undefined ? "" : ` · ${count}`}` };
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** What the viewer may do to a feed read's posts: anyone's (`all`) and their own (`own`); `undefined` when the read names none. */
|
|
96
|
+
export type FeedPermissions = { all?: WixFeedItemPermissions; own?: WixFeedItemPermissions } | undefined;
|
|
97
|
+
export const feedPermissions = (feed: WixListFeedItemsResponse): FeedPermissions =>
|
|
98
|
+
feed.permissions ? { all: feed.permissions.allFeedItemPermissions, own: feed.permissions.ownFeedItemPermissions } : undefined;
|
|
99
|
+
|
|
100
|
+
/** Whether the viewer's member id is worth reading: only a signed-in viewer who may like some post of the read can have liked one. */
|
|
101
|
+
export const mayLikeAny = (feed: WixListFeedItemsResponse, signedIn: boolean): boolean => {
|
|
102
|
+
const permissions = feedPermissions(feed);
|
|
103
|
+
return signedIn && (permissions?.all?.canReact === true || permissions?.own?.canReact === true || (feed.feedItems ?? []).some((item) => item.permissions?.canReact === true));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** The signed-in member's id, to find their own reaction and posts ("" when not `wanted` — see mayLikeAny — or when it cannot be read).
|
|
107
|
+
* The members SDK is the lean visitor directory, so this is the raw member-safe read the Branded Lite feed worker makes. */
|
|
108
|
+
export async function viewerMemberId(wanted: boolean): Promise<string> {
|
|
109
|
+
if (!wanted) return "";
|
|
110
|
+
const wixApi = (globalThis as { himalaya?: { wixApi?: { call: (method: string, path: string) => Promise<unknown> } } }).himalaya?.wixApi;
|
|
111
|
+
try { return ((await wixApi?.call("GET", "/members/v1/members/my")) as { member?: { id?: string } } | undefined)?.member?.id ?? ""; } catch { return ""; }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A post's row. The feed's permissions apply (its `own` set to the viewer's own post), and the post's own fields override them one by
|
|
115
|
+
* one; with none at all the post grants nothing: no Like, no Share, and no gate. */
|
|
116
|
+
export function postRow(item: WixFeedItem, profiles: WixFeedProfile[], now: number, groupId: string, permissions: FeedPermissions, viewerId = ""): GroupFeedRow {
|
|
67
117
|
const { name, avatar } = authorOf(item, profiles);
|
|
118
|
+
const mine = !!viewerId && item.author?.id === viewerId;
|
|
119
|
+
const feedLevel = mine ? permissions?.own ?? permissions?.all : permissions?.all;
|
|
120
|
+
const named = feedLevel || item.permissions ? { ...feedLevel, ...item.permissions } : undefined;
|
|
121
|
+
const granted: WixFeedItemPermissions = named ?? {};
|
|
122
|
+
const noLike = granted.canReact !== true, noShare = granted.canShare !== true;
|
|
123
|
+
// The section's Like is the 👍 reaction: another reaction the member left is not this like.
|
|
124
|
+
const liked = !!viewerId && (item.reactionsList ?? []).some((reaction) => reaction.userId === viewerId && reaction.reaction === DEFAULT_REACTION);
|
|
68
125
|
return {
|
|
69
126
|
id: item.feedItemId || "", author: name, initials: initials(name),
|
|
70
127
|
avatar,
|
|
71
128
|
text: postText(item), timeLabel: relativeTime(item.created ?? item.createdAt, now),
|
|
129
|
+
groupId, ...likeFields(liked, undefined),
|
|
130
|
+
noLike, noShare, noActions: noLike && noShare, gated: named !== undefined && granted.canReact !== true,
|
|
72
131
|
};
|
|
73
132
|
}
|
|
74
133
|
|
|
134
|
+
/** The gate that replaces the Like when no post may be liked: sign in for a visitor, join the group for a member. Only posts whose read
|
|
135
|
+
* named the viewer's permissions count (`gated`): a read without them shows no gate, so a member is never asked to join. */
|
|
136
|
+
export const feedGates = (rows: GroupFeedRow[], signedIn: boolean): FeedGates => {
|
|
137
|
+
const gated = rows.length > 0 && rows.every((row) => row.gated);
|
|
138
|
+
return { noSignInGate: !(gated && !signedIn), noJoinGate: !(gated && signedIn) };
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The sections' `like` action: the first tap likes the post, the next one removes that like, as the source's Like toggles. A tap while
|
|
143
|
+
* the post's last one is still out is ignored. An answer that arrives after the section loaded again (`generation` moved: a refresh, or
|
|
144
|
+
* another viewer signed in) is dropped, so it never marks the next viewer's post. A failed call leaves the post as it was.
|
|
145
|
+
*/
|
|
146
|
+
export function likeAction<R extends GroupFeedRow, S extends { rows: R[] }>(current: () => S, generation: () => number) {
|
|
147
|
+
const pending = new Set<string>();
|
|
148
|
+
return async (state: S, arg: unknown): Promise<S | undefined> => {
|
|
149
|
+
const row = state.rows.find((candidate) => candidate.id === idOf(arg));
|
|
150
|
+
const key = row ? `${row.groupId}/${row.id}` : "";
|
|
151
|
+
if (!row || row.noLike || pending.has(key)) return undefined;
|
|
152
|
+
pending.add(key);
|
|
153
|
+
const started = generation();
|
|
154
|
+
try {
|
|
155
|
+
const summary = row.liked ? await unreactFeedItem(row.id, row.groupId) : await reactToFeedItem(row.id, row.groupId);
|
|
156
|
+
if (generation() !== started) return undefined;
|
|
157
|
+
// Wix's total is authoritative; without one, a count already known moves by one and an unknown one stays unknown.
|
|
158
|
+
const count = typeof summary.total === "number" ? summary.total : row.likes === undefined ? undefined : Math.max(0, row.likes + (row.liked ? -1 : 1));
|
|
159
|
+
const now = current();
|
|
160
|
+
return { ...now, rows: now.rows.map((candidate) => candidate.id === row.id && candidate.groupId === row.groupId ? { ...candidate, ...likeFields(!row.liked, count) } : candidate) };
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.warn("group feed: the like could not be sent", error);
|
|
163
|
+
return undefined;
|
|
164
|
+
} finally {
|
|
165
|
+
pending.delete(key);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Share one post through the OS share sheet: its author and text, under the group's name. */
|
|
171
|
+
export async function sharePost<R extends GroupFeedRow>(rows: R[], arg: unknown, groupName: (row: R) => string): Promise<void> {
|
|
172
|
+
const row = rows.find((candidate) => candidate.id === idOf(arg));
|
|
173
|
+
if (!row || row.noShare) return;
|
|
174
|
+
try { await shareSheet({ subject: groupName(row), text: `${row.author}: ${row.text}` }); } catch { /* the sheet is best-effort */ }
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const idOf = (arg: unknown): string => typeof arg === "string" ? arg : String((arg as { id?: unknown } | undefined)?.id ?? "");
|
|
178
|
+
|
|
75
179
|
/** The feed read is a member scope: Wix answers a viewer it will not show with `HTTP 401` / `HTTP 403`. */
|
|
76
180
|
export const isRefusal = (error: unknown): boolean => /\b(401|403)\b/.test(String((error as Error | undefined)?.message ?? error));
|
|
77
181
|
|
|
78
182
|
export function registerGroupFeedSection(serviceName: string, options: GroupFeedOptions) {
|
|
79
|
-
const view = (status: GroupFeedState["status"], parts: { rows?: GroupFeedRow[]; groupName?: string; privacy?: string; restrictedText?: string } = {}): GroupFeedState => {
|
|
183
|
+
const view = (status: GroupFeedState["status"], parts: { rows?: GroupFeedRow[]; groupName?: string; privacy?: string; restrictedText?: string; signedIn?: boolean } = {}): GroupFeedState => {
|
|
80
184
|
const rows = parts.rows ?? [], restrictedText = parts.restrictedText ?? "";
|
|
81
185
|
return {
|
|
82
186
|
status, rows, groupName: parts.groupName ?? "", privacy: parts.privacy ?? "", restrictedText,
|
|
83
187
|
emptyText: status === "ready" && !rows.length && !restrictedText ? copyParam("groupFeed.emptyText", "No posts in this group yet.") : "",
|
|
84
188
|
notLoading: status !== "loading", notErrored: status !== "error",
|
|
85
189
|
noRows: !rows.length, noEmpty: !(status === "ready" && !rows.length && !restrictedText), noRestricted: !restrictedText,
|
|
190
|
+
...feedGates(rows, parts.signedIn === true), noShortcuts: status !== "ready",
|
|
86
191
|
};
|
|
87
192
|
};
|
|
88
193
|
const session = hostSessionFromGlobal();
|
|
@@ -90,7 +195,10 @@ export function registerGroupFeedSection(serviceName: string, options: GroupFeed
|
|
|
90
195
|
const restart = () => { void service.clear(); void service.load(); };
|
|
91
196
|
// Only the newest load may answer, and only for the viewer who started it: a feed read for one member is never shown to the next.
|
|
92
197
|
let sequence = 0;
|
|
93
|
-
const service = defineService<GroupFeedState, {
|
|
198
|
+
const service = defineService<GroupFeedState, {
|
|
199
|
+
load: (state: GroupFeedState, arg?: unknown) => Promise<GroupFeedState | undefined>; clear: () => Promise<GroupFeedState>;
|
|
200
|
+
like: (state: GroupFeedState, arg?: unknown) => Promise<GroupFeedState | undefined>; share: (state: GroupFeedState, arg?: unknown) => Promise<GroupFeedState | undefined>;
|
|
201
|
+
}>(serviceName, {
|
|
94
202
|
state: view("loading"),
|
|
95
203
|
// A group's posts are member-scoped: never written to disk and restored for the next person on the device.
|
|
96
204
|
notHydrated: Object.keys(view("loading")) as Array<keyof GroupFeedState>,
|
|
@@ -114,10 +222,12 @@ export function registerGroupFeedSection(serviceName: string, options: GroupFeed
|
|
|
114
222
|
}
|
|
115
223
|
try {
|
|
116
224
|
const feed = await listFeedItems(options.groupId, Math.min(options.limit ?? MAX_POSTS, MAX_POSTS));
|
|
225
|
+
const viewerId = await viewerMemberId(mayLikeAny(feed, viewer.signedIn === true));
|
|
117
226
|
if (!(await sameViewer())) { if (seq === sequence) restart(); return undefined; }
|
|
118
227
|
const profiles = feed.profiles ?? [], now = Date.now();
|
|
119
|
-
const
|
|
120
|
-
|
|
228
|
+
const permissions = feedPermissions(feed);
|
|
229
|
+
const rows = (feed.feedItems ?? []).filter((item) => item.feedItemId).map((item) => postRow(item, profiles, now, options.groupId, permissions, viewerId));
|
|
230
|
+
return view("ready", { rows, groupName, privacy, signedIn: viewer.signedIn === true });
|
|
121
231
|
} catch (error) {
|
|
122
232
|
if (!(await sameViewer())) { if (seq === sequence) restart(); return undefined; }
|
|
123
233
|
if (!isRefusal(error)) throw error;
|
|
@@ -129,6 +239,8 @@ export function registerGroupFeedSection(serviceName: string, options: GroupFeed
|
|
|
129
239
|
return view("error");
|
|
130
240
|
}
|
|
131
241
|
},
|
|
242
|
+
like: likeAction((): GroupFeedState => service.getState(), () => sequence),
|
|
243
|
+
share: async (state, arg) => { await sharePost(state.rows, arg, () => state.groupName); return undefined; },
|
|
132
244
|
},
|
|
133
245
|
});
|
|
134
246
|
// Signing in or out on another screen changes who the feed is read for.
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// It is the single-group feed (group-feed-section.ts) read for several groups and merged: the same post rows, and the same rule that a group
|
|
5
5
|
// which is not public is never read, so no post of a private group reaches the page. A public group whose feed Wix refuses the viewer
|
|
6
6
|
// (401/403: the feed read is a member scope) adds nothing; when every group refuses, the section says posts are for members.
|
|
7
|
+
// A post has the Like and Share its own group's feed allows the viewer; when no post may be liked, a sign-in or join gate shows instead.
|
|
7
8
|
// A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*` (recipe groups-newsfeed.json).
|
|
8
9
|
import { defineService } from "@himalaya/state";
|
|
9
10
|
import { hostSessionFromGlobal } from "@himalaya/iap";
|
|
@@ -11,7 +12,7 @@ import { memberAccess } from "./member-access.js";
|
|
|
11
12
|
import { queryGroups, type WixGroup } from "@himalaya/wix-groups";
|
|
12
13
|
import { listFeedItems } from "@himalaya/wix-social-feed";
|
|
13
14
|
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
14
|
-
import { isRefusal, postRow, type GroupFeedRow } from "./group-feed-section.js";
|
|
15
|
+
import { feedGates, feedPermissions, isRefusal, likeAction, mayLikeAny, postRow, viewerMemberId, sharePost, type FeedGates, type GroupFeedRow } from "./group-feed-section.js";
|
|
15
16
|
|
|
16
17
|
export interface GroupsNewsfeedOptions {
|
|
17
18
|
/** Show only these groups' posts. */
|
|
@@ -21,11 +22,11 @@ export interface GroupsNewsfeedOptions {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export interface NewsfeedRow extends GroupFeedRow {
|
|
24
|
-
/** The group the post is in: the row names it and opens it. */
|
|
25
|
-
|
|
25
|
+
/** The name of the group the post is in (`groupId`): the row names it and opens it. */
|
|
26
|
+
groupName: string;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export interface GroupsNewsfeedState {
|
|
29
|
+
export interface GroupsNewsfeedState extends FeedGates {
|
|
29
30
|
status: "loading" | "ready" | "error";
|
|
30
31
|
rows: NewsfeedRow[];
|
|
31
32
|
/** Why the posts are not shown ("" when they are): every group's feed refused the viewer. */
|
|
@@ -44,12 +45,13 @@ const GROUP_PAGE = 100;
|
|
|
44
45
|
const isPublic = (group: WixGroup): boolean => { const kind = (group.privacyStatus || "UNKNOWN").toLowerCase(); return kind === "public" || kind === "unknown"; };
|
|
45
46
|
|
|
46
47
|
export function registerGroupsNewsfeedSection(serviceName: string, options: GroupsNewsfeedOptions = {}) {
|
|
47
|
-
const view = (status: GroupsNewsfeedState["status"], parts: { rows?: NewsfeedRow[]; restrictedText?: string } = {}): GroupsNewsfeedState => {
|
|
48
|
+
const view = (status: GroupsNewsfeedState["status"], parts: { rows?: NewsfeedRow[]; restrictedText?: string; signedIn?: boolean } = {}): GroupsNewsfeedState => {
|
|
48
49
|
const rows = parts.rows ?? [], restrictedText = parts.restrictedText ?? "";
|
|
49
50
|
const empty = status === "ready" && !rows.length && !restrictedText;
|
|
50
51
|
return {
|
|
51
52
|
status, rows, restrictedText, emptyText: empty ? copyParam("feed.emptyText", "Nothing has been posted yet — start the conversation.") : "",
|
|
52
53
|
notLoading: status !== "loading", notErrored: status !== "error", noRows: !rows.length, noEmpty: !empty, noRestricted: !restrictedText,
|
|
54
|
+
...feedGates(rows, parts.signedIn === true),
|
|
53
55
|
};
|
|
54
56
|
};
|
|
55
57
|
const session = hostSessionFromGlobal();
|
|
@@ -57,7 +59,10 @@ export function registerGroupsNewsfeedSection(serviceName: string, options: Grou
|
|
|
57
59
|
const restart = () => { void service.clear(); void service.load(); };
|
|
58
60
|
// Only the newest load may answer, and only for the viewer who started it: a feed read for one member is never shown to the next.
|
|
59
61
|
let sequence = 0;
|
|
60
|
-
const service = defineService<GroupsNewsfeedState, {
|
|
62
|
+
const service = defineService<GroupsNewsfeedState, {
|
|
63
|
+
load: (state: GroupsNewsfeedState, arg?: unknown) => Promise<GroupsNewsfeedState | undefined>; clear: () => Promise<GroupsNewsfeedState>;
|
|
64
|
+
like: (state: GroupsNewsfeedState, arg?: unknown) => Promise<GroupsNewsfeedState | undefined>; share: (state: GroupsNewsfeedState, arg?: unknown) => Promise<GroupsNewsfeedState | undefined>;
|
|
65
|
+
}>(serviceName, {
|
|
61
66
|
state: view("loading"),
|
|
62
67
|
// The posts are member-scoped: never written to disk and restored for the next person on the device.
|
|
63
68
|
notHydrated: Object.keys(view("loading")) as Array<keyof GroupsNewsfeedState>,
|
|
@@ -75,28 +80,31 @@ export function registerGroupsNewsfeedSection(serviceName: string, options: Grou
|
|
|
75
80
|
const groups = chosen.filter(isPublic).slice(0, NEWSFEED_GROUPS_MAX);
|
|
76
81
|
const limit = Math.min(options.limit ?? MAX_POSTS, MAX_POSTS);
|
|
77
82
|
const reads = await Promise.allSettled(groups.map((group) => listFeedItems(group.id, limit)));
|
|
83
|
+
const viewerId = await viewerMemberId(reads.some((read) => read.status === "fulfilled" && mayLikeAny(read.value, viewer.signedIn === true)));
|
|
78
84
|
if (!(await sameViewer())) { if (seq === sequence) restart(); return undefined; }
|
|
79
85
|
const now = Date.now(), posts: Array<{ row: NewsfeedRow; at: number }> = [];
|
|
80
86
|
let refused = 0, failed: unknown;
|
|
81
87
|
reads.forEach((read, i) => {
|
|
82
88
|
const group = groups[i]!, groupName = (group.name || copyParam("groups.groupFallbackName", "Group")).trim();
|
|
83
89
|
if (read.status === "rejected") { if (isRefusal(read.reason)) refused++; else failed = read.reason; return; }
|
|
84
|
-
const profiles = read.value.profiles ?? [];
|
|
90
|
+
const profiles = read.value.profiles ?? [], permissions = feedPermissions(read.value);
|
|
85
91
|
for (const item of read.value.feedItems ?? []) {
|
|
86
|
-
if (item.feedItemId) posts.push({ row: { ...postRow(item, profiles, now
|
|
92
|
+
if (item.feedItemId) posts.push({ row: { ...postRow(item, profiles, now, group.id, permissions, viewerId), groupName }, at: Date.parse(String(item.created ?? item.createdAt ?? "")) || 0 });
|
|
87
93
|
}
|
|
88
94
|
});
|
|
89
95
|
// A group whose feed failed for another reason hides the posts of the rest only when nothing else answered: one broken group does not blank the feed.
|
|
90
96
|
if (failed !== undefined && !posts.length) throw failed;
|
|
91
97
|
const rows = posts.sort((a, b) => b.at - a.at).slice(0, limit).map((post) => post.row);
|
|
92
98
|
const allRefused = !rows.length && groups.length > 0 && refused === groups.length;
|
|
93
|
-
return view("ready", { rows, restrictedText: allRefused ? copyParam("groupFeed.restrictedText", "Posts are shown to the group's members.") : "" });
|
|
99
|
+
return view("ready", { rows, restrictedText: allRefused ? copyParam("groupFeed.restrictedText", "Posts are shown to the group's members.") : "", signedIn: viewer.signedIn === true });
|
|
94
100
|
} catch (error) {
|
|
95
101
|
if (seq !== sequence) return undefined;
|
|
96
102
|
console.warn("groups_newsfeed_section: the groups' posts could not be read", error);
|
|
97
103
|
return view("error");
|
|
98
104
|
}
|
|
99
105
|
},
|
|
106
|
+
like: likeAction((): GroupsNewsfeedState => service.getState(), () => sequence),
|
|
107
|
+
share: async (state, arg) => { await sharePost(state.rows, arg, (row) => row.groupName); return undefined; },
|
|
100
108
|
},
|
|
101
109
|
});
|
|
102
110
|
// Signing in or out on another screen changes who the feed is read for.
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
// Reads the same Wix Video gateway as the `himi_videos` screen's worker (`@himalaya/wix-video`), with the same ready-to-play rule: a
|
|
9
9
|
// video still processing, or unpublished, is not shown. A page worker registers it under a service name; the descriptor binds
|
|
10
10
|
// `$service:<serviceName>.*` (recipe videos-carousel).
|
|
11
|
+
//
|
|
12
|
+
// `registerVideoLibrarySection` is the One App's channel list (`vod_list_section`) inline: each channel as its header (cover, title,
|
|
13
|
+
// "1 video · Free"), Play All and its first clips as rows (recipe video-library). A clip and Play All open the template's video screen,
|
|
14
|
+
// which picks the player for the video's provider; Play All starts on the channel's first clip that player can play.
|
|
11
15
|
import { defineService } from "@himalaya/state";
|
|
12
|
-
import { latestVideos, listChannels, videoCard, type WixVideoChannel } from "@himalaya/wix-video";
|
|
13
|
-
import { copyParam, stashCopy } from "./himi-copy.js";
|
|
16
|
+
import { channelCoverUrl, isPlayableVideo, isVideoReady, latestVideos, listChannels, videoCard, type WixVideoChannel } from "@himalaya/wix-video";
|
|
17
|
+
import { copyParam, copyPlural, copyTemplate, stashCopy } from "./himi-copy.js";
|
|
14
18
|
|
|
15
19
|
export interface VideosSectionOptions {
|
|
16
20
|
/** The source channel's id; unset reads every channel. */
|
|
@@ -89,3 +93,131 @@ export function registerVideosSection(serviceName: string, options: VideosSectio
|
|
|
89
93
|
},
|
|
90
94
|
});
|
|
91
95
|
}
|
|
96
|
+
|
|
97
|
+
export interface VideoLibraryOptions {
|
|
98
|
+
/** A channel the source names; unset (the One App's list has no setting for it) lists every channel. */
|
|
99
|
+
channelId?: string;
|
|
100
|
+
/** How many channels to show; the rest are one See All away. */
|
|
101
|
+
channels?: number;
|
|
102
|
+
/** How many clips each channel shows; the rest are on the channel's own screen. */
|
|
103
|
+
videosPerChannel?: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface LibraryVideoRow {
|
|
107
|
+
id: string; channelId: string; title: string; duration: string;
|
|
108
|
+
/** The video's host when it is not Wix ("YouTube", "Vimeo"), as the One App's row names it. */
|
|
109
|
+
provider: string;
|
|
110
|
+
coverUrl: string; hasCover: boolean; noCover: boolean; noDuration: boolean; noProvider: boolean;
|
|
111
|
+
accessibilityLabel: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface LibraryChannel {
|
|
115
|
+
id: string; title: string;
|
|
116
|
+
/** "1 video · Free": the channel's size, and Free when nothing in it is sold. */
|
|
117
|
+
summary: string;
|
|
118
|
+
coverUrl: string; hasCover: boolean; noCover: boolean;
|
|
119
|
+
videos: LibraryVideoRow[];
|
|
120
|
+
/** Play All opens this clip (the first one the video screen can play) with its channel and title. */
|
|
121
|
+
playId: string; playChannelId: string; playTitle: string;
|
|
122
|
+
noPlayAll: boolean;
|
|
123
|
+
/** false when the channel has more videos than its rows show. */
|
|
124
|
+
noMore: boolean;
|
|
125
|
+
/** Spoken labels naming the channel: every channel has its own Play All and See All. */
|
|
126
|
+
playAllLabel: string; seeAllLabel: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface VideoLibraryState {
|
|
130
|
+
status: "loading" | "ready" | "error";
|
|
131
|
+
channels: LibraryChannel[];
|
|
132
|
+
notLoading: boolean; notErrored: boolean; noRows: boolean;
|
|
133
|
+
/** false only when the read answered and there is no channel with a ready video: the section says there is nothing yet. */
|
|
134
|
+
noEmpty: boolean;
|
|
135
|
+
/** false when the site has more channels than the section shows. */
|
|
136
|
+
noMoreChannels: boolean;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const LIBRARY_CHANNELS = 3;
|
|
140
|
+
const LIBRARY_VIDEOS = 5;
|
|
141
|
+
/** A 112pt row thumbnail at 3x, 16:9. */
|
|
142
|
+
const ROW_IMAGE = { width: 336, height: 189, quality: 85 };
|
|
143
|
+
/** A full-width channel cover at 3x. */
|
|
144
|
+
const CHANNEL_IMAGE = { width: 1080, height: 480, quality: 85 };
|
|
145
|
+
const PROVIDERS: Readonly<Record<string, string>> = { YOUTUBE: "YouTube", VIMEO: "Vimeo", FACEBOOK: "Facebook" };
|
|
146
|
+
|
|
147
|
+
function isFree(channel: WixVideoChannel): boolean {
|
|
148
|
+
return Array.isArray(channel.pricing) && !channel.pricing.some((p) => p.enabled) && channel.hasPaidVideos !== true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** `read` is how many clips the preview asked for. */
|
|
152
|
+
function libraryChannel(channel: WixVideoChannel, limit: number, read: number, untitled: string): LibraryChannel | undefined {
|
|
153
|
+
const preview = channel.videos?.entities ?? [];
|
|
154
|
+
const ready = preview.filter((video) => video?.id && isVideoReady(video));
|
|
155
|
+
// Nothing ready in a preview that holds every clip (it came back short of what it asked for, or it already covers the channel's
|
|
156
|
+
// total): nothing to play or list, as in the source. A full preview cut short of the total with nothing ready (the newest clips
|
|
157
|
+
// still processing) keeps the header and See All: older clips may be ready.
|
|
158
|
+
const complete = preview.length < read || (channel.videos?.total ?? preview.length) <= preview.length;
|
|
159
|
+
if (!ready.length && complete) return undefined;
|
|
160
|
+
const videos = ready.slice(0, limit).map((video): LibraryVideoRow => {
|
|
161
|
+
const card = videoCard({ channel, video }, untitled, ROW_IMAGE);
|
|
162
|
+
const provider = PROVIDERS[video.source ?? ""] ?? "";
|
|
163
|
+
return {
|
|
164
|
+
id: card.id, channelId: channel.id, title: card.title, duration: card.duration, provider,
|
|
165
|
+
coverUrl: card.coverUrl, hasCover: card.hasCover, noCover: card.noCover, noDuration: !card.duration, noProvider: !provider,
|
|
166
|
+
accessibilityLabel: [card.title, card.duration, provider].filter(Boolean).join(", "),
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
// Play All looks only at the clips this one read returned (the rows and one more). A channel whose clips there are all hosted
|
|
170
|
+
// where no Himi player plays them (Vimeo, Facebook) shows no Play All: its rows and See All still open every clip.
|
|
171
|
+
const first = ready.find(isPlayableVideo);
|
|
172
|
+
const total = channel.videos?.total ?? ready.length;
|
|
173
|
+
const count = copyPlural("videos.channelVideoCount", "{n, plural, one {# video} other {# videos}}", total);
|
|
174
|
+
const coverUrl = channelCoverUrl(channel, CHANNEL_IMAGE);
|
|
175
|
+
const title = channel.title?.trim() ?? "";
|
|
176
|
+
return {
|
|
177
|
+
id: channel.id, title,
|
|
178
|
+
summary: isFree(channel) ? `${count} · ${copyParam("videos.free", "Free")}` : count,
|
|
179
|
+
coverUrl, hasCover: !!coverUrl, noCover: !coverUrl,
|
|
180
|
+
videos,
|
|
181
|
+
playId: first?.id ?? "", playChannelId: first ? channel.id : "", playTitle: first ? videoCard({ channel, video: first }, untitled).title : "",
|
|
182
|
+
noPlayAll: !first,
|
|
183
|
+
noMore: total <= videos.length,
|
|
184
|
+
playAllLabel: copyTemplate("videos.playAllLabel", "Play all, {channel}", { channel: title }),
|
|
185
|
+
seeAllLabel: copyTemplate("videos.seeAllLabel", "See all, {channel}", { channel: title }),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function registerVideoLibrarySection(serviceName: string, options: VideoLibraryOptions = {}) {
|
|
190
|
+
const channelLimit = options.channels ?? LIBRARY_CHANNELS;
|
|
191
|
+
const videoLimit = options.videosPerChannel ?? LIBRARY_VIDEOS;
|
|
192
|
+
const view = (status: VideoLibraryState["status"], channels: LibraryChannel[], moreChannels: boolean): VideoLibraryState => ({
|
|
193
|
+
status, channels,
|
|
194
|
+
notLoading: status !== "loading", notErrored: status !== "error", noRows: !channels.length,
|
|
195
|
+
noEmpty: !(status === "ready" && !channels.length),
|
|
196
|
+
noMoreChannels: !moreChannels,
|
|
197
|
+
});
|
|
198
|
+
// A Retry that overtakes a slow first read: only the latest read publishes.
|
|
199
|
+
let generation = 0;
|
|
200
|
+
return defineService<VideoLibraryState, { load: (state: VideoLibraryState, arg?: unknown) => Promise<VideoLibraryState | undefined> }>(serviceName, {
|
|
201
|
+
state: view("loading", [], false),
|
|
202
|
+
actions: {
|
|
203
|
+
load: async (_state, arg) => {
|
|
204
|
+
stashCopy(arg);
|
|
205
|
+
const request = ++generation;
|
|
206
|
+
// One read: every channel with its first clips (one more than shown, so Play All can pass a clip the video screen cannot play).
|
|
207
|
+
const read = videoLimit + 1;
|
|
208
|
+
try {
|
|
209
|
+
const all = await listChannels({ videosPerChannel: read });
|
|
210
|
+
if (request !== generation) return undefined;
|
|
211
|
+
const chosen = options.channelId ? all.filter((channel) => channel.id === options.channelId) : all;
|
|
212
|
+
const untitled = copyParam("videos.untitledVideo", "Video");
|
|
213
|
+
const shown = chosen.flatMap((channel) => libraryChannel(channel, videoLimit, read, untitled) ?? []);
|
|
214
|
+
return view("ready", shown.slice(0, channelLimit), shown.length > channelLimit);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (request !== generation) return undefined;
|
|
217
|
+
console.warn("video_library: the channels could not be read", error);
|
|
218
|
+
return view("error", [], false);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|