@wix/himalaya-cli 0.2051.0 → 0.2052.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/stores-v1/src/display.d.ts +7 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-stores.mjs +1 -1
- package/dist/cli.mjs +1 -2
- package/guides/sdk-reference.json +1 -1
- package/package.json +2 -2
- package/templates/beauty-salon/l10n/he.json +4 -0
- package/templates/beauty-salon/tier5-src/_shared/himi-store-search.ts +77 -0
- package/templates/beauty-salon/tier5-src/himi-branded-lite-category/index.ts +22 -8
- package/templates/branded-lite/l10n/he.json +4 -0
- package/templates/branded-lite/tier5-src/_shared/himi-store-search.ts +77 -0
- package/templates/branded-lite/tier5-src/himi-branded-lite-category/index.ts +22 -8
- package/templates/branded-lite/tier5-src/himi-branded-lite-shop/index.ts +31 -14
- package/templates/gym-fitness/l10n/he.json +4 -0
- package/templates/gym-fitness/tier5-src/_shared/himi-store-search.ts +77 -0
- package/templates/gym-fitness/tier5-src/himi-branded-lite-category/index.ts +22 -8
- package/templates/portfolio-creative/l10n/he.json +4 -0
- package/templates/portfolio-creative/tier5-src/_shared/himi-store-search.ts +77 -0
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-category/index.ts +22 -8
- package/templates/retail-store/l10n/he.json +4 -0
- package/templates/retail-store/tier5-src/_shared/himi-store-search.ts +77 -0
- package/templates/retail-store/tier5-src/himi-branded-lite-category/index.ts +22 -8
- package/templates/retail-store/tier5-src/himi-branded-lite-shop/index.ts +31 -14
|
@@ -147,6 +147,13 @@ export interface StoreProductSearch {
|
|
|
147
147
|
* `collections.id`.
|
|
148
148
|
*/
|
|
149
149
|
categoryId?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Match `query` in every field Wix Search Products searches (name, description, …), as the
|
|
152
|
+
* Wix store's own search does, instead of the name alone. Either way any word of the query
|
|
153
|
+
* matches (Wix's default OR mode) and the answer comes in relevance order. V3 only: V1 has
|
|
154
|
+
* no search engine, so its `name` `$contains` filter stays the whole match.
|
|
155
|
+
*/
|
|
156
|
+
searchAllFields?: boolean;
|
|
150
157
|
limit?: number;
|
|
151
158
|
cursor?: string;
|
|
152
159
|
/** Extra v3 fieldsets. Additive — widens the default, never replaces it. */
|
|
@@ -419,7 +419,7 @@ async function searchStoreProducts(options = {}, readOptions) {
|
|
|
419
419
|
const criteria = {
|
|
420
420
|
cursorPaging: { limit, ...options.cursor ? { cursor: options.cursor } : {} },
|
|
421
421
|
...Object.keys(filter).length ? { filter } : {},
|
|
422
|
-
...query ? { search: { expression: query, fields: ["name"] } } : {},
|
|
422
|
+
...query ? { search: { expression: query, ...options.searchAllFields ? {} : { fields: ["name"] } } } : {},
|
|
423
423
|
...sorted ? { sort: [{ fieldName: "name", order: ascending ? "ASC" : "DESC" }] } : {}
|
|
424
424
|
};
|
|
425
425
|
return wixCall("POST", `/stores/v3/products/${search ? "search" : "query"}`, {
|
package/dist/cli.mjs
CHANGED
|
@@ -20300,7 +20300,6 @@ function buttonVariant(style) {
|
|
|
20300
20300
|
var SYSTEM_FONT_FAMILY, TONAL_ELEVATION_ALPHA, BUTTON_SIZES, BUTTON_MIN_HIT_TARGET, nonNegative, nonEmpty2, own2, COLOR_TOKEN_PROPS, TYPOGRAPHY_TOKEN_PROPS, BUTTON_VARIANTS;
|
|
20301
20301
|
var init_tokens = __esm({
|
|
20302
20302
|
"../../core/ts/src/tokens.ts"() {
|
|
20303
|
-
"use strict";
|
|
20304
20303
|
init_define_HHP_CATALOG();
|
|
20305
20304
|
SYSTEM_FONT_FAMILY = "$system";
|
|
20306
20305
|
TONAL_ELEVATION_ALPHA = [0, 0.05, 0.08, 0.11, 0.12, 0.14];
|
|
@@ -46686,7 +46685,6 @@ function resolveIdiom(tokens2, ctx = {}) {
|
|
|
46686
46685
|
var IDIOM_CONTEXTS, UNSAFE_KEYS;
|
|
46687
46686
|
var init_idiom = __esm({
|
|
46688
46687
|
"../../core/ts/src/idiom.ts"() {
|
|
46689
|
-
"use strict";
|
|
46690
46688
|
init_define_HHP_CATALOG();
|
|
46691
46689
|
IDIOM_CONTEXTS = {
|
|
46692
46690
|
ios: { native: ["ios"] },
|
|
@@ -48456,6 +48454,7 @@ function shouldRevealError(args) {
|
|
|
48456
48454
|
var EMAIL_RE, URL_HOST_RE, INTEGER_RE, NUMBER_RE, AUTHORED_PATTERN_LIMIT, authoredPatterns;
|
|
48457
48455
|
var init_validation = __esm({
|
|
48458
48456
|
"../../core/ts/src/validation.ts"() {
|
|
48457
|
+
"use strict";
|
|
48459
48458
|
init_define_HHP_CATALOG();
|
|
48460
48459
|
EMAIL_RE = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/;
|
|
48461
48460
|
URL_HOST_RE = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(:[0-9]+)?$/;
|
|
@@ -37523,7 +37523,7 @@
|
|
|
37523
37523
|
"name": "StoreProductSearch",
|
|
37524
37524
|
"kind": "interface",
|
|
37525
37525
|
"jsdoc": "/** User-facing product discovery. V3 name search/sorting belong to Search\n * Products; Query Products deliberately does not support the name field.\n * V1 uses its documented JSON-string filter/sort dialect. */",
|
|
37526
|
-
"decl": "export interface StoreProductSearch {\n query?: string;\n sort?: 'default' | 'az' | 'za';\n ids?: string[];\n /**\n * Only products in this category (V3) / collection (V1) — a category screen's\n * \"products in X\". ANDed with `ids` when both are given.\n *\n * V3 matches `allCategoriesInfo.categories`, so a parent category also lists its\n * subcategories' products, as the site does. Only Search Products can filter by\n * category — Query Products answers `not declared as filterable` — so a\n * `categoryId` always routes the V3 read to `/products/search`. V1 matches\n * `collections.id`.\n */\n categoryId?: string;\n limit?: number;\n cursor?: string;\n /** Extra v3 fieldsets. Additive — widens the default, never replaces it. */\n fields?: readonly string[];\n}",
|
|
37526
|
+
"decl": "export interface StoreProductSearch {\n query?: string;\n sort?: 'default' | 'az' | 'za';\n ids?: string[];\n /**\n * Only products in this category (V3) / collection (V1) — a category screen's\n * \"products in X\". ANDed with `ids` when both are given.\n *\n * V3 matches `allCategoriesInfo.categories`, so a parent category also lists its\n * subcategories' products, as the site does. Only Search Products can filter by\n * category — Query Products answers `not declared as filterable` — so a\n * `categoryId` always routes the V3 read to `/products/search`. V1 matches\n * `collections.id`.\n */\n categoryId?: string;\n /**\n * Match `query` in every field Wix Search Products searches (name, description, …), as the\n * Wix store's own search does, instead of the name alone. Either way any word of the query\n * matches (Wix's default OR mode) and the answer comes in relevance order. V3 only: V1 has\n * no search engine, so its `name` `$contains` filter stays the whole match.\n */\n searchAllFields?: boolean;\n limit?: number;\n cursor?: string;\n /** Extra v3 fieldsets. Additive — widens the default, never replaces it. */\n fields?: readonly string[];\n}",
|
|
37527
37527
|
"verificationChecked": true
|
|
37528
37528
|
},
|
|
37529
37529
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/himalaya-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2052.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "himi — the Himalaya authoring CLI. Build a Tier-5 content package on your own machine, push it to the production serve as a draft, preview it on web + Himi Player, and read worker logs back — the remote dev loop. Wraps @himalaya/serve-cli for transport.",
|
|
6
6
|
"keywords": [
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"artifactId": "himalaya-cli"
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
|
-
"falconPackageHash": "
|
|
85
|
+
"falconPackageHash": "34b831849428c72a200ebbe9f93efb9c950232e0cab024d4d9535eab"
|
|
86
86
|
}
|
|
@@ -3726,6 +3726,10 @@
|
|
|
3726
3726
|
"source": "No products match “{query}”.",
|
|
3727
3727
|
"translation": "אין מוצרים שתואמים ל“{query}”."
|
|
3728
3728
|
},
|
|
3729
|
+
"h_30c8584bc33b": {
|
|
3730
|
+
"source": "Search isn’t available right now. No product names match “{query}”.",
|
|
3731
|
+
"translation": "החיפוש לא זמין כרגע. אין שמות מוצרים שתואמים ל“{query}”."
|
|
3732
|
+
},
|
|
3729
3733
|
"h_d00aa6043f90": {
|
|
3730
3734
|
"source": "No products match these filters.",
|
|
3731
3735
|
"translation": "אין מוצרים שתואמים למסננים האלה."
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The store search behind Branded Lite's Shop and category search fields: the text goes to Wix
|
|
2
|
+
// Search Products, which matches any word of it in the name or the description, as the Wix
|
|
3
|
+
// store's own search does (the One App "Studio Practice Towel" also finds "Studio Practice
|
|
4
|
+
// Journal"). The product list stays the screen's loaded scope; the server answer only says which
|
|
5
|
+
// of those products match and in what order, so sort, filters, prices and hearts are unchanged.
|
|
6
|
+
//
|
|
7
|
+
// Debounce lives in the field (`searchField.debounceMs`): the worker sandbox has no timers on
|
|
8
|
+
// every engine, so one `search` action is one request. Only the newest text owns the answer; an
|
|
9
|
+
// older one landing late is dropped.
|
|
10
|
+
//
|
|
11
|
+
// Offline, or when the request fails, the products whose name contains the text still show
|
|
12
|
+
// (the previous, on-device rule), and `unavailable` lets the screen say the search itself did not
|
|
13
|
+
// run, which is not the same as "nothing matches".
|
|
14
|
+
import { connectivity } from "@himalaya/state";
|
|
15
|
+
import { searchStoreProducts } from "./himi-store.js";
|
|
16
|
+
import type { Row } from "./himi-store-facets.js";
|
|
17
|
+
|
|
18
|
+
/** The server ranks the best matches first; the first page is the answer. A broad word in a large
|
|
19
|
+
* catalog can match more than this: the name matches all still show, the rest past Wix's top 100
|
|
20
|
+
* do not (as a paged search shows its first page). */
|
|
21
|
+
export const STORE_SEARCH_LIMIT = 100;
|
|
22
|
+
|
|
23
|
+
export interface StoreSearchMatch {
|
|
24
|
+
/** Exact name first, then the other names that contain the text, then the server's other matches in its order. */
|
|
25
|
+
rows: Row[];
|
|
26
|
+
/** The server answer for this text is on its way: the name matches show, "no matches" must not. */
|
|
27
|
+
searching: boolean;
|
|
28
|
+
/** The server search did not run (offline) or failed: only name matches show. */
|
|
29
|
+
unavailable: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Entry { key: string; status: "pending" | "ready" | "failed"; order?: Map<string, number> }
|
|
33
|
+
|
|
34
|
+
/** `onLanded` runs when the answer for the newest text lands or fails; the screen re-derives then. */
|
|
35
|
+
export function createStoreSearch(onLanded: () => void) {
|
|
36
|
+
let current: Entry | undefined;
|
|
37
|
+
|
|
38
|
+
/** The newest text's entry, starting its request when the text or the scope changed. */
|
|
39
|
+
function entryFor(scope: string, text: string): Entry | undefined {
|
|
40
|
+
const key = `${scope}\u0000${text.toLowerCase()}`;
|
|
41
|
+
if (current?.key === key) return current;
|
|
42
|
+
// Offline nothing is asked. Back online, the next derive asks (an edit, a refresh, or on Shop
|
|
43
|
+
// the reconnect recovery). A failed answer stays until `reset()`: asking again from derive
|
|
44
|
+
// would turn every failure into a request loop.
|
|
45
|
+
if (!connectivity().online) return undefined;
|
|
46
|
+
const entry: Entry = { key, status: "pending" };
|
|
47
|
+
current = entry;
|
|
48
|
+
void searchStoreProducts({ query: text, searchAllFields: true, limit: STORE_SEARCH_LIMIT, ...(scope ? { categoryId: scope } : {}) }).then(
|
|
49
|
+
(res) => {
|
|
50
|
+
entry.order = new Map();
|
|
51
|
+
for (const p of res.products ?? []) if (p.id && !entry.order.has(p.id)) entry.order.set(p.id, entry.order.size);
|
|
52
|
+
entry.status = "ready";
|
|
53
|
+
},
|
|
54
|
+
() => { entry.status = "failed"; },
|
|
55
|
+
).then(() => { if (current === entry) onLanded(); });
|
|
56
|
+
return entry;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
/** `rows` narrowed to `typed` (as typed; the match trims). `scope`: a category id, "" for the whole catalog. */
|
|
61
|
+
match(rows: Row[], scope: string, typed: string): StoreSearchMatch {
|
|
62
|
+
const text = typed.trim();
|
|
63
|
+
if (!text) return { rows, searching: false, unavailable: false };
|
|
64
|
+
const q = text.toLowerCase();
|
|
65
|
+
// Row names are lower-cased (toRows). An exact name is the product the shopper meant.
|
|
66
|
+
const named = rows.filter((r) => r.name === q).concat(rows.filter((r) => r.name !== q && r.name.includes(q)));
|
|
67
|
+
const entry = entryFor(scope, text);
|
|
68
|
+
if (entry?.status !== "ready") return { rows: named, searching: entry?.status === "pending", unavailable: entry?.status !== "pending" };
|
|
69
|
+
const order = entry.order!;
|
|
70
|
+
const shown = new Set(named);
|
|
71
|
+
const more = rows.filter((r) => !shown.has(r) && order.has(r.card.id)).sort((a, b) => order.get(a.card.id)! - order.get(b.card.id)!);
|
|
72
|
+
return { rows: named.concat(more), searching: false, unavailable: false };
|
|
73
|
+
},
|
|
74
|
+
/** Forget the answer (pull to refresh, a new session): the next match asks again. */
|
|
75
|
+
reset(): void { current = undefined; },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -9,6 +9,7 @@ import { detailInputId, presence, presenceAfterError, type PresenceFlags } from
|
|
|
9
9
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
10
10
|
import { FACETS_BOOT, PAGE_SIZE, applyFacets, currencyOf, facetActions, idOf, readViewPrefs, tagFields, toRows, toggleSaved, type FacetState } from "../_shared/himi-store-facets.js";
|
|
11
11
|
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
12
|
+
import { createStoreSearch } from "../_shared/himi-store-search.js";
|
|
12
13
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
13
14
|
|
|
14
15
|
interface State extends FacetState, PresenceFlags {
|
|
@@ -46,12 +47,18 @@ const products = createCollectionQuery<StoreProduct>({
|
|
|
46
47
|
},
|
|
47
48
|
}, () => { void svc.productsChanged(); });
|
|
48
49
|
|
|
50
|
+
// The search field asks Wix which of the category's products match (any word, name or
|
|
51
|
+
// description), like Shop; offline or on a failure, the names on the device.
|
|
52
|
+
const search = createStoreSearch(() => { void svc.searchLanded(); });
|
|
53
|
+
|
|
49
54
|
function derive(s: State): State {
|
|
50
55
|
const page = products.getState();
|
|
51
56
|
const source = s.found ? page.items : [];
|
|
52
|
-
const query = s.query.trim().toLowerCase();
|
|
53
57
|
const rows = toRows(source);
|
|
54
|
-
const
|
|
58
|
+
const found = search.match(rows, categoryId, s.found ? s.query : "");
|
|
59
|
+
const next = applyFacets(s, found.rows, source.map(currencyOf).find(Boolean));
|
|
60
|
+
// While Wix answers with no name match on screen yet, the skeleton, never "no matches".
|
|
61
|
+
const waiting = found.searching && next.matched === 0;
|
|
55
62
|
const pending = s.found && (page.status === "idle" || page.status === "loading" || page.loadingMore || (!!page.nextCursor && !page.pageError));
|
|
56
63
|
const firstError = s.found && page.status === "error";
|
|
57
64
|
const loaded = s.hasLoadedProducts || page.status === "ready";
|
|
@@ -68,12 +75,12 @@ function derive(s: State): State {
|
|
|
68
75
|
opt1Chips: next.opt1Chips.map(c => ({ ...c, selected: next.opt1Selected.includes(c.id) })),
|
|
69
76
|
opt2Chips: next.opt2Chips.map(c => ({ ...c, selected: next.opt2Selected.includes(c.id) })),
|
|
70
77
|
opt3Chips: next.opt3Chips.map(c => ({ ...c, selected: next.opt3Selected.includes(c.id) })),
|
|
71
|
-
countLabel: s.found && page.status === "ready" ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
78
|
+
countLabel: s.found && page.status === "ready" && !found.searching ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
72
79
|
// Searching a partially loaded category must not replace its content with
|
|
73
80
|
// a first-load skeleton just because the current pages have no match yet.
|
|
74
81
|
hasLoadedProducts: loaded,
|
|
75
|
-
isLoading: pending && !loaded,
|
|
76
|
-
notLoading: !(pending && !loaded),
|
|
82
|
+
isLoading: (pending && !loaded) || waiting,
|
|
83
|
+
notLoading: !(pending && !loaded) && !waiting,
|
|
77
84
|
nextCursor: next.nextCursor || (!scanning && !page.pageError ? page.nextCursor : ""),
|
|
78
85
|
noMore: next.noMore && (scanning || !page.nextCursor || page.pageError),
|
|
79
86
|
pendingProducts: pending,
|
|
@@ -81,8 +88,11 @@ function derive(s: State): State {
|
|
|
81
88
|
noPageError: !s.found || !page.pageError,
|
|
82
89
|
noRefreshError: !refreshFailed || !s.found || !loaded || page.pageError,
|
|
83
90
|
// A filtered first page isn't proof of no matches while later pages load.
|
|
84
|
-
noEmpty: !s.found || pending || firstError || page.pageError || next.results.length > 0,
|
|
85
|
-
|
|
91
|
+
noEmpty: !s.found || pending || waiting || firstError || page.pageError || next.results.length > 0,
|
|
92
|
+
// Offline or a failed search is not "nothing matches": say only the names were searched.
|
|
93
|
+
emptyText: found.unavailable && s.query.trim()
|
|
94
|
+
? copyTemplate("collection.searchUnavailable", "Search isn’t available right now. No product names match “{query}”.", { query: s.query.trim() })
|
|
95
|
+
: copyParam("collection.productsEmptyBody", "Try another search or browse a different category."),
|
|
86
96
|
};
|
|
87
97
|
}
|
|
88
98
|
|
|
@@ -112,6 +122,8 @@ const actions = {
|
|
|
112
122
|
stashCopy(arg);
|
|
113
123
|
// Hearts follow the signed-in member's account wishlist, read beside the products.
|
|
114
124
|
refreshSavedThen(() => svc.savedChanged());
|
|
125
|
+
// A load (onAppear, pull to refresh, the error banner) asks a failed search again.
|
|
126
|
+
search.reset();
|
|
115
127
|
const version = ++loadVersion;
|
|
116
128
|
const id = detailInputId();
|
|
117
129
|
if (!id) return derive({ ...s, ...presence("missing"), loadId: version });
|
|
@@ -155,6 +167,8 @@ const actions = {
|
|
|
155
167
|
});
|
|
156
168
|
},
|
|
157
169
|
productsChanged: (s: State) => s.loadId === loadVersion ? derive(s) : undefined,
|
|
170
|
+
// Wix answered the newest search text (an older text's answer never dispatches).
|
|
171
|
+
searchLanded: (s: State) => derive(s),
|
|
158
172
|
search: (s: State, arg?: { value?: string }) => derive({ ...s, query: (arg?.value ?? "").slice(0, 256), visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
|
|
159
173
|
toggleSave: async (s: State, arg?: unknown): Promise<State> => { try { await toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(svc.getState() as State); },
|
|
160
174
|
// The signed-in member's saved list landed: re-mark the hearts.
|
|
@@ -179,7 +193,7 @@ const actions = {
|
|
|
179
193
|
await products.loadMore();
|
|
180
194
|
return undefined;
|
|
181
195
|
},
|
|
182
|
-
retry: async () => { refreshFailed = false; await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
196
|
+
retry: async () => { refreshFailed = false; search.reset(); await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
183
197
|
};
|
|
184
198
|
const register = withIapPresentation<State>({
|
|
185
199
|
prefix: "category",
|
|
@@ -6957,6 +6957,10 @@
|
|
|
6957
6957
|
"source": "No products match “{query}”.",
|
|
6958
6958
|
"translation": "אין מוצרים שתואמים ל“{query}”."
|
|
6959
6959
|
},
|
|
6960
|
+
"h_30c8584bc33b": {
|
|
6961
|
+
"source": "Search isn’t available right now. No product names match “{query}”.",
|
|
6962
|
+
"translation": "החיפוש לא זמין כרגע. אין שמות מוצרים שתואמים ל“{query}”."
|
|
6963
|
+
},
|
|
6960
6964
|
"h_d00aa6043f90": {
|
|
6961
6965
|
"source": "No products match these filters.",
|
|
6962
6966
|
"translation": "אין מוצרים שתואמים למסננים האלה."
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The store search behind Branded Lite's Shop and category search fields: the text goes to Wix
|
|
2
|
+
// Search Products, which matches any word of it in the name or the description, as the Wix
|
|
3
|
+
// store's own search does (the One App "Studio Practice Towel" also finds "Studio Practice
|
|
4
|
+
// Journal"). The product list stays the screen's loaded scope; the server answer only says which
|
|
5
|
+
// of those products match and in what order, so sort, filters, prices and hearts are unchanged.
|
|
6
|
+
//
|
|
7
|
+
// Debounce lives in the field (`searchField.debounceMs`): the worker sandbox has no timers on
|
|
8
|
+
// every engine, so one `search` action is one request. Only the newest text owns the answer; an
|
|
9
|
+
// older one landing late is dropped.
|
|
10
|
+
//
|
|
11
|
+
// Offline, or when the request fails, the products whose name contains the text still show
|
|
12
|
+
// (the previous, on-device rule), and `unavailable` lets the screen say the search itself did not
|
|
13
|
+
// run, which is not the same as "nothing matches".
|
|
14
|
+
import { connectivity } from "@himalaya/state";
|
|
15
|
+
import { searchStoreProducts } from "./himi-store.js";
|
|
16
|
+
import type { Row } from "./himi-store-facets.js";
|
|
17
|
+
|
|
18
|
+
/** The server ranks the best matches first; the first page is the answer. A broad word in a large
|
|
19
|
+
* catalog can match more than this: the name matches all still show, the rest past Wix's top 100
|
|
20
|
+
* do not (as a paged search shows its first page). */
|
|
21
|
+
export const STORE_SEARCH_LIMIT = 100;
|
|
22
|
+
|
|
23
|
+
export interface StoreSearchMatch {
|
|
24
|
+
/** Exact name first, then the other names that contain the text, then the server's other matches in its order. */
|
|
25
|
+
rows: Row[];
|
|
26
|
+
/** The server answer for this text is on its way: the name matches show, "no matches" must not. */
|
|
27
|
+
searching: boolean;
|
|
28
|
+
/** The server search did not run (offline) or failed: only name matches show. */
|
|
29
|
+
unavailable: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Entry { key: string; status: "pending" | "ready" | "failed"; order?: Map<string, number> }
|
|
33
|
+
|
|
34
|
+
/** `onLanded` runs when the answer for the newest text lands or fails; the screen re-derives then. */
|
|
35
|
+
export function createStoreSearch(onLanded: () => void) {
|
|
36
|
+
let current: Entry | undefined;
|
|
37
|
+
|
|
38
|
+
/** The newest text's entry, starting its request when the text or the scope changed. */
|
|
39
|
+
function entryFor(scope: string, text: string): Entry | undefined {
|
|
40
|
+
const key = `${scope}\u0000${text.toLowerCase()}`;
|
|
41
|
+
if (current?.key === key) return current;
|
|
42
|
+
// Offline nothing is asked. Back online, the next derive asks (an edit, a refresh, or on Shop
|
|
43
|
+
// the reconnect recovery). A failed answer stays until `reset()`: asking again from derive
|
|
44
|
+
// would turn every failure into a request loop.
|
|
45
|
+
if (!connectivity().online) return undefined;
|
|
46
|
+
const entry: Entry = { key, status: "pending" };
|
|
47
|
+
current = entry;
|
|
48
|
+
void searchStoreProducts({ query: text, searchAllFields: true, limit: STORE_SEARCH_LIMIT, ...(scope ? { categoryId: scope } : {}) }).then(
|
|
49
|
+
(res) => {
|
|
50
|
+
entry.order = new Map();
|
|
51
|
+
for (const p of res.products ?? []) if (p.id && !entry.order.has(p.id)) entry.order.set(p.id, entry.order.size);
|
|
52
|
+
entry.status = "ready";
|
|
53
|
+
},
|
|
54
|
+
() => { entry.status = "failed"; },
|
|
55
|
+
).then(() => { if (current === entry) onLanded(); });
|
|
56
|
+
return entry;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
/** `rows` narrowed to `typed` (as typed; the match trims). `scope`: a category id, "" for the whole catalog. */
|
|
61
|
+
match(rows: Row[], scope: string, typed: string): StoreSearchMatch {
|
|
62
|
+
const text = typed.trim();
|
|
63
|
+
if (!text) return { rows, searching: false, unavailable: false };
|
|
64
|
+
const q = text.toLowerCase();
|
|
65
|
+
// Row names are lower-cased (toRows). An exact name is the product the shopper meant.
|
|
66
|
+
const named = rows.filter((r) => r.name === q).concat(rows.filter((r) => r.name !== q && r.name.includes(q)));
|
|
67
|
+
const entry = entryFor(scope, text);
|
|
68
|
+
if (entry?.status !== "ready") return { rows: named, searching: entry?.status === "pending", unavailable: entry?.status !== "pending" };
|
|
69
|
+
const order = entry.order!;
|
|
70
|
+
const shown = new Set(named);
|
|
71
|
+
const more = rows.filter((r) => !shown.has(r) && order.has(r.card.id)).sort((a, b) => order.get(a.card.id)! - order.get(b.card.id)!);
|
|
72
|
+
return { rows: named.concat(more), searching: false, unavailable: false };
|
|
73
|
+
},
|
|
74
|
+
/** Forget the answer (pull to refresh, a new session): the next match asks again. */
|
|
75
|
+
reset(): void { current = undefined; },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -9,6 +9,7 @@ import { detailInputId, presence, presenceAfterError, type PresenceFlags } from
|
|
|
9
9
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
10
10
|
import { FACETS_BOOT, PAGE_SIZE, applyFacets, currencyOf, facetActions, idOf, readViewPrefs, tagFields, toRows, toggleSaved, type FacetState } from "../_shared/himi-store-facets.js";
|
|
11
11
|
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
12
|
+
import { createStoreSearch } from "../_shared/himi-store-search.js";
|
|
12
13
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
13
14
|
|
|
14
15
|
interface State extends FacetState, PresenceFlags {
|
|
@@ -46,12 +47,18 @@ const products = createCollectionQuery<StoreProduct>({
|
|
|
46
47
|
},
|
|
47
48
|
}, () => { void svc.productsChanged(); });
|
|
48
49
|
|
|
50
|
+
// The search field asks Wix which of the category's products match (any word, name or
|
|
51
|
+
// description), like Shop; offline or on a failure, the names on the device.
|
|
52
|
+
const search = createStoreSearch(() => { void svc.searchLanded(); });
|
|
53
|
+
|
|
49
54
|
function derive(s: State): State {
|
|
50
55
|
const page = products.getState();
|
|
51
56
|
const source = s.found ? page.items : [];
|
|
52
|
-
const query = s.query.trim().toLowerCase();
|
|
53
57
|
const rows = toRows(source);
|
|
54
|
-
const
|
|
58
|
+
const found = search.match(rows, categoryId, s.found ? s.query : "");
|
|
59
|
+
const next = applyFacets(s, found.rows, source.map(currencyOf).find(Boolean));
|
|
60
|
+
// While Wix answers with no name match on screen yet, the skeleton, never "no matches".
|
|
61
|
+
const waiting = found.searching && next.matched === 0;
|
|
55
62
|
const pending = s.found && (page.status === "idle" || page.status === "loading" || page.loadingMore || (!!page.nextCursor && !page.pageError));
|
|
56
63
|
const firstError = s.found && page.status === "error";
|
|
57
64
|
const loaded = s.hasLoadedProducts || page.status === "ready";
|
|
@@ -68,12 +75,12 @@ function derive(s: State): State {
|
|
|
68
75
|
opt1Chips: next.opt1Chips.map(c => ({ ...c, selected: next.opt1Selected.includes(c.id) })),
|
|
69
76
|
opt2Chips: next.opt2Chips.map(c => ({ ...c, selected: next.opt2Selected.includes(c.id) })),
|
|
70
77
|
opt3Chips: next.opt3Chips.map(c => ({ ...c, selected: next.opt3Selected.includes(c.id) })),
|
|
71
|
-
countLabel: s.found && page.status === "ready" ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
78
|
+
countLabel: s.found && page.status === "ready" && !found.searching ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
72
79
|
// Searching a partially loaded category must not replace its content with
|
|
73
80
|
// a first-load skeleton just because the current pages have no match yet.
|
|
74
81
|
hasLoadedProducts: loaded,
|
|
75
|
-
isLoading: pending && !loaded,
|
|
76
|
-
notLoading: !(pending && !loaded),
|
|
82
|
+
isLoading: (pending && !loaded) || waiting,
|
|
83
|
+
notLoading: !(pending && !loaded) && !waiting,
|
|
77
84
|
nextCursor: next.nextCursor || (!scanning && !page.pageError ? page.nextCursor : ""),
|
|
78
85
|
noMore: next.noMore && (scanning || !page.nextCursor || page.pageError),
|
|
79
86
|
pendingProducts: pending,
|
|
@@ -81,8 +88,11 @@ function derive(s: State): State {
|
|
|
81
88
|
noPageError: !s.found || !page.pageError,
|
|
82
89
|
noRefreshError: !refreshFailed || !s.found || !loaded || page.pageError,
|
|
83
90
|
// A filtered first page isn't proof of no matches while later pages load.
|
|
84
|
-
noEmpty: !s.found || pending || firstError || page.pageError || next.results.length > 0,
|
|
85
|
-
|
|
91
|
+
noEmpty: !s.found || pending || waiting || firstError || page.pageError || next.results.length > 0,
|
|
92
|
+
// Offline or a failed search is not "nothing matches": say only the names were searched.
|
|
93
|
+
emptyText: found.unavailable && s.query.trim()
|
|
94
|
+
? copyTemplate("collection.searchUnavailable", "Search isn’t available right now. No product names match “{query}”.", { query: s.query.trim() })
|
|
95
|
+
: copyParam("collection.productsEmptyBody", "Try another search or browse a different category."),
|
|
86
96
|
};
|
|
87
97
|
}
|
|
88
98
|
|
|
@@ -112,6 +122,8 @@ const actions = {
|
|
|
112
122
|
stashCopy(arg);
|
|
113
123
|
// Hearts follow the signed-in member's account wishlist, read beside the products.
|
|
114
124
|
refreshSavedThen(() => svc.savedChanged());
|
|
125
|
+
// A load (onAppear, pull to refresh, the error banner) asks a failed search again.
|
|
126
|
+
search.reset();
|
|
115
127
|
const version = ++loadVersion;
|
|
116
128
|
const id = detailInputId();
|
|
117
129
|
if (!id) return derive({ ...s, ...presence("missing"), loadId: version });
|
|
@@ -155,6 +167,8 @@ const actions = {
|
|
|
155
167
|
});
|
|
156
168
|
},
|
|
157
169
|
productsChanged: (s: State) => s.loadId === loadVersion ? derive(s) : undefined,
|
|
170
|
+
// Wix answered the newest search text (an older text's answer never dispatches).
|
|
171
|
+
searchLanded: (s: State) => derive(s),
|
|
158
172
|
search: (s: State, arg?: { value?: string }) => derive({ ...s, query: (arg?.value ?? "").slice(0, 256), visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
|
|
159
173
|
toggleSave: async (s: State, arg?: unknown): Promise<State> => { try { await toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(svc.getState() as State); },
|
|
160
174
|
// The signed-in member's saved list landed: re-mark the hearts.
|
|
@@ -179,7 +193,7 @@ const actions = {
|
|
|
179
193
|
await products.loadMore();
|
|
180
194
|
return undefined;
|
|
181
195
|
},
|
|
182
|
-
retry: async () => { refreshFailed = false; await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
196
|
+
retry: async () => { refreshFailed = false; search.reset(); await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
183
197
|
};
|
|
184
198
|
const register = withIapPresentation<State>({
|
|
185
199
|
prefix: "category",
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
// of product cards with a saved-products heart, and a live cart count for the top bar.
|
|
5
5
|
//
|
|
6
6
|
// The scope is one category (or All), fetched from Wix; sort and filters then narrow
|
|
7
|
-
// it on the device (../_shared/himi-store-facets.ts). The search field
|
|
8
|
-
// the
|
|
9
|
-
//
|
|
7
|
+
// it on the device (../_shared/himi-store-facets.ts). The search field asks Wix which
|
|
8
|
+
// products of the scope match, by any word in the name or description, and falls back to
|
|
9
|
+
// the names on the device offline (../_shared/himi-store-search.ts). The first page paints
|
|
10
|
+
// as soon as it lands; later pages join it in the background.
|
|
10
11
|
//
|
|
11
12
|
// Opened with `category` = a category id or name; absent ⇒ All.
|
|
12
13
|
import { getCurrentCart } from "@himalaya/wix-ecom";
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
type FacetState, type Option, type Row,
|
|
22
23
|
} from "../_shared/himi-store-facets.js";
|
|
23
24
|
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
25
|
+
import { createStoreSearch } from "../_shared/himi-store-search.js";
|
|
24
26
|
|
|
25
27
|
const ALL = "all";
|
|
26
28
|
const PAGE = 100;
|
|
@@ -43,7 +45,7 @@ interface S extends FacetState {
|
|
|
43
45
|
categorySelected: string;
|
|
44
46
|
/** The scope generation this state was derived for — see `committed`. */
|
|
45
47
|
scopeGen: number;
|
|
46
|
-
/** The search field's text; matches
|
|
48
|
+
/** The search field's text; Wix matches it within the category (names on the device offline). */
|
|
47
49
|
query: string;
|
|
48
50
|
/** The chip row: All plus one chip per store category, with its selected state. */
|
|
49
51
|
categoryOptions: Option[];
|
|
@@ -169,21 +171,26 @@ function reconcileCategories(): { invalidatedSelection: boolean; intentVersion:
|
|
|
169
171
|
return { invalidatedSelection, intentVersion: categoryIntentVersion };
|
|
170
172
|
}
|
|
171
173
|
|
|
174
|
+
/** The answer for the newest search text landed (or failed): re-derive the page as it is now. */
|
|
175
|
+
const search = createStoreSearch(() => { void svc.searchLanded(); });
|
|
176
|
+
|
|
172
177
|
function derive(s: S): S {
|
|
173
178
|
// The field keeps exactly what the shopper typed (a trailing space included); the match trims.
|
|
174
179
|
const typed = s.query.trim();
|
|
175
|
-
const
|
|
176
|
-
const next = applyFacets(s,
|
|
180
|
+
const found = search.match(rows, s.categorySelected === ALL ? "" : s.categorySelected, s.query);
|
|
181
|
+
const next = applyFacets(s, found.rows, currency);
|
|
177
182
|
const n = next.matched;
|
|
178
|
-
|
|
183
|
+
// While Wix answers, the name matches show; with none yet, the skeleton, never "no matches".
|
|
184
|
+
const waiting = found.searching && n === 0;
|
|
185
|
+
const ready = s.status === "ready" && !waiting;
|
|
179
186
|
const readMessage = !s.readStatus.hasSnapshot && s.readStatus.offline
|
|
180
187
|
? "This content isn’t available offline. Connect to load it."
|
|
181
188
|
: s.readStatus.error || "";
|
|
182
189
|
const choices = [{ id: ALL, label: copyParam("shop.allChip", "All") }, ...categories.map((c) => ({ id: c.id, label: c.name }))];
|
|
183
190
|
return {
|
|
184
191
|
...next,
|
|
185
|
-
isLoading: s.status === "loading",
|
|
186
|
-
notLoading: s.status !== "loading",
|
|
192
|
+
isLoading: s.status === "loading" || waiting,
|
|
193
|
+
notLoading: s.status !== "loading" && !waiting,
|
|
187
194
|
isErrored: s.status === "error",
|
|
188
195
|
notErrored: s.status !== "error",
|
|
189
196
|
// The shared shell owns offline/stale messages; this former local-DB note stays hidden.
|
|
@@ -191,10 +198,14 @@ function derive(s: S): S {
|
|
|
191
198
|
readMessage, noReadMessage: !readMessage, hasReadMessage: !!readMessage,
|
|
192
199
|
categoryOptions: choices.map((c) => option(c, c.id === s.categorySelected)),
|
|
193
200
|
hideCategories: categories.length === 0,
|
|
194
|
-
|
|
201
|
+
// A count that grows when the answer lands would read as a wrong count: none until then.
|
|
202
|
+
countLabel: ready && !found.searching ? countText(n) : "",
|
|
195
203
|
noEmpty: !ready || n > 0,
|
|
204
|
+
// Offline or a failed search is not "nothing matches": say only the names were searched.
|
|
196
205
|
emptyText: typed
|
|
197
|
-
?
|
|
206
|
+
? found.unavailable
|
|
207
|
+
? copyTemplate("shop.searchUnavailable", "Search isn’t available right now. No product names match “{query}”.", { query: typed })
|
|
208
|
+
: copyTemplate("shop.noQueryMatch", "No products match “{query}”.", { query: typed })
|
|
198
209
|
: next.activeFilters
|
|
199
210
|
? copyParam("shop.noMatchText", "No products match these filters.")
|
|
200
211
|
: s.categorySelected !== ALL
|
|
@@ -613,7 +624,7 @@ const BOOT: S = derive({
|
|
|
613
624
|
});
|
|
614
625
|
|
|
615
626
|
const facets = facetActions<S>(derive);
|
|
616
|
-
const CONTENT = ["readChanged", "load", "refresh", "retry", "loaded", "scopeLanded", "scopeGrew", "selectCategory", "search", "toggleSave", "loadMore", ...Object.keys(facets)];
|
|
627
|
+
const CONTENT = ["readChanged", "load", "refresh", "retry", "loaded", "scopeLanded", "scopeGrew", "selectCategory", "search", "searchLanded", "toggleSave", "loadMore", ...Object.keys(facets)];
|
|
617
628
|
const register = withIapPresentation<S>({
|
|
618
629
|
// Restored from the last run, these painted a state this boot has not reached: a count over
|
|
619
630
|
// no cards, an open sheet, a stale scope generation that defeats `committed`, a search
|
|
@@ -677,12 +688,15 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
|
|
|
677
688
|
load: (s, arg) => load(s, arg),
|
|
678
689
|
// Pull to refresh: the categories and the scope again, from Wix.
|
|
679
690
|
refresh: async (s, arg) => {
|
|
691
|
+
// A pull to refresh asks the search again too (a failed one gets its retry here).
|
|
692
|
+
search.reset();
|
|
680
693
|
const next = await load(s, arg, true);
|
|
681
694
|
// The result owns its scope; another action may have changed the globals during load.
|
|
682
695
|
return next ? settledWithin(next, next.categorySelected, next.scopeGen) : undefined;
|
|
683
696
|
},
|
|
684
|
-
|
|
685
|
-
|
|
697
|
+
// Retry and reconnect recovery ask a failed search again too, like a pull to refresh.
|
|
698
|
+
retry: (s) => { search.reset(); return settledWithin(showScope(s, s.categorySelected, true), s.categorySelected, generation); },
|
|
699
|
+
recover: async () => { search.reset(); await fetchScope(selectedCategory, generation, true); return undefined; },
|
|
686
700
|
readChanged: (s, arg) => {
|
|
687
701
|
if (!arg || typeof arg !== 'object') return undefined;
|
|
688
702
|
const value = arg as { gen: number; category: string; readStatus: ReadStatus };
|
|
@@ -736,6 +750,8 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
|
|
|
736
750
|
if (query === s.query) return s;
|
|
737
751
|
return derive({ ...s, query, ...(query.trim() === s.query.trim() ? {} : { visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }) });
|
|
738
752
|
},
|
|
753
|
+
// Wix answered the newest search text (an older text's answer never dispatches).
|
|
754
|
+
searchLanded: (s) => derive(s),
|
|
739
755
|
toggleSave: async (s, arg): Promise<S> => {
|
|
740
756
|
try { await toggleSaved(s.results, idOf(arg)); } catch { return s; }
|
|
741
757
|
// The page as it is now: other actions may have run while the save was on the wire.
|
|
@@ -755,6 +771,7 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
|
|
|
755
771
|
rows = []; currency = undefined; categories = []; categoriesAuthoritative = false;
|
|
756
772
|
scopes.clear(); pendingScopes.clear(); pendingRefreshScopes.clear();
|
|
757
773
|
loadedCartCount = 0; pendingAuxiliary = undefined; pendingCategoriesRead = undefined;
|
|
774
|
+
search.reset();
|
|
758
775
|
void svc.identityChanged();
|
|
759
776
|
});
|
|
760
777
|
svc.load();
|
|
@@ -4039,6 +4039,10 @@
|
|
|
4039
4039
|
"source": "No products match “{query}”.",
|
|
4040
4040
|
"translation": "אין מוצרים שתואמים ל“{query}”."
|
|
4041
4041
|
},
|
|
4042
|
+
"h_30c8584bc33b": {
|
|
4043
|
+
"source": "Search isn’t available right now. No product names match “{query}”.",
|
|
4044
|
+
"translation": "החיפוש לא זמין כרגע. אין שמות מוצרים שתואמים ל“{query}”."
|
|
4045
|
+
},
|
|
4042
4046
|
"h_d00aa6043f90": {
|
|
4043
4047
|
"source": "No products match these filters.",
|
|
4044
4048
|
"translation": "אין מוצרים שתואמים למסננים האלה."
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The store search behind Branded Lite's Shop and category search fields: the text goes to Wix
|
|
2
|
+
// Search Products, which matches any word of it in the name or the description, as the Wix
|
|
3
|
+
// store's own search does (the One App "Studio Practice Towel" also finds "Studio Practice
|
|
4
|
+
// Journal"). The product list stays the screen's loaded scope; the server answer only says which
|
|
5
|
+
// of those products match and in what order, so sort, filters, prices and hearts are unchanged.
|
|
6
|
+
//
|
|
7
|
+
// Debounce lives in the field (`searchField.debounceMs`): the worker sandbox has no timers on
|
|
8
|
+
// every engine, so one `search` action is one request. Only the newest text owns the answer; an
|
|
9
|
+
// older one landing late is dropped.
|
|
10
|
+
//
|
|
11
|
+
// Offline, or when the request fails, the products whose name contains the text still show
|
|
12
|
+
// (the previous, on-device rule), and `unavailable` lets the screen say the search itself did not
|
|
13
|
+
// run, which is not the same as "nothing matches".
|
|
14
|
+
import { connectivity } from "@himalaya/state";
|
|
15
|
+
import { searchStoreProducts } from "./himi-store.js";
|
|
16
|
+
import type { Row } from "./himi-store-facets.js";
|
|
17
|
+
|
|
18
|
+
/** The server ranks the best matches first; the first page is the answer. A broad word in a large
|
|
19
|
+
* catalog can match more than this: the name matches all still show, the rest past Wix's top 100
|
|
20
|
+
* do not (as a paged search shows its first page). */
|
|
21
|
+
export const STORE_SEARCH_LIMIT = 100;
|
|
22
|
+
|
|
23
|
+
export interface StoreSearchMatch {
|
|
24
|
+
/** Exact name first, then the other names that contain the text, then the server's other matches in its order. */
|
|
25
|
+
rows: Row[];
|
|
26
|
+
/** The server answer for this text is on its way: the name matches show, "no matches" must not. */
|
|
27
|
+
searching: boolean;
|
|
28
|
+
/** The server search did not run (offline) or failed: only name matches show. */
|
|
29
|
+
unavailable: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Entry { key: string; status: "pending" | "ready" | "failed"; order?: Map<string, number> }
|
|
33
|
+
|
|
34
|
+
/** `onLanded` runs when the answer for the newest text lands or fails; the screen re-derives then. */
|
|
35
|
+
export function createStoreSearch(onLanded: () => void) {
|
|
36
|
+
let current: Entry | undefined;
|
|
37
|
+
|
|
38
|
+
/** The newest text's entry, starting its request when the text or the scope changed. */
|
|
39
|
+
function entryFor(scope: string, text: string): Entry | undefined {
|
|
40
|
+
const key = `${scope}\u0000${text.toLowerCase()}`;
|
|
41
|
+
if (current?.key === key) return current;
|
|
42
|
+
// Offline nothing is asked. Back online, the next derive asks (an edit, a refresh, or on Shop
|
|
43
|
+
// the reconnect recovery). A failed answer stays until `reset()`: asking again from derive
|
|
44
|
+
// would turn every failure into a request loop.
|
|
45
|
+
if (!connectivity().online) return undefined;
|
|
46
|
+
const entry: Entry = { key, status: "pending" };
|
|
47
|
+
current = entry;
|
|
48
|
+
void searchStoreProducts({ query: text, searchAllFields: true, limit: STORE_SEARCH_LIMIT, ...(scope ? { categoryId: scope } : {}) }).then(
|
|
49
|
+
(res) => {
|
|
50
|
+
entry.order = new Map();
|
|
51
|
+
for (const p of res.products ?? []) if (p.id && !entry.order.has(p.id)) entry.order.set(p.id, entry.order.size);
|
|
52
|
+
entry.status = "ready";
|
|
53
|
+
},
|
|
54
|
+
() => { entry.status = "failed"; },
|
|
55
|
+
).then(() => { if (current === entry) onLanded(); });
|
|
56
|
+
return entry;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
/** `rows` narrowed to `typed` (as typed; the match trims). `scope`: a category id, "" for the whole catalog. */
|
|
61
|
+
match(rows: Row[], scope: string, typed: string): StoreSearchMatch {
|
|
62
|
+
const text = typed.trim();
|
|
63
|
+
if (!text) return { rows, searching: false, unavailable: false };
|
|
64
|
+
const q = text.toLowerCase();
|
|
65
|
+
// Row names are lower-cased (toRows). An exact name is the product the shopper meant.
|
|
66
|
+
const named = rows.filter((r) => r.name === q).concat(rows.filter((r) => r.name !== q && r.name.includes(q)));
|
|
67
|
+
const entry = entryFor(scope, text);
|
|
68
|
+
if (entry?.status !== "ready") return { rows: named, searching: entry?.status === "pending", unavailable: entry?.status !== "pending" };
|
|
69
|
+
const order = entry.order!;
|
|
70
|
+
const shown = new Set(named);
|
|
71
|
+
const more = rows.filter((r) => !shown.has(r) && order.has(r.card.id)).sort((a, b) => order.get(a.card.id)! - order.get(b.card.id)!);
|
|
72
|
+
return { rows: named.concat(more), searching: false, unavailable: false };
|
|
73
|
+
},
|
|
74
|
+
/** Forget the answer (pull to refresh, a new session): the next match asks again. */
|
|
75
|
+
reset(): void { current = undefined; },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -9,6 +9,7 @@ import { detailInputId, presence, presenceAfterError, type PresenceFlags } from
|
|
|
9
9
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
10
10
|
import { FACETS_BOOT, PAGE_SIZE, applyFacets, currencyOf, facetActions, idOf, readViewPrefs, tagFields, toRows, toggleSaved, type FacetState } from "../_shared/himi-store-facets.js";
|
|
11
11
|
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
12
|
+
import { createStoreSearch } from "../_shared/himi-store-search.js";
|
|
12
13
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
13
14
|
|
|
14
15
|
interface State extends FacetState, PresenceFlags {
|
|
@@ -46,12 +47,18 @@ const products = createCollectionQuery<StoreProduct>({
|
|
|
46
47
|
},
|
|
47
48
|
}, () => { void svc.productsChanged(); });
|
|
48
49
|
|
|
50
|
+
// The search field asks Wix which of the category's products match (any word, name or
|
|
51
|
+
// description), like Shop; offline or on a failure, the names on the device.
|
|
52
|
+
const search = createStoreSearch(() => { void svc.searchLanded(); });
|
|
53
|
+
|
|
49
54
|
function derive(s: State): State {
|
|
50
55
|
const page = products.getState();
|
|
51
56
|
const source = s.found ? page.items : [];
|
|
52
|
-
const query = s.query.trim().toLowerCase();
|
|
53
57
|
const rows = toRows(source);
|
|
54
|
-
const
|
|
58
|
+
const found = search.match(rows, categoryId, s.found ? s.query : "");
|
|
59
|
+
const next = applyFacets(s, found.rows, source.map(currencyOf).find(Boolean));
|
|
60
|
+
// While Wix answers with no name match on screen yet, the skeleton, never "no matches".
|
|
61
|
+
const waiting = found.searching && next.matched === 0;
|
|
55
62
|
const pending = s.found && (page.status === "idle" || page.status === "loading" || page.loadingMore || (!!page.nextCursor && !page.pageError));
|
|
56
63
|
const firstError = s.found && page.status === "error";
|
|
57
64
|
const loaded = s.hasLoadedProducts || page.status === "ready";
|
|
@@ -68,12 +75,12 @@ function derive(s: State): State {
|
|
|
68
75
|
opt1Chips: next.opt1Chips.map(c => ({ ...c, selected: next.opt1Selected.includes(c.id) })),
|
|
69
76
|
opt2Chips: next.opt2Chips.map(c => ({ ...c, selected: next.opt2Selected.includes(c.id) })),
|
|
70
77
|
opt3Chips: next.opt3Chips.map(c => ({ ...c, selected: next.opt3Selected.includes(c.id) })),
|
|
71
|
-
countLabel: s.found && page.status === "ready" ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
78
|
+
countLabel: s.found && page.status === "ready" && !found.searching ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
72
79
|
// Searching a partially loaded category must not replace its content with
|
|
73
80
|
// a first-load skeleton just because the current pages have no match yet.
|
|
74
81
|
hasLoadedProducts: loaded,
|
|
75
|
-
isLoading: pending && !loaded,
|
|
76
|
-
notLoading: !(pending && !loaded),
|
|
82
|
+
isLoading: (pending && !loaded) || waiting,
|
|
83
|
+
notLoading: !(pending && !loaded) && !waiting,
|
|
77
84
|
nextCursor: next.nextCursor || (!scanning && !page.pageError ? page.nextCursor : ""),
|
|
78
85
|
noMore: next.noMore && (scanning || !page.nextCursor || page.pageError),
|
|
79
86
|
pendingProducts: pending,
|
|
@@ -81,8 +88,11 @@ function derive(s: State): State {
|
|
|
81
88
|
noPageError: !s.found || !page.pageError,
|
|
82
89
|
noRefreshError: !refreshFailed || !s.found || !loaded || page.pageError,
|
|
83
90
|
// A filtered first page isn't proof of no matches while later pages load.
|
|
84
|
-
noEmpty: !s.found || pending || firstError || page.pageError || next.results.length > 0,
|
|
85
|
-
|
|
91
|
+
noEmpty: !s.found || pending || waiting || firstError || page.pageError || next.results.length > 0,
|
|
92
|
+
// Offline or a failed search is not "nothing matches": say only the names were searched.
|
|
93
|
+
emptyText: found.unavailable && s.query.trim()
|
|
94
|
+
? copyTemplate("collection.searchUnavailable", "Search isn’t available right now. No product names match “{query}”.", { query: s.query.trim() })
|
|
95
|
+
: copyParam("collection.productsEmptyBody", "Try another search or browse a different category."),
|
|
86
96
|
};
|
|
87
97
|
}
|
|
88
98
|
|
|
@@ -112,6 +122,8 @@ const actions = {
|
|
|
112
122
|
stashCopy(arg);
|
|
113
123
|
// Hearts follow the signed-in member's account wishlist, read beside the products.
|
|
114
124
|
refreshSavedThen(() => svc.savedChanged());
|
|
125
|
+
// A load (onAppear, pull to refresh, the error banner) asks a failed search again.
|
|
126
|
+
search.reset();
|
|
115
127
|
const version = ++loadVersion;
|
|
116
128
|
const id = detailInputId();
|
|
117
129
|
if (!id) return derive({ ...s, ...presence("missing"), loadId: version });
|
|
@@ -155,6 +167,8 @@ const actions = {
|
|
|
155
167
|
});
|
|
156
168
|
},
|
|
157
169
|
productsChanged: (s: State) => s.loadId === loadVersion ? derive(s) : undefined,
|
|
170
|
+
// Wix answered the newest search text (an older text's answer never dispatches).
|
|
171
|
+
searchLanded: (s: State) => derive(s),
|
|
158
172
|
search: (s: State, arg?: { value?: string }) => derive({ ...s, query: (arg?.value ?? "").slice(0, 256), visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
|
|
159
173
|
toggleSave: async (s: State, arg?: unknown): Promise<State> => { try { await toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(svc.getState() as State); },
|
|
160
174
|
// The signed-in member's saved list landed: re-mark the hearts.
|
|
@@ -179,7 +193,7 @@ const actions = {
|
|
|
179
193
|
await products.loadMore();
|
|
180
194
|
return undefined;
|
|
181
195
|
},
|
|
182
|
-
retry: async () => { refreshFailed = false; await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
196
|
+
retry: async () => { refreshFailed = false; search.reset(); await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
183
197
|
};
|
|
184
198
|
const register = withIapPresentation<State>({
|
|
185
199
|
prefix: "category",
|
|
@@ -2982,6 +2982,10 @@
|
|
|
2982
2982
|
"source": "No products match “{query}”.",
|
|
2983
2983
|
"translation": "אין מוצרים שתואמים ל“{query}”."
|
|
2984
2984
|
},
|
|
2985
|
+
"h_30c8584bc33b": {
|
|
2986
|
+
"source": "Search isn’t available right now. No product names match “{query}”.",
|
|
2987
|
+
"translation": "החיפוש לא זמין כרגע. אין שמות מוצרים שתואמים ל“{query}”."
|
|
2988
|
+
},
|
|
2985
2989
|
"h_d00aa6043f90": {
|
|
2986
2990
|
"source": "No products match these filters.",
|
|
2987
2991
|
"translation": "אין מוצרים שתואמים למסננים האלה."
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The store search behind Branded Lite's Shop and category search fields: the text goes to Wix
|
|
2
|
+
// Search Products, which matches any word of it in the name or the description, as the Wix
|
|
3
|
+
// store's own search does (the One App "Studio Practice Towel" also finds "Studio Practice
|
|
4
|
+
// Journal"). The product list stays the screen's loaded scope; the server answer only says which
|
|
5
|
+
// of those products match and in what order, so sort, filters, prices and hearts are unchanged.
|
|
6
|
+
//
|
|
7
|
+
// Debounce lives in the field (`searchField.debounceMs`): the worker sandbox has no timers on
|
|
8
|
+
// every engine, so one `search` action is one request. Only the newest text owns the answer; an
|
|
9
|
+
// older one landing late is dropped.
|
|
10
|
+
//
|
|
11
|
+
// Offline, or when the request fails, the products whose name contains the text still show
|
|
12
|
+
// (the previous, on-device rule), and `unavailable` lets the screen say the search itself did not
|
|
13
|
+
// run, which is not the same as "nothing matches".
|
|
14
|
+
import { connectivity } from "@himalaya/state";
|
|
15
|
+
import { searchStoreProducts } from "./himi-store.js";
|
|
16
|
+
import type { Row } from "./himi-store-facets.js";
|
|
17
|
+
|
|
18
|
+
/** The server ranks the best matches first; the first page is the answer. A broad word in a large
|
|
19
|
+
* catalog can match more than this: the name matches all still show, the rest past Wix's top 100
|
|
20
|
+
* do not (as a paged search shows its first page). */
|
|
21
|
+
export const STORE_SEARCH_LIMIT = 100;
|
|
22
|
+
|
|
23
|
+
export interface StoreSearchMatch {
|
|
24
|
+
/** Exact name first, then the other names that contain the text, then the server's other matches in its order. */
|
|
25
|
+
rows: Row[];
|
|
26
|
+
/** The server answer for this text is on its way: the name matches show, "no matches" must not. */
|
|
27
|
+
searching: boolean;
|
|
28
|
+
/** The server search did not run (offline) or failed: only name matches show. */
|
|
29
|
+
unavailable: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Entry { key: string; status: "pending" | "ready" | "failed"; order?: Map<string, number> }
|
|
33
|
+
|
|
34
|
+
/** `onLanded` runs when the answer for the newest text lands or fails; the screen re-derives then. */
|
|
35
|
+
export function createStoreSearch(onLanded: () => void) {
|
|
36
|
+
let current: Entry | undefined;
|
|
37
|
+
|
|
38
|
+
/** The newest text's entry, starting its request when the text or the scope changed. */
|
|
39
|
+
function entryFor(scope: string, text: string): Entry | undefined {
|
|
40
|
+
const key = `${scope}\u0000${text.toLowerCase()}`;
|
|
41
|
+
if (current?.key === key) return current;
|
|
42
|
+
// Offline nothing is asked. Back online, the next derive asks (an edit, a refresh, or on Shop
|
|
43
|
+
// the reconnect recovery). A failed answer stays until `reset()`: asking again from derive
|
|
44
|
+
// would turn every failure into a request loop.
|
|
45
|
+
if (!connectivity().online) return undefined;
|
|
46
|
+
const entry: Entry = { key, status: "pending" };
|
|
47
|
+
current = entry;
|
|
48
|
+
void searchStoreProducts({ query: text, searchAllFields: true, limit: STORE_SEARCH_LIMIT, ...(scope ? { categoryId: scope } : {}) }).then(
|
|
49
|
+
(res) => {
|
|
50
|
+
entry.order = new Map();
|
|
51
|
+
for (const p of res.products ?? []) if (p.id && !entry.order.has(p.id)) entry.order.set(p.id, entry.order.size);
|
|
52
|
+
entry.status = "ready";
|
|
53
|
+
},
|
|
54
|
+
() => { entry.status = "failed"; },
|
|
55
|
+
).then(() => { if (current === entry) onLanded(); });
|
|
56
|
+
return entry;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
/** `rows` narrowed to `typed` (as typed; the match trims). `scope`: a category id, "" for the whole catalog. */
|
|
61
|
+
match(rows: Row[], scope: string, typed: string): StoreSearchMatch {
|
|
62
|
+
const text = typed.trim();
|
|
63
|
+
if (!text) return { rows, searching: false, unavailable: false };
|
|
64
|
+
const q = text.toLowerCase();
|
|
65
|
+
// Row names are lower-cased (toRows). An exact name is the product the shopper meant.
|
|
66
|
+
const named = rows.filter((r) => r.name === q).concat(rows.filter((r) => r.name !== q && r.name.includes(q)));
|
|
67
|
+
const entry = entryFor(scope, text);
|
|
68
|
+
if (entry?.status !== "ready") return { rows: named, searching: entry?.status === "pending", unavailable: entry?.status !== "pending" };
|
|
69
|
+
const order = entry.order!;
|
|
70
|
+
const shown = new Set(named);
|
|
71
|
+
const more = rows.filter((r) => !shown.has(r) && order.has(r.card.id)).sort((a, b) => order.get(a.card.id)! - order.get(b.card.id)!);
|
|
72
|
+
return { rows: named.concat(more), searching: false, unavailable: false };
|
|
73
|
+
},
|
|
74
|
+
/** Forget the answer (pull to refresh, a new session): the next match asks again. */
|
|
75
|
+
reset(): void { current = undefined; },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -9,6 +9,7 @@ import { detailInputId, presence, presenceAfterError, type PresenceFlags } from
|
|
|
9
9
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
10
10
|
import { FACETS_BOOT, PAGE_SIZE, applyFacets, currencyOf, facetActions, idOf, readViewPrefs, tagFields, toRows, toggleSaved, type FacetState } from "../_shared/himi-store-facets.js";
|
|
11
11
|
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
12
|
+
import { createStoreSearch } from "../_shared/himi-store-search.js";
|
|
12
13
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
13
14
|
|
|
14
15
|
interface State extends FacetState, PresenceFlags {
|
|
@@ -46,12 +47,18 @@ const products = createCollectionQuery<StoreProduct>({
|
|
|
46
47
|
},
|
|
47
48
|
}, () => { void svc.productsChanged(); });
|
|
48
49
|
|
|
50
|
+
// The search field asks Wix which of the category's products match (any word, name or
|
|
51
|
+
// description), like Shop; offline or on a failure, the names on the device.
|
|
52
|
+
const search = createStoreSearch(() => { void svc.searchLanded(); });
|
|
53
|
+
|
|
49
54
|
function derive(s: State): State {
|
|
50
55
|
const page = products.getState();
|
|
51
56
|
const source = s.found ? page.items : [];
|
|
52
|
-
const query = s.query.trim().toLowerCase();
|
|
53
57
|
const rows = toRows(source);
|
|
54
|
-
const
|
|
58
|
+
const found = search.match(rows, categoryId, s.found ? s.query : "");
|
|
59
|
+
const next = applyFacets(s, found.rows, source.map(currencyOf).find(Boolean));
|
|
60
|
+
// While Wix answers with no name match on screen yet, the skeleton, never "no matches".
|
|
61
|
+
const waiting = found.searching && next.matched === 0;
|
|
55
62
|
const pending = s.found && (page.status === "idle" || page.status === "loading" || page.loadingMore || (!!page.nextCursor && !page.pageError));
|
|
56
63
|
const firstError = s.found && page.status === "error";
|
|
57
64
|
const loaded = s.hasLoadedProducts || page.status === "ready";
|
|
@@ -68,12 +75,12 @@ function derive(s: State): State {
|
|
|
68
75
|
opt1Chips: next.opt1Chips.map(c => ({ ...c, selected: next.opt1Selected.includes(c.id) })),
|
|
69
76
|
opt2Chips: next.opt2Chips.map(c => ({ ...c, selected: next.opt2Selected.includes(c.id) })),
|
|
70
77
|
opt3Chips: next.opt3Chips.map(c => ({ ...c, selected: next.opt3Selected.includes(c.id) })),
|
|
71
|
-
countLabel: s.found && page.status === "ready" ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
78
|
+
countLabel: s.found && page.status === "ready" && !found.searching ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
72
79
|
// Searching a partially loaded category must not replace its content with
|
|
73
80
|
// a first-load skeleton just because the current pages have no match yet.
|
|
74
81
|
hasLoadedProducts: loaded,
|
|
75
|
-
isLoading: pending && !loaded,
|
|
76
|
-
notLoading: !(pending && !loaded),
|
|
82
|
+
isLoading: (pending && !loaded) || waiting,
|
|
83
|
+
notLoading: !(pending && !loaded) && !waiting,
|
|
77
84
|
nextCursor: next.nextCursor || (!scanning && !page.pageError ? page.nextCursor : ""),
|
|
78
85
|
noMore: next.noMore && (scanning || !page.nextCursor || page.pageError),
|
|
79
86
|
pendingProducts: pending,
|
|
@@ -81,8 +88,11 @@ function derive(s: State): State {
|
|
|
81
88
|
noPageError: !s.found || !page.pageError,
|
|
82
89
|
noRefreshError: !refreshFailed || !s.found || !loaded || page.pageError,
|
|
83
90
|
// A filtered first page isn't proof of no matches while later pages load.
|
|
84
|
-
noEmpty: !s.found || pending || firstError || page.pageError || next.results.length > 0,
|
|
85
|
-
|
|
91
|
+
noEmpty: !s.found || pending || waiting || firstError || page.pageError || next.results.length > 0,
|
|
92
|
+
// Offline or a failed search is not "nothing matches": say only the names were searched.
|
|
93
|
+
emptyText: found.unavailable && s.query.trim()
|
|
94
|
+
? copyTemplate("collection.searchUnavailable", "Search isn’t available right now. No product names match “{query}”.", { query: s.query.trim() })
|
|
95
|
+
: copyParam("collection.productsEmptyBody", "Try another search or browse a different category."),
|
|
86
96
|
};
|
|
87
97
|
}
|
|
88
98
|
|
|
@@ -112,6 +122,8 @@ const actions = {
|
|
|
112
122
|
stashCopy(arg);
|
|
113
123
|
// Hearts follow the signed-in member's account wishlist, read beside the products.
|
|
114
124
|
refreshSavedThen(() => svc.savedChanged());
|
|
125
|
+
// A load (onAppear, pull to refresh, the error banner) asks a failed search again.
|
|
126
|
+
search.reset();
|
|
115
127
|
const version = ++loadVersion;
|
|
116
128
|
const id = detailInputId();
|
|
117
129
|
if (!id) return derive({ ...s, ...presence("missing"), loadId: version });
|
|
@@ -155,6 +167,8 @@ const actions = {
|
|
|
155
167
|
});
|
|
156
168
|
},
|
|
157
169
|
productsChanged: (s: State) => s.loadId === loadVersion ? derive(s) : undefined,
|
|
170
|
+
// Wix answered the newest search text (an older text's answer never dispatches).
|
|
171
|
+
searchLanded: (s: State) => derive(s),
|
|
158
172
|
search: (s: State, arg?: { value?: string }) => derive({ ...s, query: (arg?.value ?? "").slice(0, 256), visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
|
|
159
173
|
toggleSave: async (s: State, arg?: unknown): Promise<State> => { try { await toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(svc.getState() as State); },
|
|
160
174
|
// The signed-in member's saved list landed: re-mark the hearts.
|
|
@@ -179,7 +193,7 @@ const actions = {
|
|
|
179
193
|
await products.loadMore();
|
|
180
194
|
return undefined;
|
|
181
195
|
},
|
|
182
|
-
retry: async () => { refreshFailed = false; await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
196
|
+
retry: async () => { refreshFailed = false; search.reset(); await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
183
197
|
};
|
|
184
198
|
const register = withIapPresentation<State>({
|
|
185
199
|
prefix: "category",
|
|
@@ -2646,6 +2646,10 @@
|
|
|
2646
2646
|
"source": "No products match “{query}”.",
|
|
2647
2647
|
"translation": "אין מוצרים שתואמים ל“{query}”."
|
|
2648
2648
|
},
|
|
2649
|
+
"h_30c8584bc33b": {
|
|
2650
|
+
"source": "Search isn’t available right now. No product names match “{query}”.",
|
|
2651
|
+
"translation": "החיפוש לא זמין כרגע. אין שמות מוצרים שתואמים ל“{query}”."
|
|
2652
|
+
},
|
|
2649
2653
|
"h_d00aa6043f90": {
|
|
2650
2654
|
"source": "No products match these filters.",
|
|
2651
2655
|
"translation": "אין מוצרים שתואמים למסננים האלה."
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The store search behind Branded Lite's Shop and category search fields: the text goes to Wix
|
|
2
|
+
// Search Products, which matches any word of it in the name or the description, as the Wix
|
|
3
|
+
// store's own search does (the One App "Studio Practice Towel" also finds "Studio Practice
|
|
4
|
+
// Journal"). The product list stays the screen's loaded scope; the server answer only says which
|
|
5
|
+
// of those products match and in what order, so sort, filters, prices and hearts are unchanged.
|
|
6
|
+
//
|
|
7
|
+
// Debounce lives in the field (`searchField.debounceMs`): the worker sandbox has no timers on
|
|
8
|
+
// every engine, so one `search` action is one request. Only the newest text owns the answer; an
|
|
9
|
+
// older one landing late is dropped.
|
|
10
|
+
//
|
|
11
|
+
// Offline, or when the request fails, the products whose name contains the text still show
|
|
12
|
+
// (the previous, on-device rule), and `unavailable` lets the screen say the search itself did not
|
|
13
|
+
// run, which is not the same as "nothing matches".
|
|
14
|
+
import { connectivity } from "@himalaya/state";
|
|
15
|
+
import { searchStoreProducts } from "./himi-store.js";
|
|
16
|
+
import type { Row } from "./himi-store-facets.js";
|
|
17
|
+
|
|
18
|
+
/** The server ranks the best matches first; the first page is the answer. A broad word in a large
|
|
19
|
+
* catalog can match more than this: the name matches all still show, the rest past Wix's top 100
|
|
20
|
+
* do not (as a paged search shows its first page). */
|
|
21
|
+
export const STORE_SEARCH_LIMIT = 100;
|
|
22
|
+
|
|
23
|
+
export interface StoreSearchMatch {
|
|
24
|
+
/** Exact name first, then the other names that contain the text, then the server's other matches in its order. */
|
|
25
|
+
rows: Row[];
|
|
26
|
+
/** The server answer for this text is on its way: the name matches show, "no matches" must not. */
|
|
27
|
+
searching: boolean;
|
|
28
|
+
/** The server search did not run (offline) or failed: only name matches show. */
|
|
29
|
+
unavailable: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Entry { key: string; status: "pending" | "ready" | "failed"; order?: Map<string, number> }
|
|
33
|
+
|
|
34
|
+
/** `onLanded` runs when the answer for the newest text lands or fails; the screen re-derives then. */
|
|
35
|
+
export function createStoreSearch(onLanded: () => void) {
|
|
36
|
+
let current: Entry | undefined;
|
|
37
|
+
|
|
38
|
+
/** The newest text's entry, starting its request when the text or the scope changed. */
|
|
39
|
+
function entryFor(scope: string, text: string): Entry | undefined {
|
|
40
|
+
const key = `${scope}\u0000${text.toLowerCase()}`;
|
|
41
|
+
if (current?.key === key) return current;
|
|
42
|
+
// Offline nothing is asked. Back online, the next derive asks (an edit, a refresh, or on Shop
|
|
43
|
+
// the reconnect recovery). A failed answer stays until `reset()`: asking again from derive
|
|
44
|
+
// would turn every failure into a request loop.
|
|
45
|
+
if (!connectivity().online) return undefined;
|
|
46
|
+
const entry: Entry = { key, status: "pending" };
|
|
47
|
+
current = entry;
|
|
48
|
+
void searchStoreProducts({ query: text, searchAllFields: true, limit: STORE_SEARCH_LIMIT, ...(scope ? { categoryId: scope } : {}) }).then(
|
|
49
|
+
(res) => {
|
|
50
|
+
entry.order = new Map();
|
|
51
|
+
for (const p of res.products ?? []) if (p.id && !entry.order.has(p.id)) entry.order.set(p.id, entry.order.size);
|
|
52
|
+
entry.status = "ready";
|
|
53
|
+
},
|
|
54
|
+
() => { entry.status = "failed"; },
|
|
55
|
+
).then(() => { if (current === entry) onLanded(); });
|
|
56
|
+
return entry;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
/** `rows` narrowed to `typed` (as typed; the match trims). `scope`: a category id, "" for the whole catalog. */
|
|
61
|
+
match(rows: Row[], scope: string, typed: string): StoreSearchMatch {
|
|
62
|
+
const text = typed.trim();
|
|
63
|
+
if (!text) return { rows, searching: false, unavailable: false };
|
|
64
|
+
const q = text.toLowerCase();
|
|
65
|
+
// Row names are lower-cased (toRows). An exact name is the product the shopper meant.
|
|
66
|
+
const named = rows.filter((r) => r.name === q).concat(rows.filter((r) => r.name !== q && r.name.includes(q)));
|
|
67
|
+
const entry = entryFor(scope, text);
|
|
68
|
+
if (entry?.status !== "ready") return { rows: named, searching: entry?.status === "pending", unavailable: entry?.status !== "pending" };
|
|
69
|
+
const order = entry.order!;
|
|
70
|
+
const shown = new Set(named);
|
|
71
|
+
const more = rows.filter((r) => !shown.has(r) && order.has(r.card.id)).sort((a, b) => order.get(a.card.id)! - order.get(b.card.id)!);
|
|
72
|
+
return { rows: named.concat(more), searching: false, unavailable: false };
|
|
73
|
+
},
|
|
74
|
+
/** Forget the answer (pull to refresh, a new session): the next match asks again. */
|
|
75
|
+
reset(): void { current = undefined; },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -9,6 +9,7 @@ import { detailInputId, presence, presenceAfterError, type PresenceFlags } from
|
|
|
9
9
|
import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
|
|
10
10
|
import { FACETS_BOOT, PAGE_SIZE, applyFacets, currencyOf, facetActions, idOf, readViewPrefs, tagFields, toRows, toggleSaved, type FacetState } from "../_shared/himi-store-facets.js";
|
|
11
11
|
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
12
|
+
import { createStoreSearch } from "../_shared/himi-store-search.js";
|
|
12
13
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
13
14
|
|
|
14
15
|
interface State extends FacetState, PresenceFlags {
|
|
@@ -46,12 +47,18 @@ const products = createCollectionQuery<StoreProduct>({
|
|
|
46
47
|
},
|
|
47
48
|
}, () => { void svc.productsChanged(); });
|
|
48
49
|
|
|
50
|
+
// The search field asks Wix which of the category's products match (any word, name or
|
|
51
|
+
// description), like Shop; offline or on a failure, the names on the device.
|
|
52
|
+
const search = createStoreSearch(() => { void svc.searchLanded(); });
|
|
53
|
+
|
|
49
54
|
function derive(s: State): State {
|
|
50
55
|
const page = products.getState();
|
|
51
56
|
const source = s.found ? page.items : [];
|
|
52
|
-
const query = s.query.trim().toLowerCase();
|
|
53
57
|
const rows = toRows(source);
|
|
54
|
-
const
|
|
58
|
+
const found = search.match(rows, categoryId, s.found ? s.query : "");
|
|
59
|
+
const next = applyFacets(s, found.rows, source.map(currencyOf).find(Boolean));
|
|
60
|
+
// While Wix answers with no name match on screen yet, the skeleton, never "no matches".
|
|
61
|
+
const waiting = found.searching && next.matched === 0;
|
|
55
62
|
const pending = s.found && (page.status === "idle" || page.status === "loading" || page.loadingMore || (!!page.nextCursor && !page.pageError));
|
|
56
63
|
const firstError = s.found && page.status === "error";
|
|
57
64
|
const loaded = s.hasLoadedProducts || page.status === "ready";
|
|
@@ -68,12 +75,12 @@ function derive(s: State): State {
|
|
|
68
75
|
opt1Chips: next.opt1Chips.map(c => ({ ...c, selected: next.opt1Selected.includes(c.id) })),
|
|
69
76
|
opt2Chips: next.opt2Chips.map(c => ({ ...c, selected: next.opt2Selected.includes(c.id) })),
|
|
70
77
|
opt3Chips: next.opt3Chips.map(c => ({ ...c, selected: next.opt3Selected.includes(c.id) })),
|
|
71
|
-
countLabel: s.found && page.status === "ready" ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
78
|
+
countLabel: s.found && page.status === "ready" && !found.searching ? copyTemplate("collection.resultCount", "{count} products", { count: next.matched }) : "",
|
|
72
79
|
// Searching a partially loaded category must not replace its content with
|
|
73
80
|
// a first-load skeleton just because the current pages have no match yet.
|
|
74
81
|
hasLoadedProducts: loaded,
|
|
75
|
-
isLoading: pending && !loaded,
|
|
76
|
-
notLoading: !(pending && !loaded),
|
|
82
|
+
isLoading: (pending && !loaded) || waiting,
|
|
83
|
+
notLoading: !(pending && !loaded) && !waiting,
|
|
77
84
|
nextCursor: next.nextCursor || (!scanning && !page.pageError ? page.nextCursor : ""),
|
|
78
85
|
noMore: next.noMore && (scanning || !page.nextCursor || page.pageError),
|
|
79
86
|
pendingProducts: pending,
|
|
@@ -81,8 +88,11 @@ function derive(s: State): State {
|
|
|
81
88
|
noPageError: !s.found || !page.pageError,
|
|
82
89
|
noRefreshError: !refreshFailed || !s.found || !loaded || page.pageError,
|
|
83
90
|
// A filtered first page isn't proof of no matches while later pages load.
|
|
84
|
-
noEmpty: !s.found || pending || firstError || page.pageError || next.results.length > 0,
|
|
85
|
-
|
|
91
|
+
noEmpty: !s.found || pending || waiting || firstError || page.pageError || next.results.length > 0,
|
|
92
|
+
// Offline or a failed search is not "nothing matches": say only the names were searched.
|
|
93
|
+
emptyText: found.unavailable && s.query.trim()
|
|
94
|
+
? copyTemplate("collection.searchUnavailable", "Search isn’t available right now. No product names match “{query}”.", { query: s.query.trim() })
|
|
95
|
+
: copyParam("collection.productsEmptyBody", "Try another search or browse a different category."),
|
|
86
96
|
};
|
|
87
97
|
}
|
|
88
98
|
|
|
@@ -112,6 +122,8 @@ const actions = {
|
|
|
112
122
|
stashCopy(arg);
|
|
113
123
|
// Hearts follow the signed-in member's account wishlist, read beside the products.
|
|
114
124
|
refreshSavedThen(() => svc.savedChanged());
|
|
125
|
+
// A load (onAppear, pull to refresh, the error banner) asks a failed search again.
|
|
126
|
+
search.reset();
|
|
115
127
|
const version = ++loadVersion;
|
|
116
128
|
const id = detailInputId();
|
|
117
129
|
if (!id) return derive({ ...s, ...presence("missing"), loadId: version });
|
|
@@ -155,6 +167,8 @@ const actions = {
|
|
|
155
167
|
});
|
|
156
168
|
},
|
|
157
169
|
productsChanged: (s: State) => s.loadId === loadVersion ? derive(s) : undefined,
|
|
170
|
+
// Wix answered the newest search text (an older text's answer never dispatches).
|
|
171
|
+
searchLanded: (s: State) => derive(s),
|
|
158
172
|
search: (s: State, arg?: { value?: string }) => derive({ ...s, query: (arg?.value ?? "").slice(0, 256), visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
|
|
159
173
|
toggleSave: async (s: State, arg?: unknown): Promise<State> => { try { await toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(svc.getState() as State); },
|
|
160
174
|
// The signed-in member's saved list landed: re-mark the hearts.
|
|
@@ -179,7 +193,7 @@ const actions = {
|
|
|
179
193
|
await products.loadMore();
|
|
180
194
|
return undefined;
|
|
181
195
|
},
|
|
182
|
-
retry: async () => { refreshFailed = false; await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
196
|
+
retry: async () => { refreshFailed = false; search.reset(); await products.retry(); await readRemaining(loadVersion); return undefined; },
|
|
183
197
|
};
|
|
184
198
|
const register = withIapPresentation<State>({
|
|
185
199
|
prefix: "category",
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
// of product cards with a saved-products heart, and a live cart count for the top bar.
|
|
5
5
|
//
|
|
6
6
|
// The scope is one category (or All), fetched from Wix; sort and filters then narrow
|
|
7
|
-
// it on the device (../_shared/himi-store-facets.ts). The search field
|
|
8
|
-
// the
|
|
9
|
-
//
|
|
7
|
+
// it on the device (../_shared/himi-store-facets.ts). The search field asks Wix which
|
|
8
|
+
// products of the scope match, by any word in the name or description, and falls back to
|
|
9
|
+
// the names on the device offline (../_shared/himi-store-search.ts). The first page paints
|
|
10
|
+
// as soon as it lands; later pages join it in the background.
|
|
10
11
|
//
|
|
11
12
|
// Opened with `category` = a category id or name; absent ⇒ All.
|
|
12
13
|
import { getCurrentCart } from "@himalaya/wix-ecom";
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
type FacetState, type Option, type Row,
|
|
22
23
|
} from "../_shared/himi-store-facets.js";
|
|
23
24
|
import { refreshSavedThen } from "../_shared/himi-store-saved.js";
|
|
25
|
+
import { createStoreSearch } from "../_shared/himi-store-search.js";
|
|
24
26
|
|
|
25
27
|
const ALL = "all";
|
|
26
28
|
const PAGE = 100;
|
|
@@ -43,7 +45,7 @@ interface S extends FacetState {
|
|
|
43
45
|
categorySelected: string;
|
|
44
46
|
/** The scope generation this state was derived for — see `committed`. */
|
|
45
47
|
scopeGen: number;
|
|
46
|
-
/** The search field's text; matches
|
|
48
|
+
/** The search field's text; Wix matches it within the category (names on the device offline). */
|
|
47
49
|
query: string;
|
|
48
50
|
/** The chip row: All plus one chip per store category, with its selected state. */
|
|
49
51
|
categoryOptions: Option[];
|
|
@@ -169,21 +171,26 @@ function reconcileCategories(): { invalidatedSelection: boolean; intentVersion:
|
|
|
169
171
|
return { invalidatedSelection, intentVersion: categoryIntentVersion };
|
|
170
172
|
}
|
|
171
173
|
|
|
174
|
+
/** The answer for the newest search text landed (or failed): re-derive the page as it is now. */
|
|
175
|
+
const search = createStoreSearch(() => { void svc.searchLanded(); });
|
|
176
|
+
|
|
172
177
|
function derive(s: S): S {
|
|
173
178
|
// The field keeps exactly what the shopper typed (a trailing space included); the match trims.
|
|
174
179
|
const typed = s.query.trim();
|
|
175
|
-
const
|
|
176
|
-
const next = applyFacets(s,
|
|
180
|
+
const found = search.match(rows, s.categorySelected === ALL ? "" : s.categorySelected, s.query);
|
|
181
|
+
const next = applyFacets(s, found.rows, currency);
|
|
177
182
|
const n = next.matched;
|
|
178
|
-
|
|
183
|
+
// While Wix answers, the name matches show; with none yet, the skeleton, never "no matches".
|
|
184
|
+
const waiting = found.searching && n === 0;
|
|
185
|
+
const ready = s.status === "ready" && !waiting;
|
|
179
186
|
const readMessage = !s.readStatus.hasSnapshot && s.readStatus.offline
|
|
180
187
|
? "This content isn’t available offline. Connect to load it."
|
|
181
188
|
: s.readStatus.error || "";
|
|
182
189
|
const choices = [{ id: ALL, label: copyParam("shop.allChip", "All") }, ...categories.map((c) => ({ id: c.id, label: c.name }))];
|
|
183
190
|
return {
|
|
184
191
|
...next,
|
|
185
|
-
isLoading: s.status === "loading",
|
|
186
|
-
notLoading: s.status !== "loading",
|
|
192
|
+
isLoading: s.status === "loading" || waiting,
|
|
193
|
+
notLoading: s.status !== "loading" && !waiting,
|
|
187
194
|
isErrored: s.status === "error",
|
|
188
195
|
notErrored: s.status !== "error",
|
|
189
196
|
// The shared shell owns offline/stale messages; this former local-DB note stays hidden.
|
|
@@ -191,10 +198,14 @@ function derive(s: S): S {
|
|
|
191
198
|
readMessage, noReadMessage: !readMessage, hasReadMessage: !!readMessage,
|
|
192
199
|
categoryOptions: choices.map((c) => option(c, c.id === s.categorySelected)),
|
|
193
200
|
hideCategories: categories.length === 0,
|
|
194
|
-
|
|
201
|
+
// A count that grows when the answer lands would read as a wrong count: none until then.
|
|
202
|
+
countLabel: ready && !found.searching ? countText(n) : "",
|
|
195
203
|
noEmpty: !ready || n > 0,
|
|
204
|
+
// Offline or a failed search is not "nothing matches": say only the names were searched.
|
|
196
205
|
emptyText: typed
|
|
197
|
-
?
|
|
206
|
+
? found.unavailable
|
|
207
|
+
? copyTemplate("shop.searchUnavailable", "Search isn’t available right now. No product names match “{query}”.", { query: typed })
|
|
208
|
+
: copyTemplate("shop.noQueryMatch", "No products match “{query}”.", { query: typed })
|
|
198
209
|
: next.activeFilters
|
|
199
210
|
? copyParam("shop.noMatchText", "No products match these filters.")
|
|
200
211
|
: s.categorySelected !== ALL
|
|
@@ -613,7 +624,7 @@ const BOOT: S = derive({
|
|
|
613
624
|
});
|
|
614
625
|
|
|
615
626
|
const facets = facetActions<S>(derive);
|
|
616
|
-
const CONTENT = ["readChanged", "load", "refresh", "retry", "loaded", "scopeLanded", "scopeGrew", "selectCategory", "search", "toggleSave", "loadMore", ...Object.keys(facets)];
|
|
627
|
+
const CONTENT = ["readChanged", "load", "refresh", "retry", "loaded", "scopeLanded", "scopeGrew", "selectCategory", "search", "searchLanded", "toggleSave", "loadMore", ...Object.keys(facets)];
|
|
617
628
|
const register = withIapPresentation<S>({
|
|
618
629
|
// Restored from the last run, these painted a state this boot has not reached: a count over
|
|
619
630
|
// no cards, an open sheet, a stale scope generation that defeats `committed`, a search
|
|
@@ -677,12 +688,15 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
|
|
|
677
688
|
load: (s, arg) => load(s, arg),
|
|
678
689
|
// Pull to refresh: the categories and the scope again, from Wix.
|
|
679
690
|
refresh: async (s, arg) => {
|
|
691
|
+
// A pull to refresh asks the search again too (a failed one gets its retry here).
|
|
692
|
+
search.reset();
|
|
680
693
|
const next = await load(s, arg, true);
|
|
681
694
|
// The result owns its scope; another action may have changed the globals during load.
|
|
682
695
|
return next ? settledWithin(next, next.categorySelected, next.scopeGen) : undefined;
|
|
683
696
|
},
|
|
684
|
-
|
|
685
|
-
|
|
697
|
+
// Retry and reconnect recovery ask a failed search again too, like a pull to refresh.
|
|
698
|
+
retry: (s) => { search.reset(); return settledWithin(showScope(s, s.categorySelected, true), s.categorySelected, generation); },
|
|
699
|
+
recover: async () => { search.reset(); await fetchScope(selectedCategory, generation, true); return undefined; },
|
|
686
700
|
readChanged: (s, arg) => {
|
|
687
701
|
if (!arg || typeof arg !== 'object') return undefined;
|
|
688
702
|
const value = arg as { gen: number; category: string; readStatus: ReadStatus };
|
|
@@ -736,6 +750,8 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
|
|
|
736
750
|
if (query === s.query) return s;
|
|
737
751
|
return derive({ ...s, query, ...(query.trim() === s.query.trim() ? {} : { visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }) });
|
|
738
752
|
},
|
|
753
|
+
// Wix answered the newest search text (an older text's answer never dispatches).
|
|
754
|
+
searchLanded: (s) => derive(s),
|
|
739
755
|
toggleSave: async (s, arg): Promise<S> => {
|
|
740
756
|
try { await toggleSaved(s.results, idOf(arg)); } catch { return s; }
|
|
741
757
|
// The page as it is now: other actions may have run while the save was on the wire.
|
|
@@ -755,6 +771,7 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
|
|
|
755
771
|
rows = []; currency = undefined; categories = []; categoriesAuthoritative = false;
|
|
756
772
|
scopes.clear(); pendingScopes.clear(); pendingRefreshScopes.clear();
|
|
757
773
|
loadedCartCount = 0; pendingAuxiliary = undefined; pendingCategoriesRead = undefined;
|
|
774
|
+
search.reset();
|
|
758
775
|
void svc.identityChanged();
|
|
759
776
|
});
|
|
760
777
|
svc.load();
|