@wix/himalaya-cli 0.1646.0 → 0.1648.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.
Files changed (155) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +3 -1
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +4 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/validator.d.ts +6 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/blog-v3/src/extensions.d.ts +21 -3
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/media/src/rendition.d.ts +6 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/members-v1/src/index.d.ts +5 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +1 -0
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +4 -0
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +1 -0
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-blog.mjs +8 -3
  11. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-events.mjs +4 -0
  12. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-media.mjs +22 -4
  13. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-members.mjs +5 -0
  14. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-rich-content.mjs +4 -0
  15. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-stores-collections.mjs +4 -0
  16. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-stores.mjs +4 -0
  17. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-video.mjs +4 -0
  18. package/dist/browser-plane/assets.json +5 -5
  19. package/dist/browser-plane/preview-deferred/{155f61519885c85d61a39fa595197071a3ca07680da56055ccb1dcff2e709cd1.bin → 4ef4d326496b4d7809746936207067b4c921f5db9878ecc7030aa3a9e4d2aaeb.bin} +1 -1
  20. package/dist/browser-plane/sw.js +5 -5
  21. package/dist/cli.mjs +4100 -3355
  22. package/dist/preview-assets.generated.bin +0 -0
  23. package/guides/component-reference.json +1 -1
  24. package/guides/component-reference.md +2 -0
  25. package/guides/designing-himi-screens.md +4 -0
  26. package/guides/himi-skill.md +6 -0
  27. package/guides/image-preview.md +92 -0
  28. package/guides/index.json +7 -0
  29. package/guides/release-notes.md +6 -0
  30. package/guides/sdk-reference.json +42 -3
  31. package/package.json +2 -2
  32. package/templates/beauty-salon/config.ts +1 -1
  33. package/templates/beauty-salon/dev/index.ts +2773 -2969
  34. package/templates/beauty-salon/tier5-src/_shared/collection-contract.ts +0 -1
  35. package/templates/beauty-salon/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  36. package/templates/beauty-salon/tier5-src/_shared/himi-blog-saved.ts +0 -10
  37. package/templates/beauty-salon/tier5-src/himi-blog-feed/index.ts +220 -95
  38. package/templates/beauty-salon/tier5-src/himi-blog-post/index.ts +436 -140
  39. package/templates/beauty-salon/tier5-src/himi-blog-saved/index.ts +97 -39
  40. package/templates/beauty-salon-owner/dev/index.ts +7 -0
  41. package/templates/beauty-salon-owner/tier5-src/_shared/collection-contract.ts +0 -1
  42. package/templates/branded-lite/config.ts +1 -1
  43. package/templates/branded-lite/dev/index.ts +2741 -2937
  44. package/templates/branded-lite/l10n/en.json +12 -12
  45. package/templates/branded-lite/tier5-src/_shared/collection-contract.ts +0 -1
  46. package/templates/branded-lite/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  47. package/templates/branded-lite/tier5-src/_shared/himi-blog-saved.ts +0 -10
  48. package/templates/branded-lite/tier5-src/himi-blog-feed/index.ts +220 -95
  49. package/templates/branded-lite/tier5-src/himi-blog-post/index.ts +436 -140
  50. package/templates/branded-lite/tier5-src/himi-blog-saved/index.ts +97 -39
  51. package/templates/community-club/config.ts +1 -1
  52. package/templates/community-club/dev/index.ts +2799 -2995
  53. package/templates/community-club/tier5-src/_shared/collection-contract.ts +0 -1
  54. package/templates/community-club/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  55. package/templates/community-club/tier5-src/_shared/himi-blog-saved.ts +0 -10
  56. package/templates/community-club/tier5-src/himi-blog-feed/index.ts +220 -95
  57. package/templates/community-club/tier5-src/himi-blog-post/index.ts +436 -140
  58. package/templates/community-club/tier5-src/himi-blog-saved/index.ts +97 -39
  59. package/templates/community-club-owner/dev/index.ts +7 -0
  60. package/templates/community-club-owner/tier5-src/_shared/collection-contract.ts +0 -1
  61. package/templates/conference/tier5-src/_shared/collection-contract.ts +0 -1
  62. package/templates/events-meetups/config.ts +1 -1
  63. package/templates/events-meetups/dev/index.ts +2859 -3055
  64. package/templates/events-meetups/tier5-src/_shared/collection-contract.ts +0 -1
  65. package/templates/events-meetups/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  66. package/templates/events-meetups/tier5-src/_shared/himi-blog-saved.ts +0 -10
  67. package/templates/events-meetups/tier5-src/himi-blog-feed/index.ts +220 -95
  68. package/templates/events-meetups/tier5-src/himi-blog-post/index.ts +436 -140
  69. package/templates/events-meetups/tier5-src/himi-blog-saved/index.ts +97 -39
  70. package/templates/events-meetups-owner/dev/index.ts +7 -0
  71. package/templates/events-meetups-owner/tier5-src/_shared/collection-contract.ts +0 -1
  72. package/templates/gym-fitness/config.ts +1 -1
  73. package/templates/gym-fitness/dev/index.ts +2733 -2929
  74. package/templates/gym-fitness/tier5-src/_shared/collection-contract.ts +0 -1
  75. package/templates/gym-fitness/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  76. package/templates/gym-fitness/tier5-src/_shared/himi-blog-saved.ts +0 -10
  77. package/templates/gym-fitness/tier5-src/himi-blog-feed/index.ts +220 -95
  78. package/templates/gym-fitness/tier5-src/himi-blog-post/index.ts +436 -140
  79. package/templates/gym-fitness/tier5-src/himi-blog-saved/index.ts +97 -39
  80. package/templates/gym-fitness-owner/dev/index.ts +7 -0
  81. package/templates/gym-fitness-owner/tier5-src/_shared/collection-contract.ts +0 -1
  82. package/templates/nonprofit-cause/config.ts +1 -1
  83. package/templates/nonprofit-cause/dev/index.ts +2813 -3009
  84. package/templates/nonprofit-cause/tier5-src/_shared/collection-contract.ts +0 -1
  85. package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  86. package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-saved.ts +0 -10
  87. package/templates/nonprofit-cause/tier5-src/himi-blog-feed/index.ts +220 -95
  88. package/templates/nonprofit-cause/tier5-src/himi-blog-post/index.ts +436 -140
  89. package/templates/nonprofit-cause/tier5-src/himi-blog-saved/index.ts +97 -39
  90. package/templates/nonprofit-cause-owner/dev/index.ts +7 -0
  91. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-contract.ts +0 -1
  92. package/templates/owner-lite/dev/index.ts +7 -0
  93. package/templates/owner-lite/tier5-src/_shared/collection-contract.ts +0 -1
  94. package/templates/podcast-creator/config.ts +1 -1
  95. package/templates/podcast-creator/dev/index.ts +2862 -3058
  96. package/templates/podcast-creator/tier5-src/_shared/collection-contract.ts +0 -1
  97. package/templates/podcast-creator/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  98. package/templates/podcast-creator/tier5-src/_shared/himi-blog-saved.ts +0 -10
  99. package/templates/podcast-creator/tier5-src/himi-blog-feed/index.ts +220 -95
  100. package/templates/podcast-creator/tier5-src/himi-blog-post/index.ts +436 -140
  101. package/templates/podcast-creator/tier5-src/himi-blog-saved/index.ts +97 -39
  102. package/templates/podcast-creator-owner/dev/index.ts +7 -0
  103. package/templates/podcast-creator-owner/tier5-src/_shared/collection-contract.ts +0 -1
  104. package/templates/portfolio-creative/config.ts +1 -1
  105. package/templates/portfolio-creative/dev/index.ts +2803 -2999
  106. package/templates/portfolio-creative/tier5-src/_shared/collection-contract.ts +0 -1
  107. package/templates/portfolio-creative/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  108. package/templates/portfolio-creative/tier5-src/_shared/himi-blog-saved.ts +0 -10
  109. package/templates/portfolio-creative/tier5-src/himi-blog-feed/index.ts +220 -95
  110. package/templates/portfolio-creative/tier5-src/himi-blog-post/index.ts +436 -140
  111. package/templates/portfolio-creative/tier5-src/himi-blog-saved/index.ts +97 -39
  112. package/templates/portfolio-creative-owner/dev/index.ts +7 -0
  113. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-contract.ts +0 -1
  114. package/templates/restaurant/config.ts +1 -1
  115. package/templates/restaurant/dev/index.ts +2845 -3041
  116. package/templates/restaurant/tier5-src/_shared/collection-contract.ts +0 -1
  117. package/templates/restaurant/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  118. package/templates/restaurant/tier5-src/_shared/himi-blog-saved.ts +0 -10
  119. package/templates/restaurant/tier5-src/himi-blog-feed/index.ts +220 -95
  120. package/templates/restaurant/tier5-src/himi-blog-post/index.ts +436 -140
  121. package/templates/restaurant/tier5-src/himi-blog-saved/index.ts +97 -39
  122. package/templates/restaurant-owner/dev/index.ts +7 -0
  123. package/templates/restaurant-owner/tier5-src/_shared/collection-contract.ts +0 -1
  124. package/templates/retail-store/config.ts +1 -1
  125. package/templates/retail-store/dev/index.ts +2809 -3005
  126. package/templates/retail-store/tier5-src/_shared/collection-contract.ts +0 -1
  127. package/templates/retail-store/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  128. package/templates/retail-store/tier5-src/_shared/himi-blog-saved.ts +0 -10
  129. package/templates/retail-store/tier5-src/himi-blog-feed/index.ts +220 -95
  130. package/templates/retail-store/tier5-src/himi-blog-post/index.ts +436 -140
  131. package/templates/retail-store/tier5-src/himi-blog-saved/index.ts +97 -39
  132. package/templates/retail-store-owner/dev/index.ts +7 -0
  133. package/templates/retail-store-owner/tier5-src/_shared/collection-contract.ts +0 -1
  134. package/templates/salon-spa/tier5-src/_shared/collection-contract.ts +0 -1
  135. package/templates/yoga-studio/config.ts +1 -1
  136. package/templates/yoga-studio/dev/index.ts +2752 -2948
  137. package/templates/yoga-studio/tier5-src/_shared/collection-contract.ts +0 -1
  138. package/templates/yoga-studio/tier5-src/_shared/himi-blog-post-row.ts +210 -0
  139. package/templates/yoga-studio/tier5-src/_shared/himi-blog-saved.ts +0 -10
  140. package/templates/yoga-studio/tier5-src/himi-blog-feed/index.ts +220 -95
  141. package/templates/yoga-studio/tier5-src/himi-blog-post/index.ts +436 -140
  142. package/templates/yoga-studio/tier5-src/himi-blog-saved/index.ts +97 -39
  143. package/templates/yoga-studio-owner/dev/index.ts +7 -0
  144. package/templates/yoga-studio-owner/tier5-src/_shared/collection-contract.ts +0 -1
  145. package/templates/beauty-salon/tier5-src/_shared/himi-blog-collection.ts +0 -7
  146. package/templates/branded-lite/tier5-src/_shared/himi-blog-collection.ts +0 -7
  147. package/templates/community-club/tier5-src/_shared/himi-blog-collection.ts +0 -7
  148. package/templates/events-meetups/tier5-src/_shared/himi-blog-collection.ts +0 -7
  149. package/templates/gym-fitness/tier5-src/_shared/himi-blog-collection.ts +0 -7
  150. package/templates/nonprofit-cause/tier5-src/_shared/himi-blog-collection.ts +0 -7
  151. package/templates/podcast-creator/tier5-src/_shared/himi-blog-collection.ts +0 -7
  152. package/templates/portfolio-creative/tier5-src/_shared/himi-blog-collection.ts +0 -7
  153. package/templates/restaurant/tier5-src/_shared/himi-blog-collection.ts +0 -7
  154. package/templates/retail-store/tier5-src/_shared/himi-blog-collection.ts +0 -7
  155. package/templates/yoga-studio/tier5-src/_shared/himi-blog-collection.ts +0 -7
@@ -1,10 +1,14 @@
1
1
  // Tier-5 bundle: Himi Blog feed - public reader list/search/category browsing.
2
- import { defineService } from "../_shared/himi-blog-collection.js";
3
- import { queryCategories, queryPosts, type WixPost } from "@himalaya/wix-blog";
4
- import { stashCopy, copyParam } from "../_shared/himi-copy.js";
2
+ //
3
+ // The feed draws its own layout (one card per post: photo, author, title, excerpt, counts), so
4
+ // it is NOT a shared collection: no List/Grid toggle, no Refine, no "Saved" chip. Saved posts
5
+ // live on their own screen (himi_saved).
6
+ import { defineService } from "@himalaya/state";
7
+ import { queryCategories, queryPosts, type WixPost, type WixQueryPostsRequest } from "@himalaya/wix-blog";
8
+ import { stashCopy, copyParam, copyPlural } from "../_shared/himi-copy.js";
5
9
  import { getAll, upsert, type DbEntity } from "@himalaya/local-db";
6
- import { formatDateMedium } from "../_shared/engine-intl.js";
7
10
  import { withoutHidden } from "../_shared/himi-blog-hidden.js";
11
+ import { authorFields, BLOG_CARD_IMAGE, countLabels, countsOf, coverOf, dateLineOf, dateOf, cachedCover, coverSourceOf, legacyRowFixes, LIST_FIELDSETS, NO_AUTHOR, resolveAuthors, type AuthorFields, type BlogPostShape, type CountLabels } from "../_shared/himi-blog-post-row.js";
8
12
 
9
13
  const PAGE_SIZE = 20;
10
14
 
@@ -13,17 +17,33 @@ interface CategoryRow {
13
17
  label: string;
14
18
  }
15
19
 
16
- interface PostRow {
20
+ interface PostRow extends AuthorFields, CountLabels {
17
21
  id: string;
18
22
  title: string;
19
23
  excerpt: string;
20
24
  category: string;
21
25
  categoryId: string;
26
+ /** Every category the post is filed under: a chip matches any of them, not only the first. */
27
+ categoryIds: string[];
28
+ /** "Jul 30, 2026 · 4 min read". */
22
29
  meta: string;
23
- counts: string;
30
+ /** The publish date alone (Saved reads it from the cached row). */
31
+ date: string;
32
+ likes: string;
33
+ views: string;
34
+ comments: string;
35
+ /** The row carries the site's counts. A row cached by an older build has none, and shows no
36
+ * counts row rather than invented zeros. */
37
+ hasCounts: boolean;
38
+ noCounts: boolean;
24
39
  cover: string;
40
+ /** The photo as stored (unsized), cached so an offline post or Saved row sizes it for itself. */
41
+ coverSource: string;
25
42
  hasCover: boolean;
26
43
  noCover: boolean;
44
+ pinned: boolean;
45
+ notPinned: boolean;
46
+ memberId: string;
27
47
  initial: string;
28
48
  detailScreenId: string;
29
49
  }
@@ -32,15 +52,25 @@ interface S {
32
52
  status: "loading" | "ready" | "error";
33
53
  query: string;
34
54
  selectedCategoryId: string;
55
+ /** All + each category that has posts. */
35
56
  categories: CategoryRow[];
57
+ /** The chips' selection: one id ("" = All). */
58
+ selectedCategoryIds: string[];
59
+ hideCategories: boolean;
60
+ /** The pinned-posts read failed: the feed shows the newest posts without them first. */
61
+ pinnedUnavailable: boolean;
36
62
  allPosts: PostRow[];
37
63
  posts: PostRow[];
38
64
  offset: number;
39
65
  total: number;
40
66
  hasMore: boolean;
41
67
  noMore: boolean;
42
- /** RFC 0008 scroll load-more — the offset as a synthetic cursor ("" ⇒ exhausted). */
68
+ /** RFC 0008 scroll load-more — `generation:offset` as a synthetic cursor ("" ⇒ exhausted). */
43
69
  nextCursor: string;
70
+ /** One more each time a new list lands (load, retry, chip, clear). In the cursor, so a list that
71
+ * replaced one whose page was claimed never republishes that claimed cursor ("0:20" twice): the
72
+ * host pages only on a cursor it has not claimed, so the new list would never load page 2. */
73
+ generation: number;
44
74
  emptyText: string;
45
75
  errorText: string;
46
76
  isLoading: boolean;
@@ -52,13 +82,7 @@ interface S {
52
82
  resultSummary: string;
53
83
  }
54
84
 
55
- type PostWithExtras = WixPost & {
56
- categoryIds?: string[];
57
- media?: { wixMedia?: { image?: { url?: string } }; embedMedia?: { thumbnail?: { url?: string } } };
58
- coverImage?: { image?: { url?: string }; url?: string };
59
- metrics?: { likeCount?: number; totalComments?: number; commentCount?: number };
60
- memberInteraction?: { liked?: boolean };
61
- };
85
+ type PostWithExtras = WixPost & BlogPostShape;
62
86
 
63
87
  // Offline-first (data-offline): the reader feed is public read-through — paint the
64
88
  // last-synced posts from the on-device store first (instant, works offline), then
@@ -68,7 +92,14 @@ type PostWithExtras = WixPost & {
68
92
  // online-only path — the capability fails closed per-entity.
69
93
  const ENTITY = "blog_posts";
70
94
  async function readCachedPosts(): Promise<PostRow[]> {
71
- try { return (await getAll(ENTITY)) as unknown as PostRow[]; } catch { return []; }
95
+ try {
96
+ // A row cached by an older build has no author or count fields. An unset gate fails open
97
+ // and paints an empty author row, so it reads as "no author" until the network refresh.
98
+ return ((await getAll(ENTITY)) as unknown as Array<Partial<PostRow>>).map((row): PostRow => {
99
+ const cover = cachedCover(row, BLOG_CARD_IMAGE);
100
+ return { ...NO_AUTHOR, likes: "", views: "", comments: "", likesLabel: "", viewsLabel: "", commentsLabel: "", hasCounts: false, noCounts: true, pinned: false, notPinned: true, memberId: "", date: "", coverSource: "", ...row, ...legacyRowFixes(row), cover, hasCover: !!cover, noCover: !cover, categoryIds: row.categoryIds ?? (row.categoryId ? [row.categoryId] : []) } as PostRow;
101
+ });
102
+ } catch { return []; }
72
103
  }
73
104
  async function writeCachedPosts(rows: PostRow[]): Promise<void> {
74
105
  try { for (const r of rows) await upsert(ENTITY, r as unknown as DbEntity); } catch { /* capability not granted → online-only */ }
@@ -80,54 +111,51 @@ function strOf(arg: unknown): string {
80
111
  return a?.value ?? a?.text ?? a?.query ?? "";
81
112
  }
82
113
 
114
+ /** The chip the reader picked. FilterChips sends `{ selectedIds }` (an empty list when the
115
+ * selected chip is tapped again, which reads as All). The string / `{ categoryId }` arms are
116
+ * the older direct callers. */
83
117
  function categoryIdOf(arg: unknown): string {
84
118
  if (typeof arg === "string") return arg;
85
- const a = arg as { categoryId?: string; id?: string } | undefined;
119
+ const a = arg as { categoryId?: string; id?: string; selectedIds?: unknown; args?: { selectedIds?: unknown } } | undefined;
120
+ const ids = a?.selectedIds ?? a?.args?.selectedIds;
121
+ if (Array.isArray(ids)) return typeof ids[0] === "string" ? ids[0] : "";
86
122
  return a?.categoryId ?? a?.id ?? "";
87
123
  }
88
124
 
89
- function imageUrl(post: PostWithExtras): string {
90
- return (
91
- post.media?.wixMedia?.image?.url ??
92
- post.media?.embedMedia?.thumbnail?.url ??
93
- post.coverImage?.image?.url ??
94
- post.coverImage?.url ??
95
- ""
96
- );
97
- }
98
-
99
- function countsLine(post: PostWithExtras): string {
100
- const likes = post.metrics?.likeCount ?? 0;
101
- const comments = post.metrics?.totalComments ?? post.metrics?.commentCount ?? 0;
102
- if (!likes && !comments) return "";
103
- return `${likes} likes · ${comments} comments`;
104
- }
105
-
106
- function metaLine(post: WixPost): string {
107
- const bits: string[] = [];
108
- if (post.firstPublishedDate) {
109
- bits.push(formatDateMedium(new Date(post.firstPublishedDate)));
110
- }
111
- if (post.minutesToRead) bits.push(`${post.minutesToRead} min read`);
112
- return bits.join(" · ");
113
- }
114
-
115
125
  function normalize(post: WixPost, categoryMap: Map<string, string>): PostRow {
116
126
  const richPost = post as PostWithExtras;
117
- const title = post.title || "Untitled post";
118
- const categoryId = richPost.categoryIds?.[0] ?? "";
119
- const cover = imageUrl(richPost);
127
+ const title = post.title || copyParam("blogCommon.untitled", "Untitled post");
128
+ const categoryId = (richPost.categoryIds ?? []).find((id) => categoryMap.has(id)) ?? richPost.categoryIds?.[0] ?? "";
129
+ // No id, no label: the map never names "" (that is the All chip, not a category).
130
+ const category = categoryId ? categoryMap.get(categoryId) ?? "" : "";
131
+ const cover = coverOf(richPost);
132
+ const counts = countsOf(richPost);
120
133
  return {
134
+ ...NO_AUTHOR,
121
135
  id: post.id,
122
136
  title,
123
- excerpt: (post.excerpt || copyParam("blog.excerptFallback", "Open to read the full note.")).trim(),
124
- category: categoryId ? categoryMap.get(categoryId) ?? "Blog" : "Blog",
137
+ // No invented filler: a post with no excerpt shows none.
138
+ excerpt: (post.excerpt ?? "").trim(),
139
+ // A post with no category has none: no "Blog" stand-in, and so no chip for it either.
140
+ category,
125
141
  categoryId,
126
- meta: metaLine(post),
127
- counts: countsLine(richPost),
142
+ categoryIds: (richPost.categoryIds ?? []).filter((id) => typeof id === "string" && id),
143
+ meta: dateLineOf(richPost),
144
+ date: dateOf(richPost),
145
+ // Unknown counts (a read without METRICS) show no counts row: never invented zeros.
146
+ likes: counts ? String(counts.likes) : "",
147
+ views: counts ? String(counts.views) : "",
148
+ comments: counts ? String(counts.comments) : "",
149
+ ...countLabels(counts),
150
+ hasCounts: !!counts,
151
+ noCounts: !counts,
128
152
  cover,
153
+ coverSource: coverSourceOf(richPost),
129
154
  hasCover: Boolean(cover),
130
155
  noCover: !cover,
156
+ pinned: richPost.pinned === true,
157
+ notPinned: richPost.pinned !== true,
158
+ memberId: richPost.memberId ?? "",
131
159
  initial: (title[0] || "#").toUpperCase(),
132
160
  // WS-C — canonical param-less detail screenId; the descriptor row binds the
133
161
  // separate `id` field as a first-class nav param. This also dissolves the
@@ -136,16 +164,29 @@ function normalize(post: WixPost, categoryMap: Map<string, string>): PostRow {
136
164
  };
137
165
  }
138
166
 
167
+ async function withAuthors(rows: PostRow[]): Promise<PostRow[]> {
168
+ const authors = await resolveAuthors(rows.map((row) => row.memberId));
169
+ return rows.map((row) => ({ ...row, ...authorFields(authors.get(row.memberId)) }));
170
+ }
171
+
172
+ /** Pinned posts first; otherwise the site's own order (newest first). */
173
+ function pinnedFirst(rows: PostRow[]): PostRow[] {
174
+ return [...rows.filter((row) => row.pinned), ...rows.filter((row) => !row.pinned)];
175
+ }
176
+
139
177
  function applyFilters(s: S): S {
140
178
  const needle = s.query.trim().toLowerCase();
141
179
  // Posts this device's reader hid (on the post screen) never show, whatever the cache or the live page holds.
142
- const posts = withoutHidden(s.allPosts).filter((post) => {
143
- const categoryOk = !s.selectedCategoryId || post.categoryId === s.selectedCategoryId;
180
+ // Pinned posts lead All only: a category shows its own posts in date order.
181
+ const visible = withoutHidden(s.allPosts);
182
+ const posts = (s.selectedCategoryId ? visible : pinnedFirst(visible)).filter((post) => {
183
+ const categoryOk = !s.selectedCategoryId || post.categoryIds.includes(s.selectedCategoryId);
144
184
  const queryOk =
145
185
  !needle ||
146
186
  post.title.toLowerCase().includes(needle) ||
147
187
  post.excerpt.toLowerCase().includes(needle) ||
148
- post.category.toLowerCase().includes(needle);
188
+ post.category.toLowerCase().includes(needle) ||
189
+ post.authorName.toLowerCase().includes(needle);
149
190
  return categoryOk && queryOk;
150
191
  });
151
192
  return derive({
@@ -156,7 +197,7 @@ function applyFilters(s: S): S {
156
197
  : needle || s.selectedCategoryId
157
198
  ? copyParam("blog.noMatchText", "No matching posts")
158
199
  : copyParam("blog.emptyText", "No blog posts yet"),
159
- resultSummary: posts.length === 1 ? "1 post" : `${posts.length} posts`,
200
+ resultSummary: copyPlural("blog.resultSummary", "{n, plural, one {# post} other {# posts}}", posts.length),
160
201
  });
161
202
  }
162
203
 
@@ -166,6 +207,13 @@ function derive(s: S): S {
166
207
  const isEmpty = !isLoading && !errored && s.posts.length === 0;
167
208
  return {
168
209
  ...s,
210
+ selectedCategoryIds: [s.selectedCategoryId],
211
+ // No real category, or one that every loaded post is in, is no choice at all: All already
212
+ // shows the same posts. One category beside uncategorized posts still narrows the list.
213
+ // While a category is selected the chips always stay: they are the way back to All. While
214
+ // more pages are to come, a later page may hold an uncategorized post, so they stay too.
215
+ hideCategories: !s.selectedCategoryId && (s.categories.length <= 1
216
+ || (s.categories.length === 2 && !s.hasMore && s.allPosts.every((post) => post.categoryIds.includes(s.categories[1]!.id)))),
169
217
  isLoading,
170
218
  notLoading: !isLoading,
171
219
  errored,
@@ -173,43 +221,47 @@ function derive(s: S): S {
173
221
  isEmpty,
174
222
  noEmpty: !isEmpty,
175
223
  noMore: !s.hasMore,
176
- nextCursor: s.hasMore ? String(s.offset) : "",
224
+ nextCursor: s.hasMore ? `${s.generation}:${s.offset}` : "",
177
225
  };
178
226
  }
179
227
 
180
- async function loadCategories(): Promise<{ rows: CategoryRow[]; map: Map<string, string> }> {
181
- const fallback = { rows: [{ id: "", label: "All" }], map: new Map<string, string>() };
228
+ const allChip = (): CategoryRow => ({ id: "", label: copyParam("collection.all", "All") });
229
+
230
+ async function loadCategories(): Promise<{ rows: CategoryRow[]; map: Map<string, string>; failed?: true }> {
182
231
  try {
183
232
  const result = await queryCategories({ paging: { limit: 100 } });
184
- const rows: CategoryRow[] = [{ id: "", label: "All" }];
233
+ const rows: CategoryRow[] = [allChip()];
185
234
  const map = new Map<string, string>();
186
235
  for (const category of result.categories ?? []) {
187
- const label = (category.label || category.title || "Category").trim();
188
- if (category.id) {
189
- rows.push({ id: category.id, label });
190
- map.set(category.id, label);
191
- }
236
+ const label = (category.label || category.title || "").trim();
237
+ if (!category.id || !label) continue;
238
+ map.set(category.id, label);
239
+ // A category with no published post is a chip that always shows "No matching posts".
240
+ // `postCount` absent (an older payload) keeps the chip rather than guessing.
241
+ if (category.postCount === undefined || category.postCount > 0) rows.push({ id: category.id, label });
192
242
  }
193
243
  return { rows, map };
194
244
  } catch {
195
- return fallback;
245
+ return { rows: [allChip()], map: new Map<string, string>(), failed: true };
196
246
  }
197
247
  }
198
248
 
199
- async function loadPosts(offset: number, categoryMap: Map<string, string>): Promise<{ rows: PostRow[]; total: number; nextOffset: number; hasMore: boolean }> {
249
+ /** The category labels by id, from the chips (All, id "", is not a category). */
250
+ const labelsOf = (s: S): Map<string, string> => new Map(s.categories.filter((category) => category.id).map((category) => [category.id, category.label]));
251
+
252
+ /** One page of posts, newest first; with `categoryId`, that category's posts only, read on the
253
+ * server so a category whose posts fall on a later page still finds them. */
254
+ async function loadPosts(offset: number, categoryMap: Map<string, string>, categoryId = ""): Promise<{ rows: PostRow[]; total: number; nextOffset: number; hasMore: boolean }> {
255
+ const paging = { limit: PAGE_SIZE, offset };
256
+ const filter = categoryId ? { filter: { categoryIds: { $hasSome: [categoryId] } } } : {};
200
257
  let result;
201
258
  try {
202
- result = await queryPosts({
203
- query: {
204
- paging: { limit: PAGE_SIZE, offset },
205
- sort: [{ fieldName: "firstPublishedDate", order: "DESC" }],
206
- },
207
- });
259
+ result = await queryPosts({ query: { ...filter, paging, sort: [{ fieldName: "firstPublishedDate", order: "DESC" }] }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest);
208
260
  } catch {
209
- result = await queryPosts({ query: { paging: { limit: PAGE_SIZE, offset } } });
261
+ result = await queryPosts({ query: { ...filter, paging }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest);
210
262
  }
211
263
  const rawPosts = result.posts ?? [];
212
- const rows = rawPosts.map((post) => normalize(post, categoryMap));
264
+ const rows = await withAuthors(rawPosts.map((post) => normalize(post, categoryMap)));
213
265
  const total = result.pagingMetadata?.total ?? offset + rows.length;
214
266
  const nextOffset = offset + rows.length;
215
267
  return { rows, total, nextOffset, hasMore: nextOffset < total };
@@ -220,6 +272,9 @@ const baseState: S = derive({
220
272
  query: "",
221
273
  selectedCategoryId: "",
222
274
  categories: [{ id: "", label: "All" }],
275
+ selectedCategoryIds: [""],
276
+ hideCategories: true,
277
+ pinnedUnavailable: false,
223
278
  allPosts: [],
224
279
  posts: [],
225
280
  offset: 0,
@@ -227,6 +282,7 @@ const baseState: S = derive({
227
282
  hasMore: false,
228
283
  noMore: true,
229
284
  nextCursor: "",
285
+ generation: 0,
230
286
  emptyText: "",
231
287
  errorText: "",
232
288
  isLoading: true,
@@ -238,6 +294,19 @@ const baseState: S = derive({
238
294
  resultSummary: "",
239
295
  });
240
296
 
297
+ /** The site's pinned posts, whatever page they would fall on by date: they lead the feed. */
298
+ async function loadPinned(categoryMap: Map<string, string>): Promise<PostRow[]> {
299
+ const result = await queryPosts({ query: { filter: { pinned: true }, paging: { limit: PAGE_SIZE } }, fieldsets: LIST_FIELDSETS } as WixQueryPostsRequest);
300
+ // Only rows that say they are pinned: a source that ignores the filter cannot reorder the feed.
301
+ return withAuthors((result.posts ?? []).map((post) => normalize(post, categoryMap)).filter((row) => row.pinned));
302
+ }
303
+
304
+ /** `rows` without the posts `kept` already holds (a pinned post also arrives on its date's page). */
305
+ function withoutKnown(rows: PostRow[], kept: PostRow[]): PostRow[] {
306
+ const known = new Set(kept.map((row) => row.id));
307
+ return rows.filter((row) => !known.has(row.id));
308
+ }
309
+
241
310
  async function loadFeedState(s: S): Promise<S> {
242
311
  // 1) Instant paint from the on-device cache (offline-safe; empty on first-ever run).
243
312
  const cached = await readCachedPosts();
@@ -246,52 +315,106 @@ async function loadFeedState(s: S): Promise<S> {
246
315
  : s;
247
316
  // 2) Revalidate from Wix and refresh the cache.
248
317
  try {
249
- const categories = await loadCategories();
250
- const page = await loadPosts(0, categories.map);
251
- await writeCachedPosts(page.rows);
318
+ const read = await loadCategories();
319
+ // A failed categories read keeps the chips already known (and so the selection): only a
320
+ // category the site answered without is gone, and cannot stay selected.
321
+ const categories = read.failed && s.categories.length > 1 ? { rows: s.categories, map: labelsOf(s) } : read;
322
+ const selectedCategoryId = categories.rows.some((row) => row.id === s.selectedCategoryId) ? s.selectedCategoryId : "";
323
+ const page = await loadPosts(0, categories.map, selectedCategoryId);
324
+ // A failed pinned read is recorded, not taken for "no pinned posts". Pinned posts lead All;
325
+ // a category shows its own posts in date order.
326
+ let pinned: PostRow[] = [];
327
+ let pinnedUnavailable = false;
328
+ if (!selectedCategoryId) {
329
+ try { pinned = await loadPinned(categories.map); } catch { pinnedUnavailable = true; }
330
+ }
331
+ const rows = [...pinned, ...withoutKnown(page.rows, pinned)];
332
+ await writeCachedPosts(rows);
252
333
  return applyFilters({
253
334
  ...base,
254
335
  status: "ready",
255
336
  categories: categories.rows,
256
- allPosts: page.rows,
257
- posts: page.rows,
337
+ selectedCategoryId,
338
+ pinnedUnavailable,
339
+ allPosts: rows,
340
+ posts: rows,
258
341
  offset: page.nextOffset,
259
342
  total: page.total,
260
343
  hasMore: page.hasMore,
261
344
  errorText: "",
262
345
  });
263
346
  } catch {
264
- // Offline / fetch failure: keep the cached rows instead of a blank error state.
347
+ // Offline / fetch failure: keep the cached rows instead of a blank error state. No paging
348
+ // from them: the offset belongs to whatever list was read before (another chip, maybe), so a
349
+ // later page would skip this list's first posts. Retry or pull-to-refresh reads page 1.
265
350
  return cached.length
266
- ? base
267
- : derive({ ...s, status: "error", errorText: copyParam("blog.errorText", "Blog posts are unavailable. Try again.") });
351
+ ? derive({ ...base, hasMore: false })
352
+ : derive({ ...s, status: "error", hasMore: false, errorText: copyParam("blog.errorText", "Blog posts are unavailable. Try again.") });
268
353
  }
269
354
  }
270
355
 
356
+ // The reads are async and the runtime keeps whichever result resolves LAST, so a slower answer to
357
+ // an earlier tap (chip A, then chip B; a chip, then a search) would put the older choice back.
358
+ // Every action that changes which posts are READ (load, retry, chip, clear) takes a new version;
359
+ // an async result whose version is no longer current is dropped (undefined keeps the state the
360
+ // newer action set). Search only filters what is loaded, so it does not drop a read in flight
361
+ // (a first load would then never land): the reader's latest search text is applied to the
362
+ // result instead.
363
+ // `shownVersion` is the version of the list on screen: while a newer read is in flight the two
364
+ // differ, and loadMore waits (a page of the old list would land on top of the new one). A chip tap
365
+ // is compared with the latest tap (`wantedCategoryId`), not with the chip on screen, so tapping
366
+ // back to it while another chip's read is in flight still wins.
367
+ let feedVersion = 0;
368
+ let shownVersion = 0;
369
+ let searchText = "";
370
+ let wantedCategoryId = "";
371
+ async function current(version: number, next: Promise<S>): Promise<S | undefined> {
372
+ const s = await next;
373
+ if (version !== feedVersion) return undefined;
374
+ shownVersion = version;
375
+ wantedCategoryId = s.selectedCategoryId;
376
+ return applyFilters({ ...s, query: searchText, generation: s.generation + 1 });
377
+ }
378
+
271
379
  const svc = defineService<S, {
272
- load: (s: S, arg?: unknown) => Promise<S>;
273
- retry: (s: S) => Promise<S>;
380
+ load: (s: S, arg?: unknown) => Promise<S | undefined>;
381
+ retry: (s: S) => Promise<S | undefined>;
274
382
  search: (s: S, arg?: unknown) => S;
275
- selectCategory: (s: S, arg?: unknown) => S;
276
- clearFilters: (s: S) => S;
277
- loadMore: (s: S) => Promise<S>;
383
+ /** A chip: that category's posts, read on the server (from the first page). */
384
+ selectCategory: (s: S, arg?: unknown) => Promise<S | undefined>;
385
+ clearFilters: (s: S) => Promise<S | undefined>;
386
+ loadMore: (s: S) => Promise<S | undefined>;
278
387
  }>("himiBlogFeed", {
279
388
  state: baseState,
280
389
  actions: {
281
- load: (s, arg) => { stashCopy(arg); return loadFeedState(s); },
282
- retry: (s) => loadFeedState({ ...s, status: "loading", errorText: "" }),
283
- search: (s, arg) => applyFilters({ ...s, query: strOf(arg) }),
284
- selectCategory: (s, arg) => applyFilters({ ...s, selectedCategoryId: categoryIdOf(arg) }),
285
- clearFilters: (s) => applyFilters({ ...s, query: "", selectedCategoryId: "" }),
390
+ // Both read the last chip tapped, not the one on screen: a tap whose read is still in flight is kept.
391
+ load: (s, arg) => { stashCopy(arg); return current(++feedVersion, loadFeedState({ ...s, selectedCategoryId: wantedCategoryId })); },
392
+ retry: (s) => current(++feedVersion, loadFeedState({ ...s, selectedCategoryId: wantedCategoryId, status: "loading", errorText: "" })),
393
+ search: (s, arg) => { searchText = strOf(arg); return applyFilters({ ...s, query: searchText }); },
394
+ selectCategory: (s, arg) => {
395
+ const selectedCategoryId = categoryIdOf(arg);
396
+ if (selectedCategoryId === wantedCategoryId) return Promise.resolve(s);
397
+ wantedCategoryId = selectedCategoryId;
398
+ return current(++feedVersion, loadFeedState(applyFilters({ ...s, selectedCategoryId })));
399
+ },
400
+ clearFilters: (s) => { searchText = ""; wantedCategoryId = ""; return current(++feedVersion, loadFeedState(applyFilters({ ...s, query: "", selectedCategoryId: "" }))); },
286
401
  loadMore: async (s) => {
287
- if (!s.hasMore || s.status === "loading") return s;
402
+ // Not while a newer read is in flight: s is the old list, and its next page would replace
403
+ // the new one when it lands.
404
+ if (!s.hasMore || s.status === "loading" || shownVersion !== feedVersion) return s;
405
+ // A page that lands after a newer chip or reload belongs to the old list: dropped. A search
406
+ // made while it loaded is applied to it.
407
+ const version = feedVersion;
288
408
  try {
289
- const categoryMap = new Map(s.categories.map((category) => [category.id, category.label]));
290
- const page = await loadPosts(s.offset, categoryMap);
291
- const allPosts = [...s.allPosts, ...page.rows];
409
+ const page = await loadPosts(s.offset, labelsOf(s), s.selectedCategoryId);
410
+ if (version !== feedVersion) return undefined;
411
+ const allPosts = [...s.allPosts, ...withoutKnown(page.rows, s.allPosts)];
292
412
  await writeCachedPosts(allPosts);
413
+ // Again after the cache write: a chip or reload that landed during it is newer.
414
+ if (version !== feedVersion) return undefined;
293
415
  return applyFilters({
294
416
  ...s,
417
+ query: searchText,
295
418
  status: "ready",
296
419
  allPosts,
297
420
  offset: page.nextOffset,
@@ -300,7 +423,9 @@ const svc = defineService<S, {
300
423
  errorText: "",
301
424
  });
302
425
  } catch {
303
- return derive({ ...s, errorText: copyParam("blog.loadMoreErrorText", "More posts could not load.") });
426
+ if (version !== feedVersion) return undefined;
427
+ // A search typed while the page loaded stays applied.
428
+ return applyFilters({ ...s, query: searchText, errorText: copyParam("blog.loadMoreErrorText", "More posts could not load.") });
304
429
  }
305
430
  },
306
431
  },