@wix/himalaya-cli 0.1645.0 → 0.1647.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/blog-v3/src/extensions.d.ts +21 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/members-v1/src/index.d.ts +5 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-blog.mjs +8 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-members.mjs +5 -0
- package/dist/cli.mjs +1396 -994
- package/guides/himi-test.md +1 -1
- package/guides/one-app-to-himi-app.md +26 -12
- package/guides/sdk-reference.json +33 -1
- package/package.json +2 -2
- package/templates/beauty-salon/config.ts +1 -1
- package/templates/beauty-salon/dev/index.ts +2773 -2969
- package/templates/beauty-salon/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/beauty-salon/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/beauty-salon/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/beauty-salon/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/beauty-salon/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/beauty-salon/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/branded-lite/config.ts +1 -1
- package/templates/branded-lite/dev/index.ts +2741 -2937
- package/templates/branded-lite/l10n/en.json +12 -12
- package/templates/branded-lite/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/branded-lite/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/branded-lite/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/branded-lite/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/branded-lite/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/branded-lite/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/community-club/config.ts +1 -1
- package/templates/community-club/dev/index.ts +2799 -2995
- package/templates/community-club/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/community-club/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/community-club/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/community-club/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/community-club/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/community-club/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/community-club-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/conference/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/events-meetups/config.ts +1 -1
- package/templates/events-meetups/dev/index.ts +2859 -3055
- package/templates/events-meetups/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/events-meetups/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/events-meetups/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/events-meetups/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/events-meetups/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/events-meetups/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/events-meetups-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/gym-fitness/config.ts +1 -1
- package/templates/gym-fitness/dev/index.ts +2733 -2929
- package/templates/gym-fitness/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/gym-fitness/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/gym-fitness/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/gym-fitness/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/gym-fitness/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/gym-fitness/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/nonprofit-cause/config.ts +1 -1
- package/templates/nonprofit-cause/dev/index.ts +2813 -3009
- package/templates/nonprofit-cause/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/nonprofit-cause/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/nonprofit-cause/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/nonprofit-cause/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/owner-lite/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/podcast-creator/config.ts +1 -1
- package/templates/podcast-creator/dev/index.ts +2862 -3058
- package/templates/podcast-creator/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/podcast-creator/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/podcast-creator/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/podcast-creator/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/podcast-creator/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/podcast-creator/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/portfolio-creative/config.ts +1 -1
- package/templates/portfolio-creative/dev/index.ts +2803 -2999
- package/templates/portfolio-creative/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/portfolio-creative/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/portfolio-creative/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/portfolio-creative/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/portfolio-creative/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/portfolio-creative/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/restaurant/config.ts +1 -1
- package/templates/restaurant/dev/index.ts +2845 -3041
- package/templates/restaurant/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/restaurant/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/restaurant/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/restaurant/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/restaurant/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/restaurant/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/restaurant-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/retail-store/config.ts +1 -1
- package/templates/retail-store/dev/index.ts +2809 -3005
- package/templates/retail-store/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/retail-store/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/retail-store/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/retail-store/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/retail-store/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/retail-store/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/retail-store-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/salon-spa/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/yoga-studio/config.ts +1 -1
- package/templates/yoga-studio/dev/index.ts +2752 -2948
- package/templates/yoga-studio/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/yoga-studio/tier5-src/_shared/himi-blog-post-row.ts +210 -0
- package/templates/yoga-studio/tier5-src/_shared/himi-blog-saved.ts +0 -10
- package/templates/yoga-studio/tier5-src/himi-blog-feed/index.ts +220 -95
- package/templates/yoga-studio/tier5-src/himi-blog-post/index.ts +436 -140
- package/templates/yoga-studio/tier5-src/himi-blog-saved/index.ts +97 -39
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-contract.ts +0 -1
- package/templates/beauty-salon/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/branded-lite/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/community-club/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/events-meetups/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/gym-fitness/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/podcast-creator/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/portfolio-creative/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/restaurant/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/retail-store/tier5-src/_shared/himi-blog-collection.ts +0 -7
- package/templates/yoga-studio/tier5-src/_shared/himi-blog-collection.ts +0 -7
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
// Tier-5 bundle: Himi Blog post detail - reader content plus member actions.
|
|
2
|
-
import { defineService } from "@himalaya/state";
|
|
2
|
+
import { defineService, navigate } from "@himalaya/state";
|
|
3
|
+
import { snackbar } from "@himalaya/ui";
|
|
3
4
|
import { share as shareSheet } from "@himalaya/share";
|
|
4
|
-
import { getPost, likePost, unlikePost, type WixPost, type WixPostWithContent } from "@himalaya/wix-blog";
|
|
5
|
+
import { getPost, likePost, unlikePost, queryPosts, queryCategories, queryTags, type WixPost, type WixPostWithContent, type WixQueryPostsRequest } from "@himalaya/wix-blog";
|
|
5
6
|
import { comments, BLOG_COMMENTS_APP_ID, blogCommentRow, listBlogComments, type WixBlogCommentRow } from "@himalaya/wix-comments";
|
|
6
7
|
import { get, type DbEntity } from "@himalaya/local-db";
|
|
7
8
|
import { isSavedId, toggleSavedId } from "../_shared/himi-blog-saved";
|
|
8
9
|
import { hideId, isHiddenId, unhideId } from "../_shared/himi-blog-hidden";
|
|
9
|
-
import { stashCopy, copyParam,
|
|
10
|
+
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
10
11
|
import { formatDateMedium, formatMonthDay } from "../_shared/engine-intl.js";
|
|
11
12
|
import { openRichLink } from "../_shared/rich-content-link.js";
|
|
12
13
|
import { richBody, ROW_IMAGE_WIDTH } from "../_shared/rich-body.js";
|
|
13
|
-
import { readAccess, assertReadAccess, readAccessDenied, readSignInFlags, NO_READ_SIGN_IN } from "../_shared/member-read.js";
|
|
14
|
+
import { readAccess, assertReadAccess, readAccessDenied, readSignInFlags, NO_READ_SIGN_IN, type ReadAccess } from "../_shared/member-read.js";
|
|
15
|
+
import { authorFields, BLOG_HERO_IMAGE, BLOG_THUMB_IMAGE, commentsLabelFor, type BlogAuthor, countsOf, coverOf, dateLineOf, dateOf, legacyRowFixes, LIST_FIELDSETS, cachedCover, NO_AUTHOR, likesLabelFor, resolveAuthors, viewsLabelFor, type AuthorFields, type BlogPostShape } from "../_shared/himi-blog-post-row.js";
|
|
14
16
|
|
|
15
17
|
// Offline-first (data-offline): the post body is a public read-through — when the
|
|
16
18
|
// live fetch fails (offline) fall back to the last-synced row the feed cached under
|
|
@@ -22,9 +24,14 @@ async function readCachedPost(id: string): Promise<DbEntity | null> {
|
|
|
22
24
|
try { return await get(ENTITY, id); } catch { /* capability not granted → online-only */ return null; }
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
/** How many "Recent posts" rows the end of the post shows. */
|
|
28
|
+
const RECENT_COUNT = 3;
|
|
29
|
+
|
|
25
30
|
interface CommentRow {
|
|
26
31
|
id: string;
|
|
27
32
|
authorName: string;
|
|
33
|
+
/** The author's first letter, for the round initial beside the name. */
|
|
34
|
+
authorInitial: string;
|
|
28
35
|
/** The comment's plain text: the row RichContent's fallback. */
|
|
29
36
|
text: string;
|
|
30
37
|
meta: string;
|
|
@@ -35,19 +42,50 @@ interface CommentRow {
|
|
|
35
42
|
hasBodyJson: boolean;
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
interface
|
|
45
|
+
interface TagRow { id: string; label: string }
|
|
46
|
+
|
|
47
|
+
/** One "Recent posts" row: the photo (or none), the title and the date. */
|
|
48
|
+
interface RecentRow {
|
|
49
|
+
id: string;
|
|
50
|
+
title: string;
|
|
51
|
+
date: string;
|
|
52
|
+
cover: string;
|
|
53
|
+
hasCover: boolean;
|
|
54
|
+
noCover: boolean;
|
|
55
|
+
detailScreenId: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface S extends AuthorFields {
|
|
39
59
|
signInRequired: boolean; noSignIn: boolean; signInScreenId: string;
|
|
40
60
|
status: "loading" | "ready" | "error";
|
|
41
61
|
id: string;
|
|
42
62
|
commentResourceId: string;
|
|
43
63
|
title: string;
|
|
64
|
+
/** "Jul 30, 2026 · 4 min read". */
|
|
44
65
|
subtitle: string;
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
/** "Updated Aug 2, 2026" when the post changed on a later day than it was published; "" otherwise. */
|
|
67
|
+
updatedLine: string;
|
|
68
|
+
/** The post's first category's name ("" when it has none). */
|
|
69
|
+
categoryLabel: string;
|
|
70
|
+
hasCategory: boolean;
|
|
71
|
+
noCategory: boolean;
|
|
72
|
+
tags: TagRow[];
|
|
73
|
+
/** The tags read failed: the post shows no tags rather than claiming it has none. */
|
|
74
|
+
tagsUnavailable: boolean;
|
|
75
|
+
hasTags: boolean;
|
|
76
|
+
noTags: boolean;
|
|
77
|
+
/** Counts, as strings for the counts row; null / "" when the read carried no counts (never zeros).
|
|
78
|
+
* `likeCount` is the number the Like toggle shows. */
|
|
79
|
+
likeCount: number | null;
|
|
80
|
+
hasCounts: boolean;
|
|
81
|
+
noCounts: boolean;
|
|
82
|
+
likes: string;
|
|
83
|
+
views: string;
|
|
84
|
+
commentCount: string;
|
|
85
|
+
/** The spoken counts ("1 like", "3 views", "2 comments"). */
|
|
86
|
+
likesLabel: string;
|
|
87
|
+
viewsLabel: string;
|
|
88
|
+
commentsLabel: string;
|
|
51
89
|
/** [rico] #3370 — the body as ONE Ricos document JSON string for RichContent: the encoder has
|
|
52
90
|
* sized its media and dropped disallowed links. "" when the post has none, or the encoder rejected it. */
|
|
53
91
|
bodyJson: string;
|
|
@@ -57,6 +95,11 @@ interface S {
|
|
|
57
95
|
bodyText: string;
|
|
58
96
|
/** Share payload — the post's public URL when the payload carries one. */
|
|
59
97
|
shareUrl: string;
|
|
98
|
+
/** Blog v3 `preview`: the body is the free part of a paid post. The screen ends it with a notice. */
|
|
99
|
+
isPaid: boolean;
|
|
100
|
+
notPaid: boolean;
|
|
101
|
+
/** The paid notice's website link shows only when there is a URL to open. */
|
|
102
|
+
noShareUrl: boolean;
|
|
60
103
|
cover: string;
|
|
61
104
|
hasCover: boolean;
|
|
62
105
|
noCover: boolean;
|
|
@@ -68,17 +111,28 @@ interface S {
|
|
|
68
111
|
/** This device's reader hid the post: the feed, Home and Saved leave it out, and this screen offers Undo. */
|
|
69
112
|
hidden: boolean;
|
|
70
113
|
notHidden: boolean;
|
|
114
|
+
/** The ⋯ sheet (Report, Hide) is open. */
|
|
115
|
+
moreSheetOpen: boolean;
|
|
71
116
|
/** The reason sheet (offensive / misleading / other) is open. */
|
|
72
117
|
hideSheetOpen: boolean;
|
|
73
|
-
/** The reader reported the post this visit; the report
|
|
118
|
+
/** The reader reported the post this visit; the report row then goes and the tap stops sending. */
|
|
74
119
|
reported: boolean;
|
|
75
120
|
notReported: boolean;
|
|
76
|
-
|
|
121
|
+
commentText: string;
|
|
77
122
|
comments: CommentRow[];
|
|
123
|
+
commentsTitle: string;
|
|
78
124
|
commentsUnavailable: boolean;
|
|
79
125
|
commentsAvailable: boolean;
|
|
126
|
+
/** The owner turned comments off for this post (Blog v3 `commentingEnabled: false`). */
|
|
127
|
+
commentsOff: boolean;
|
|
128
|
+
commentsOn: boolean;
|
|
80
129
|
commentStatusText: string;
|
|
81
|
-
|
|
130
|
+
noCommentStatus: boolean;
|
|
131
|
+
recent: RecentRow[];
|
|
132
|
+
/** A "Recent posts" read failed; the section shows what the other reads found. */
|
|
133
|
+
recentUnavailable: boolean;
|
|
134
|
+
hasRecent: boolean;
|
|
135
|
+
noRecent: boolean;
|
|
82
136
|
emptyText: string;
|
|
83
137
|
errorText: string;
|
|
84
138
|
hasPost: boolean;
|
|
@@ -90,40 +144,18 @@ interface S {
|
|
|
90
144
|
blogScreenId: string;
|
|
91
145
|
}
|
|
92
146
|
|
|
93
|
-
type PostWithExtras = WixPostWithContent & {
|
|
94
|
-
media?: { wixMedia?: { image?: { url?: string } }; embedMedia?: { thumbnail?: { url?: string } } };
|
|
95
|
-
coverImage?: { image?: { url?: string }; url?: string };
|
|
96
|
-
metrics?: { likeCount?: number; likes?: number; totalComments?: number; commentCount?: number; comments?: number };
|
|
97
|
-
memberInteraction?: { liked?: boolean };
|
|
147
|
+
type PostWithExtras = WixPostWithContent & BlogPostShape & {
|
|
98
148
|
richContent?: unknown;
|
|
99
149
|
contentText?: string;
|
|
100
150
|
plainContent?: string;
|
|
101
151
|
url?: { base?: string; path?: string } | string;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
152
|
+
tagIds?: string[];
|
|
153
|
+
relatedPostIds?: string[];
|
|
154
|
+
commentingEnabled?: boolean;
|
|
155
|
+
preview?: boolean;
|
|
156
|
+
memberInteraction?: { liked?: boolean };
|
|
105
157
|
};
|
|
106
158
|
|
|
107
|
-
/** "By <name>" from the payload's writer-ish fields ("" when absent). */
|
|
108
|
-
function bylineOf(post: PostWithExtras): string {
|
|
109
|
-
const author = typeof post.author === "string" ? post.author : undefined;
|
|
110
|
-
const name = post.writer?.name ?? post.writer?.nickname
|
|
111
|
-
?? post.owner?.name ?? post.owner?.nickname
|
|
112
|
-
?? (typeof post.author === "object" ? post.author?.name ?? post.author?.nickname : undefined)
|
|
113
|
-
?? author;
|
|
114
|
-
return name && name.trim() ? copyTemplate("blogPost.byline", "By {name}", { name: name.trim() }) : "";
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** "N likes · M comments" from post.metrics ("" when both are absent/zero). */
|
|
118
|
-
function countsLineOf(post: PostWithExtras): string {
|
|
119
|
-
const likes = post.metrics?.likeCount ?? post.metrics?.likes ?? 0;
|
|
120
|
-
const comments = post.metrics?.totalComments ?? post.metrics?.commentCount ?? post.metrics?.comments ?? 0;
|
|
121
|
-
const bits: string[] = [];
|
|
122
|
-
if (likes > 0) bits.push(copyPlural("blogPost.likesCount", "{n, plural, one {# like} other {# likes}}", likes));
|
|
123
|
-
if (comments > 0) bits.push(copyPlural("blogPost.commentsCount", "{n, plural, one {# comment} other {# comments}}", comments));
|
|
124
|
-
return bits.join(" · ");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
159
|
/** The post's public URL when the payload carries one ("" otherwise). */
|
|
128
160
|
function postShareUrl(post: PostWithExtras): string {
|
|
129
161
|
if (typeof post.url === "string" && /^https?:\/\//i.test(post.url)) return post.url;
|
|
@@ -157,23 +189,13 @@ function strOf(arg: unknown): string {
|
|
|
157
189
|
return a?.value ?? a?.text ?? "";
|
|
158
190
|
}
|
|
159
191
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function subtitle(post: WixPost): string {
|
|
171
|
-
const bits: string[] = [];
|
|
172
|
-
if (post.firstPublishedDate) {
|
|
173
|
-
bits.push(formatDateMedium(new Date(post.firstPublishedDate)));
|
|
174
|
-
}
|
|
175
|
-
if (post.minutesToRead) bits.push(copyPlural("blogPost.minRead", "{n, plural, one {# min read} other {# min read}}", post.minutesToRead));
|
|
176
|
-
return bits.join(" · ");
|
|
192
|
+
/** "Updated <date>" when the last publish is on a later day than the first ("" otherwise). */
|
|
193
|
+
function updatedLineOf(post: PostWithExtras): string {
|
|
194
|
+
if (!post.firstPublishedDate || !post.lastPublishedDate) return "";
|
|
195
|
+
const first = new Date(post.firstPublishedDate), last = new Date(post.lastPublishedDate);
|
|
196
|
+
if (Number.isNaN(first.getTime()) || Number.isNaN(last.getTime())) return "";
|
|
197
|
+
if (formatDateMedium(last) === formatDateMedium(first) || last.getTime() < first.getTime()) return "";
|
|
198
|
+
return copyTemplate("blogPost.updatedLine", "Updated {date}", { date: formatDateMedium(last) });
|
|
177
199
|
}
|
|
178
200
|
|
|
179
201
|
function bodyText(post: PostWithExtras): string {
|
|
@@ -189,9 +211,11 @@ function toCommentRow(row: WixBlogCommentRow): CommentRow {
|
|
|
189
211
|
// The plain text is the document's own (runs joined as written, not space-separated) when it has one.
|
|
190
212
|
// `forum.commentCta` is the app's one "Comment": the pack forwards that single key to this screen (see the prefixes).
|
|
191
213
|
const { bodyJson, bodyText } = richBody(row.richContent, row.text || copyParam("forum.commentCta", "Comment"), ROW_IMAGE_WIDTH);
|
|
214
|
+
const authorName = row.authorName || copyParam("blogPost.memberFallback", "Member");
|
|
192
215
|
return {
|
|
193
216
|
id: row.id,
|
|
194
|
-
authorName
|
|
217
|
+
authorName,
|
|
218
|
+
authorInitial: (authorName[0] || "#").toUpperCase(),
|
|
195
219
|
text: bodyText,
|
|
196
220
|
meta: commentMeta(row),
|
|
197
221
|
bodyJson,
|
|
@@ -199,12 +223,83 @@ function toCommentRow(row: WixBlogCommentRow): CommentRow {
|
|
|
199
223
|
};
|
|
200
224
|
}
|
|
201
225
|
|
|
226
|
+
const commentsTitleFor = (count: number): string =>
|
|
227
|
+
count > 0 ? copyTemplate("blogPost.commentsTitleCount", "Comments ({count})", { count }) : copyParam("blogPost.commentsTitle", "Comments");
|
|
228
|
+
|
|
202
229
|
/** The comment text as Ricos rich content, typed against the auto tier's REST types. */
|
|
203
230
|
const commentRichContent = (text: string): comments.RichContent => ({
|
|
204
231
|
nodes: [{ type: "PARAGRAPH", id: "himi-blog-comment", nodes: [{ type: "TEXT", id: "himi-blog-comment-text", textData: { text } }] }],
|
|
205
232
|
metadata: { version: 1 },
|
|
206
233
|
});
|
|
207
234
|
|
|
235
|
+
function toRecentRow(post: WixPost): RecentRow {
|
|
236
|
+
const cover = coverOf(post as PostWithExtras, BLOG_THUMB_IMAGE);
|
|
237
|
+
return { id: post.id, title: post.title || copyParam("blogCommon.untitled", "Untitled post"), date: dateOf(post as PostWithExtras), cover, hasCover: !!cover, noCover: !cover, detailScreenId: "himi_blog_post" };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Up to three other posts: the owner's related posts, then the newest in the same category,
|
|
241
|
+
* then the newest overall. Never the current post or one this device hid. A failed read
|
|
242
|
+
* leaves that step out: the section shows what the earlier steps found, or nothing. */
|
|
243
|
+
/** How many candidates each "Recent posts" read asks for: enough that the current post and a few
|
|
244
|
+
* hidden ones can be left out and three still remain. */
|
|
245
|
+
const RECENT_CANDIDATES = 10;
|
|
246
|
+
|
|
247
|
+
async function loadRecent(post: PostWithExtras): Promise<{ posts: WixPost[]; failed: boolean }> {
|
|
248
|
+
const picked: WixPost[] = [];
|
|
249
|
+
// A failed read is recorded: the section then shows what the other reads found.
|
|
250
|
+
let failed = false;
|
|
251
|
+
const seen = new Set<string>([post.id]);
|
|
252
|
+
const add = (posts: WixPost[] | undefined) => {
|
|
253
|
+
for (const candidate of posts ?? []) {
|
|
254
|
+
if (picked.length >= RECENT_COUNT) return;
|
|
255
|
+
if (!candidate?.id || seen.has(candidate.id) || isHiddenId(candidate.id)) continue;
|
|
256
|
+
seen.add(candidate.id);
|
|
257
|
+
picked.push(candidate);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const query = async (filter: Record<string, unknown> | undefined): Promise<WixPost[] | undefined> => {
|
|
261
|
+
const base = { ...(filter ? { filter } : {}), paging: { limit: RECENT_CANDIDATES } };
|
|
262
|
+
// Newest first; a source that refuses the sort is asked again without it, as the feed does.
|
|
263
|
+
try {
|
|
264
|
+
return (await queryPosts({ query: { ...base, sort: [{ fieldName: "firstPublishedDate", order: "DESC" }] }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest)).posts;
|
|
265
|
+
} catch { /* asked again below */ }
|
|
266
|
+
try {
|
|
267
|
+
return (await queryPosts({ query: base, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest)).posts;
|
|
268
|
+
} catch { failed = true; }
|
|
269
|
+
return undefined;
|
|
270
|
+
};
|
|
271
|
+
const related = (post.relatedPostIds ?? []).filter((id) => typeof id === "string" && id);
|
|
272
|
+
if (related.length) add(await query({ id: { $in: related } }));
|
|
273
|
+
const category = post.categoryIds?.[0];
|
|
274
|
+
if (picked.length < RECENT_COUNT && category) add(await query({ categoryIds: { $hasSome: [category] } }));
|
|
275
|
+
if (picked.length < RECENT_COUNT) add(await query(undefined));
|
|
276
|
+
return { posts: picked, failed };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async function loadCategoryLabel(post: PostWithExtras): Promise<string> {
|
|
280
|
+
const ids = post.categoryIds ?? [];
|
|
281
|
+
if (!ids.length) return "";
|
|
282
|
+
try {
|
|
283
|
+
const result = await queryCategories({ paging: { limit: 100 } });
|
|
284
|
+
const labels = new Map((result.categories ?? []).map((category) => [category.id, (category.label || category.title || "").trim()]));
|
|
285
|
+
for (const id of ids) { const label = labels.get(id); if (label) return label; }
|
|
286
|
+
} catch { /* no label: the category line collapses */ }
|
|
287
|
+
return "";
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function loadTags(post: PostWithExtras): Promise<{ rows: TagRow[]; failed: boolean }> {
|
|
291
|
+
const ids = (post.tagIds ?? []).filter((id) => typeof id === "string" && id);
|
|
292
|
+
if (!ids.length) return { rows: [], failed: false };
|
|
293
|
+
let byId = new Map<string, string>();
|
|
294
|
+
let failed = false;
|
|
295
|
+
try {
|
|
296
|
+
const result = await queryTags({ filter: { id: { $in: ids } }, paging: { limit: 100 } });
|
|
297
|
+
byId = new Map((result.tags ?? []).map((tag) => [tag.id, (tag.label ?? "").trim()]));
|
|
298
|
+
} catch { failed = true; }
|
|
299
|
+
// The post's own order; a tag the site did not return is left out.
|
|
300
|
+
return { rows: ids.map((id) => ({ id, label: byId.get(id) ?? "" })).filter((tag) => tag.label), failed };
|
|
301
|
+
}
|
|
302
|
+
|
|
208
303
|
function derive(s: S): S {
|
|
209
304
|
const isLoading = s.status === "loading";
|
|
210
305
|
const errored = s.status === "error";
|
|
@@ -220,28 +315,104 @@ function derive(s: S): S {
|
|
|
220
315
|
hasCover: Boolean(s.cover),
|
|
221
316
|
noCover: !s.cover,
|
|
222
317
|
hasBodyJson: s.bodyJson !== "",
|
|
318
|
+
hasCategory: !!s.categoryLabel,
|
|
319
|
+
noCategory: !s.categoryLabel,
|
|
320
|
+
hasTags: s.tags.length > 0,
|
|
321
|
+
noTags: s.tags.length === 0,
|
|
322
|
+
likes: s.likeCount === null ? "" : String(Math.max(0, s.likeCount)),
|
|
323
|
+
likesLabel: s.likeCount === null ? "" : likesLabelFor(Math.max(0, s.likeCount)),
|
|
324
|
+
viewsLabel: s.views === "" ? "" : viewsLabelFor(Number(s.views) || 0),
|
|
325
|
+
commentsLabel: s.commentCount === "" ? "" : commentsLabelFor(Number(s.commentCount) || 0),
|
|
326
|
+
hasCounts: s.likeCount !== null,
|
|
327
|
+
noCounts: s.likeCount === null,
|
|
328
|
+
noShareUrl: !s.shareUrl,
|
|
329
|
+
noCommentStatus: !s.commentStatusText,
|
|
330
|
+
notPaid: !s.isPaid,
|
|
223
331
|
notLiked: !s.liked,
|
|
224
332
|
notSaved: !s.saved,
|
|
225
333
|
notHidden: !s.hidden,
|
|
226
334
|
notReported: !s.reported,
|
|
227
335
|
commentsAvailable: !s.commentsUnavailable,
|
|
336
|
+
commentsOn: !s.commentsOff,
|
|
337
|
+
hasRecent: s.recent.length > 0,
|
|
338
|
+
noRecent: s.recent.length === 0,
|
|
228
339
|
};
|
|
229
340
|
}
|
|
230
341
|
|
|
342
|
+
/** A message after an action, as the app's snackbar (a toast above the tab bar that closes on its
|
|
343
|
+
* own); after Hide its button is Undo, which runs `unhide`. The state is returned as it is: the
|
|
344
|
+
* screen shows the change itself. A host with no snackbar presenter shows nothing. */
|
|
345
|
+
function say(s: S, message: string, undo = false): S {
|
|
346
|
+
if (message) {
|
|
347
|
+
// Undo names the post it hid: the reader may have opened another post (Recent posts) by then.
|
|
348
|
+
const action = undo ? { action: { label: copyParam("blogCommon.undoCta", "Undo"), actionId: "tier5.himiBlogPost.unhide", args: { id: s.id } } } : {};
|
|
349
|
+
void snackbar({ message, ...action }).catch(() => undefined);
|
|
350
|
+
}
|
|
351
|
+
return derive(s);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** A like or comment the site refused (401/403: a visitor, or a member without the right) opens the
|
|
355
|
+
* app's sign-in, as the post's own Sign in button does, instead of telling the reader to sign in. */
|
|
356
|
+
const signIn = (s: S): S => navigate(derive(s), { screenId: s.signInScreenId, args: { mode: "signin" } });
|
|
357
|
+
|
|
358
|
+
/** The post a like or unlike call is on its way for ("" = none). */
|
|
359
|
+
let likeInFlight = "";
|
|
360
|
+
|
|
361
|
+
/** The state as it is now (set once the service exists). An action that awaits the network builds its
|
|
362
|
+
* result on this, not on the state it was tapped in: a Save, Hide or message that landed meanwhile stays. */
|
|
363
|
+
let committed: () => S | undefined = () => undefined;
|
|
364
|
+
/** After an await: the current state, or null when the reader opened another post meanwhile. A
|
|
365
|
+
* runtime that reports no state gets the state the action was tapped in. */
|
|
366
|
+
function samePost(s: S): S | null {
|
|
367
|
+
const now = committed();
|
|
368
|
+
if (!now) return s;
|
|
369
|
+
return now.id === s.id ? now : null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** The counts after a like (`step` 1) or an unlike (-1). The site answers with METRICS read before
|
|
373
|
+
* the change (seen on the demo site: a post with one like answered a like with 1 and the unlike
|
|
374
|
+
* with 2), so the like count moves by one from what the screen showed, or from the answer when the
|
|
375
|
+
* screen had none; an answer that already moved past that is taken as it is. Views and comments
|
|
376
|
+
* come with it, so a post read without counts never shows a likes number beside two empty chips. */
|
|
377
|
+
function countsAfter(now: S, after: { likes: number; comments: number; views: number } | null, step: 1 | -1): Partial<S> {
|
|
378
|
+
if (!after) return {};
|
|
379
|
+
const base = now.likeCount ?? after.likes;
|
|
380
|
+
const likeCount = step > 0 ? Math.max(after.likes, base + 1) : Math.max(0, Math.min(after.likes, base - 1));
|
|
381
|
+
return { likeCount, views: String(after.views), commentCount: String(Math.max(after.comments, now.comments.length, Number(now.commentCount) || 0)) };
|
|
382
|
+
}
|
|
383
|
+
|
|
231
384
|
const baseState: S = derive({
|
|
232
385
|
...NO_READ_SIGN_IN, signInScreenId: "himi_account",
|
|
386
|
+
...NO_AUTHOR,
|
|
233
387
|
status: "loading",
|
|
234
388
|
id: "",
|
|
235
389
|
commentResourceId: "",
|
|
236
390
|
title: "",
|
|
237
391
|
subtitle: "",
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
392
|
+
updatedLine: "",
|
|
393
|
+
categoryLabel: "",
|
|
394
|
+
hasCategory: false,
|
|
395
|
+
noCategory: true,
|
|
396
|
+
tags: [],
|
|
397
|
+
tagsUnavailable: false,
|
|
398
|
+
hasTags: false,
|
|
399
|
+
noTags: true,
|
|
400
|
+
likeCount: null,
|
|
401
|
+
hasCounts: false,
|
|
402
|
+
noCounts: true,
|
|
403
|
+
likes: "0",
|
|
404
|
+
views: "",
|
|
405
|
+
commentCount: "",
|
|
406
|
+
likesLabel: "",
|
|
407
|
+
viewsLabel: "",
|
|
408
|
+
commentsLabel: "",
|
|
241
409
|
bodyJson: "",
|
|
242
410
|
hasBodyJson: false,
|
|
243
411
|
bodyText: "",
|
|
244
412
|
shareUrl: "",
|
|
413
|
+
isPaid: false,
|
|
414
|
+
notPaid: true,
|
|
415
|
+
noShareUrl: true,
|
|
245
416
|
cover: "",
|
|
246
417
|
hasCover: false,
|
|
247
418
|
noCover: true,
|
|
@@ -252,15 +423,23 @@ const baseState: S = derive({
|
|
|
252
423
|
notSaved: true,
|
|
253
424
|
hidden: false,
|
|
254
425
|
notHidden: true,
|
|
426
|
+
moreSheetOpen: false,
|
|
255
427
|
hideSheetOpen: false,
|
|
256
428
|
reported: false,
|
|
257
429
|
notReported: true,
|
|
258
|
-
|
|
430
|
+
commentText: "",
|
|
259
431
|
comments: [],
|
|
432
|
+
commentsTitle: "Comments",
|
|
260
433
|
commentsUnavailable: false,
|
|
261
434
|
commentsAvailable: true,
|
|
435
|
+
commentsOff: false,
|
|
436
|
+
commentsOn: true,
|
|
262
437
|
commentStatusText: "",
|
|
263
|
-
|
|
438
|
+
noCommentStatus: true,
|
|
439
|
+
recent: [],
|
|
440
|
+
recentUnavailable: false,
|
|
441
|
+
hasRecent: false,
|
|
442
|
+
noRecent: true,
|
|
264
443
|
emptyText: "",
|
|
265
444
|
errorText: "",
|
|
266
445
|
hasPost: false,
|
|
@@ -280,23 +459,34 @@ async function cachedPostState(s: S, id: string): Promise<S> {
|
|
|
280
459
|
return derive({ ...s, status: "error", id, errorText: copyParam("blogPost.errorText", "This post could not load.") });
|
|
281
460
|
}
|
|
282
461
|
const title = String(cached.title ?? "") || "Untitled post";
|
|
462
|
+
const fixed = { ...cached, ...legacyRowFixes(cached) };
|
|
463
|
+
const author = cached.hasAuthor === true
|
|
464
|
+
? authorFields({ name: String(cached.authorName ?? ""), photo: String(cached.authorPhoto ?? ""), initial: String(cached.authorInitial ?? "") })
|
|
465
|
+
: NO_AUTHOR;
|
|
283
466
|
return derive({
|
|
284
467
|
...s,
|
|
468
|
+
...author,
|
|
285
469
|
status: "ready",
|
|
286
470
|
id,
|
|
287
471
|
commentResourceId: "",
|
|
288
472
|
title,
|
|
289
473
|
subtitle: String(cached.meta ?? ""),
|
|
290
|
-
|
|
474
|
+
categoryLabel: String(fixed.category ?? ""),
|
|
475
|
+
// A row cached by an older build has no counts: unknown, not zero.
|
|
476
|
+
likeCount: cached.hasCounts === true ? Number(cached.likes) || 0 : null,
|
|
477
|
+
views: cached.hasCounts === true ? String(cached.views ?? "") : "",
|
|
478
|
+
commentCount: cached.hasCounts === true ? String(cached.comments ?? "") : "",
|
|
291
479
|
// The feed caches no Ricos body, so the offline copy is plain text (the descriptor's gated text shows it).
|
|
292
480
|
bodyJson: "",
|
|
293
|
-
|
|
294
|
-
|
|
481
|
+
// `||`, not `??`: the feed caches an empty excerpt as "", which is no body either.
|
|
482
|
+
bodyText: String(cached.body || fixed.excerpt || copyParam("blogPost.bodyFallback", "This post has no readable body yet.")),
|
|
483
|
+
cover: cachedCover(cached, BLOG_HERO_IMAGE),
|
|
295
484
|
initial: String(cached.initial ?? "") || (title[0] || "#").toUpperCase(),
|
|
296
485
|
liked: false,
|
|
297
486
|
saved: isSavedId(id),
|
|
298
487
|
hidden: isHiddenId(id),
|
|
299
488
|
comments: [],
|
|
489
|
+
commentsTitle: commentsTitleFor(0),
|
|
300
490
|
commentsUnavailable: true,
|
|
301
491
|
commentStatusText: copyParam("blogPost.commentsUnavailable", "Comments are unavailable right now."),
|
|
302
492
|
errorText: "",
|
|
@@ -304,8 +494,63 @@ async function cachedPostState(s: S, id: string): Promise<S> {
|
|
|
304
494
|
});
|
|
305
495
|
}
|
|
306
496
|
|
|
497
|
+
/** The network half of a post load: the post and its comments, author, category, tags and recent
|
|
498
|
+
* posts, unmapped (the copy pack that names them arrives with the screen's onAppear load). */
|
|
499
|
+
interface PostFetch {
|
|
500
|
+
post: PostWithExtras;
|
|
501
|
+
comments: { rows: WixBlogCommentRow[]; unavailable: boolean };
|
|
502
|
+
authors: Map<string, BlogAuthor>;
|
|
503
|
+
categoryLabel: string;
|
|
504
|
+
tags: { rows: TagRow[]; failed: boolean };
|
|
505
|
+
recent: { posts: WixPost[]; failed: boolean };
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async function fetchPost(id: string, access: ReadAccess): Promise<PostFetch> {
|
|
509
|
+
const response = await getPost(id, { fieldsets: ["RICH_CONTENT", "CONTENT_TEXT", "INTERNAL_ID", "METRICS", "URL"] }, { preserveAccessErrors: true });
|
|
510
|
+
// The reader may have changed (sign-in, another site) while the post was read: its dependent
|
|
511
|
+
// reads (Comments above all) must not start under the new reader.
|
|
512
|
+
await assertReadAccess(access);
|
|
513
|
+
const post = response.post as PostWithExtras;
|
|
514
|
+
// Native Blog v3 Comments scopes by internalId, not the navigation UUID.
|
|
515
|
+
// A missing projection cannot establish that the post has no comments.
|
|
516
|
+
const commentResourceId = post.internalId?.trim() ?? "";
|
|
517
|
+
const loadComments = async (): Promise<{ rows: WixBlogCommentRow[]; unavailable: boolean }> => {
|
|
518
|
+
if (!commentResourceId) return { rows: [], unavailable: true };
|
|
519
|
+
try { return { rows: await listBlogComments(commentResourceId), unavailable: false }; }
|
|
520
|
+
catch { return { rows: [], unavailable: true }; }
|
|
521
|
+
};
|
|
522
|
+
const [comments, authors, categoryLabel, tags, recent] = await Promise.all([
|
|
523
|
+
loadComments(),
|
|
524
|
+
resolveAuthors([post.memberId]),
|
|
525
|
+
loadCategoryLabel(post),
|
|
526
|
+
loadTags(post),
|
|
527
|
+
loadRecent(post),
|
|
528
|
+
]);
|
|
529
|
+
return { post, comments, authors, categoryLabel, tags, recent };
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// The worker loads at boot AND again on the screen's onAppear (which carries the copy pack). The
|
|
533
|
+
// second load reuses the first one's reads, in flight or finished in the last FETCH_REUSE_MS, for
|
|
534
|
+
// the same post and the same reader; a Retry always reads again.
|
|
535
|
+
const FETCH_REUSE_MS = 10_000;
|
|
536
|
+
let lastFetch: { key: string; at: number; promise: Promise<PostFetch> } | null = null;
|
|
537
|
+
function sharedFetch(id: string, access: ReadAccess, fresh: boolean): Promise<PostFetch> {
|
|
538
|
+
const key = `${JSON.stringify(access)}|${id}`;
|
|
539
|
+
if (!fresh && lastFetch?.key === key && Date.now() - lastFetch.at < FETCH_REUSE_MS) return lastFetch.promise;
|
|
540
|
+
const promise = fetchPost(id, access);
|
|
541
|
+
const entry = { key, at: Date.now(), promise };
|
|
542
|
+
lastFetch = entry;
|
|
543
|
+
// A failed read is never handed to the next load.
|
|
544
|
+
promise.catch(() => { if (lastFetch === entry) lastFetch = null; });
|
|
545
|
+
return promise;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** After the reader changes the post (a like, a comment), the next load reads it again: the
|
|
549
|
+
* reused answer predates the change. */
|
|
550
|
+
function forgetFetch(): void { lastFetch = null; }
|
|
551
|
+
|
|
307
552
|
let loadVersion = 0;
|
|
308
|
-
async function loadPostState(s: S): Promise<S | undefined> {
|
|
553
|
+
async function loadPostState(s: S, fresh = false): Promise<S | undefined> {
|
|
309
554
|
const version = ++loadVersion;
|
|
310
555
|
await svc.prepare();
|
|
311
556
|
const clean = { ...baseState, signInScreenId: s.signInScreenId };
|
|
@@ -315,46 +560,51 @@ async function loadPostState(s: S): Promise<S | undefined> {
|
|
|
315
560
|
}
|
|
316
561
|
try {
|
|
317
562
|
const access = await readAccess();
|
|
318
|
-
const
|
|
563
|
+
const { post, comments: commentResult, authors, categoryLabel, tags, recent } = await sharedFetch(id, access, fresh);
|
|
319
564
|
await assertReadAccess(access);
|
|
320
565
|
if (version !== loadVersion) return undefined;
|
|
321
|
-
const post = response.post as PostWithExtras;
|
|
322
|
-
// Native Blog v3 Comments scopes by internalId, not the navigation UUID.
|
|
323
|
-
// A missing projection cannot establish that the post has no comments.
|
|
324
566
|
const commentResourceId = post.internalId?.trim() ?? "";
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
await assertReadAccess(access);
|
|
332
|
-
if (version !== loadVersion) return undefined;
|
|
333
|
-
const cover = imageUrl(post);
|
|
334
|
-
const title = post.title || "Untitled post";
|
|
567
|
+
const commentsOff = post.commentingEnabled === false;
|
|
568
|
+
const cover = coverOf(post, BLOG_HERO_IMAGE);
|
|
569
|
+
const title = post.title || copyParam("blogCommon.untitled", "Untitled post");
|
|
570
|
+
const counts = countsOf(post);
|
|
571
|
+
const commentRows = commentResult.rows.map(toCommentRow);
|
|
335
572
|
return derive({
|
|
336
573
|
...clean,
|
|
574
|
+
...authorFields(authors.get(post.memberId ?? "")),
|
|
337
575
|
status: "ready",
|
|
338
576
|
id,
|
|
339
577
|
commentResourceId,
|
|
340
578
|
title,
|
|
341
|
-
subtitle:
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
579
|
+
subtitle: dateLineOf(post),
|
|
580
|
+
updatedLine: updatedLineOf(post),
|
|
581
|
+
categoryLabel,
|
|
582
|
+
tags: tags.rows,
|
|
583
|
+
tagsUnavailable: tags.failed,
|
|
584
|
+
likeCount: counts ? counts.likes : null,
|
|
585
|
+
views: counts ? String(counts.views) : "",
|
|
586
|
+
// The loaded list is the better count when the site's metric lags (or is missing).
|
|
587
|
+
commentCount: counts ? String(Math.max(counts.comments, commentRows.length)) : commentResult.unavailable ? "" : String(commentRows.length),
|
|
345
588
|
// No Ricos body, or one the encoder rejects: bodyJson "" and the gated plain text shows bodyText.
|
|
346
589
|
...richBody(post.richContent, bodyText(post)),
|
|
347
590
|
shareUrl: postShareUrl(post),
|
|
591
|
+
isPaid: post.preview === true,
|
|
348
592
|
cover,
|
|
349
593
|
initial: (title[0] || "#").toUpperCase(),
|
|
350
594
|
liked: Boolean(post.memberInteraction?.liked),
|
|
351
595
|
saved: isSavedId(id),
|
|
352
596
|
hidden: isHiddenId(id),
|
|
353
|
-
comments,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
597
|
+
comments: commentRows,
|
|
598
|
+
commentsTitle: commentsTitleFor(Math.max(counts?.comments ?? 0, commentRows.length)),
|
|
599
|
+
commentsUnavailable: commentResult.unavailable,
|
|
600
|
+
commentsOff,
|
|
601
|
+
commentStatusText: commentsOff
|
|
602
|
+
? copyParam("blogPost.commentsOff", "Comments are turned off for this post.")
|
|
603
|
+
: commentResult.unavailable
|
|
604
|
+
? copyParam("blogPost.commentsUnavailable", "Comments are unavailable right now.")
|
|
605
|
+
: commentRows.length ? "" : copyParam("blogPost.commentsEmpty", "No comments yet."),
|
|
606
|
+
recent: recent.posts.map(toRecentRow),
|
|
607
|
+
recentUnavailable: recent.failed,
|
|
358
608
|
errorText: "",
|
|
359
609
|
emptyText: "",
|
|
360
610
|
});
|
|
@@ -375,9 +625,11 @@ const svc = defineService<S, {
|
|
|
375
625
|
prepare: (s: S) => S;
|
|
376
626
|
load: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
377
627
|
retry: (s: S) => Promise<S | undefined>;
|
|
378
|
-
like: (s: S) => Promise<S>;
|
|
379
|
-
unlike: (s: S) => Promise<S>;
|
|
628
|
+
like: (s: S) => Promise<S | undefined>;
|
|
629
|
+
unlike: (s: S) => Promise<S | undefined>;
|
|
380
630
|
toggleSave: (s: S) => S;
|
|
631
|
+
openMore: (s: S) => S;
|
|
632
|
+
closeMore: (s: S) => S;
|
|
381
633
|
/** Report the post: no site API takes a member's report, so the reader is thanked and the tap is the signal. */
|
|
382
634
|
report: (s: S) => S;
|
|
383
635
|
openHide: (s: S) => S;
|
|
@@ -385,12 +637,17 @@ const svc = defineService<S, {
|
|
|
385
637
|
/** Hide the post on this device. The sheet's three reasons (offensive, misleading, other) are asked for as the One
|
|
386
638
|
* App asks them, but the list keeps only the id and the site is told nothing, so the worker does not read the reason. */
|
|
387
639
|
hide: (s: S) => S;
|
|
388
|
-
|
|
389
|
-
|
|
640
|
+
/** `{ id }`: the snackbar's Undo names the post it hid; ⋯ → Show post leaves it out (this post). */
|
|
641
|
+
unhide: (s: S, arg?: unknown) => S;
|
|
642
|
+
/** Resolves after the share sheet closes; success keeps the state as it is THEN (undefined), so a
|
|
643
|
+
* message that closed meanwhile does not come back. */
|
|
644
|
+
share: (s: S) => Promise<S | undefined>;
|
|
645
|
+
/** The paid-post notice's link: the post on the site, where a subscriber can read all of it. */
|
|
646
|
+
openOnWebsite: (s: S) => Promise<S | undefined>;
|
|
390
647
|
setComment: (s: S, arg?: unknown) => S;
|
|
391
|
-
submitComment: (s: S) => Promise<S>;
|
|
648
|
+
submitComment: (s: S) => Promise<S | undefined>;
|
|
392
649
|
/** [rico] #3370 — RichContent's on_link: `{ url }` of the tapped link. */
|
|
393
|
-
openLink: (s: S, arg?: unknown) => Promise<S>;
|
|
650
|
+
openLink: (s: S, arg?: unknown) => Promise<S | undefined>;
|
|
394
651
|
}>("himiBlogPost", {
|
|
395
652
|
state: baseState,
|
|
396
653
|
actions: {
|
|
@@ -400,93 +657,132 @@ const svc = defineService<S, {
|
|
|
400
657
|
const target = (arg as { signInScreenId?: unknown })?.signInScreenId;
|
|
401
658
|
return loadPostState({ ...s, signInScreenId: target === "himi_sign_in" ? target : s.signInScreenId });
|
|
402
659
|
},
|
|
403
|
-
retry: (s) => loadPostState({ ...s, status: "loading", errorText: "" }),
|
|
660
|
+
retry: (s) => loadPostState({ ...s, status: "loading", errorText: "" }, true),
|
|
404
661
|
like: async (s) => {
|
|
405
|
-
if (!s.id) return
|
|
662
|
+
if (!s.id) return say(s, copyParam("blogPost.noPostMessage", "No post selected."));
|
|
663
|
+
// A second tap while the first is on its way is ignored: each answer moves the count by one.
|
|
664
|
+
if (likeInFlight === s.id) return undefined;
|
|
665
|
+
likeInFlight = s.id;
|
|
406
666
|
try {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
667
|
+
// The count after the like (see countsAfter); with no counts in the answer it is left as it
|
|
668
|
+
// was (the member may have liked before: "liked" is not readable here).
|
|
669
|
+
const after = countsOf(((await likePost(s.id))?.post ?? {}) as BlogPostShape);
|
|
670
|
+
forgetFetch();
|
|
671
|
+
const now = samePost(s);
|
|
672
|
+
return now ? say({ ...now, liked: true, ...countsAfter(now, after, 1) }, copyParam("blogPost.likedMessage", "Liked")) : undefined;
|
|
673
|
+
} catch (error) {
|
|
674
|
+
const now = samePost(s);
|
|
675
|
+
if (!now) return undefined;
|
|
676
|
+
return readAccessDenied(error) ? signIn(now) : say(now, copyParam("blogPost.likeFailed", "Could not update like."));
|
|
677
|
+
} finally {
|
|
678
|
+
likeInFlight = "";
|
|
411
679
|
}
|
|
412
680
|
},
|
|
413
681
|
unlike: async (s) => {
|
|
414
682
|
if (!s.id) return s;
|
|
683
|
+
if (likeInFlight === s.id) return undefined;
|
|
684
|
+
likeInFlight = s.id;
|
|
415
685
|
try {
|
|
416
|
-
await unlikePost(s.id);
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return
|
|
686
|
+
const after = countsOf(((await unlikePost(s.id))?.post ?? {}) as BlogPostShape);
|
|
687
|
+
forgetFetch();
|
|
688
|
+
const now = samePost(s);
|
|
689
|
+
return now ? say({ ...now, liked: false, ...countsAfter(now, after, -1) }, copyParam("blogPost.likeRemovedMessage", "Like removed")) : undefined;
|
|
690
|
+
} catch (error) {
|
|
691
|
+
const now = samePost(s);
|
|
692
|
+
if (!now) return undefined;
|
|
693
|
+
return readAccessDenied(error) ? signIn(now) : say(now, copyParam("blogPost.likeFailed", "Could not update like."));
|
|
694
|
+
} finally {
|
|
695
|
+
likeInFlight = "";
|
|
420
696
|
}
|
|
421
697
|
},
|
|
422
698
|
toggleSave: (s) => {
|
|
423
699
|
if (!s.id) return s;
|
|
424
700
|
const saved = toggleSavedId(s.id);
|
|
425
|
-
return
|
|
701
|
+
return say({ ...s, saved }, saved ? copyParam("blogPost.savedMessage", "Saved for later") : copyParam("blogPost.unsavedMessage", "Removed from saved"));
|
|
426
702
|
},
|
|
703
|
+
openMore: (s) => s.id ? derive({ ...s, moreSheetOpen: true, hideSheetOpen: false }) : s,
|
|
704
|
+
closeMore: (s) => derive({ ...s, moreSheetOpen: false }),
|
|
427
705
|
report: (s) => {
|
|
428
|
-
if (!s.id || s.reported) return s;
|
|
429
|
-
return
|
|
706
|
+
if (!s.id || s.reported) return derive({ ...s, moreSheetOpen: false });
|
|
707
|
+
return say({ ...s, reported: true, moreSheetOpen: false }, copyParam("blogPost.reportedMessage", "Post reported"));
|
|
430
708
|
},
|
|
431
|
-
|
|
709
|
+
// The reason sheet replaces the ⋯ sheet: two sheets never show at once.
|
|
710
|
+
openHide: (s) => s.id ? derive({ ...s, moreSheetOpen: false, hideSheetOpen: true }) : s,
|
|
432
711
|
closeHide: (s) => derive({ ...s, hideSheetOpen: false }),
|
|
433
712
|
hide: (s) => {
|
|
434
713
|
if (!s.id) return s;
|
|
435
714
|
hideId(s.id);
|
|
436
|
-
return
|
|
715
|
+
return say({ ...s, hidden: true, hideSheetOpen: false, moreSheetOpen: false }, copyParam("blogPost.hiddenMessage", "Post hidden. It will not show in your feeds."), true);
|
|
437
716
|
},
|
|
438
|
-
unhide: (s) => {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
717
|
+
unhide: (s, arg) => {
|
|
718
|
+
const named = (arg as { id?: unknown } | undefined)?.id;
|
|
719
|
+
const id = typeof named === "string" && named ? named : s.id;
|
|
720
|
+
if (!id) return s;
|
|
721
|
+
unhideId(id);
|
|
722
|
+
// Another post on screen keeps its own state; the message still says the hidden one is back.
|
|
723
|
+
const next = id === s.id ? { ...s, hidden: false, moreSheetOpen: false } : s;
|
|
724
|
+
return say(next, copyParam("blogPost.unhiddenMessage", "Post is visible again"));
|
|
442
725
|
},
|
|
443
726
|
share: async (s) => {
|
|
444
727
|
if (!s.title) return s;
|
|
445
728
|
try {
|
|
446
729
|
await shareSheet({ subject: s.title, text: s.title, ...(s.shareUrl ? { url: s.shareUrl } : {}) });
|
|
447
|
-
return
|
|
730
|
+
return undefined;
|
|
448
731
|
} catch {
|
|
449
|
-
return
|
|
732
|
+
return say(s, copyParam("blogPost.shareUnavailable", "Sharing is not available on this device."));
|
|
450
733
|
}
|
|
451
734
|
},
|
|
452
|
-
|
|
735
|
+
openOnWebsite: async (s) => {
|
|
736
|
+
// Opened: keep the state as it is now (the browser may have been open for a while).
|
|
737
|
+
return (await openRichLink({ url: s.shareUrl })) ? undefined : say(s, copyParam("blogPost.linkOpenFailed", "This link could not be opened."));
|
|
738
|
+
},
|
|
739
|
+
setComment: (s, arg) => derive({ ...s, commentText: strOf(arg) }),
|
|
453
740
|
submitComment: async (s) => {
|
|
454
|
-
const text = s.
|
|
455
|
-
if (
|
|
456
|
-
if (!
|
|
741
|
+
const text = s.commentText.trim();
|
|
742
|
+
if (s.commentsOff) return s;
|
|
743
|
+
if (!text) return say(s, copyParam("blogPost.commentValidation", "Write a comment first."));
|
|
744
|
+
if (!s.commentResourceId) return say(s, copyParam("blogPost.commentsUnavailable", "Comments are unavailable right now."));
|
|
457
745
|
try {
|
|
458
746
|
const { comment } = await comments.createComment({
|
|
459
747
|
comment: { appId: BLOG_COMMENTS_APP_ID, contextId: s.commentResourceId, resourceId: s.commentResourceId, content: { richContent: commentRichContent(text) } },
|
|
460
748
|
});
|
|
749
|
+
forgetFetch();
|
|
750
|
+
const now = samePost(s);
|
|
751
|
+
if (!now) return undefined;
|
|
461
752
|
const created = blogCommentRow(comment);
|
|
462
753
|
// Named to avoid shadowing the `comments` namespace import in this same block scope.
|
|
463
|
-
const updatedComments = [toCommentRow(created), ...
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
754
|
+
const updatedComments = [toCommentRow(created), ...now.comments];
|
|
755
|
+
// An unknown count (no METRICS, no comment list) stays unknown: one more of an unknown number is not 1.
|
|
756
|
+
const total = now.commentCount === "" ? null : Math.max(Number(now.commentCount) || 0, now.comments.length) + 1;
|
|
757
|
+
return say({
|
|
758
|
+
...now,
|
|
759
|
+
// Text typed while the comment was sending stays in the box.
|
|
760
|
+
commentText: now.commentText.trim() === text ? "" : now.commentText,
|
|
467
761
|
comments: updatedComments,
|
|
762
|
+
commentCount: total === null ? "" : String(total),
|
|
763
|
+
commentsTitle: commentsTitleFor(total ?? 0),
|
|
468
764
|
commentsUnavailable: false,
|
|
469
765
|
commentStatusText: "",
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
actionMessage: copyParam("blogPost.commentNeedsSignIn", "Sign in to comment."),
|
|
478
|
-
});
|
|
766
|
+
}, copyParam("blogPost.commentPosted", "Comment posted"));
|
|
767
|
+
} catch (error) {
|
|
768
|
+
// A refusal opens sign-in; any other failure says so and keeps the text to send again. The
|
|
769
|
+
// comment list that loaded stays as it is: one failed post is not "comments unavailable".
|
|
770
|
+
const now = samePost(s);
|
|
771
|
+
if (!now) return undefined;
|
|
772
|
+
return readAccessDenied(error) ? signIn(now) : say(now, copyParam("blogPost.commentsUnavailable", "Comments are unavailable right now."));
|
|
479
773
|
}
|
|
480
774
|
},
|
|
481
775
|
// Only http(s), mailto and tel links reach open_url; a refused link, or one nothing opened, says so, and
|
|
482
776
|
// a link that opens clears that message rather than leaving an earlier failure on screen.
|
|
483
|
-
openLink: async (s, arg) =>
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
777
|
+
openLink: async (s, arg) => {
|
|
778
|
+
const opened = await openRichLink(arg);
|
|
779
|
+
const now = samePost(s);
|
|
780
|
+
return now ? say(now, opened ? "" : copyParam("blogPost.linkOpenFailed", "This link could not be opened.")) : undefined;
|
|
781
|
+
},
|
|
487
782
|
},
|
|
488
783
|
});
|
|
489
784
|
|
|
785
|
+
committed = () => (svc as { getState?: () => S }).getState?.();
|
|
490
786
|
svc.prepare();
|
|
491
787
|
svc.load();
|
|
492
788
|
export { svc };
|