@wovvmap/ui-headless 0.0.0-stage → 1.2.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/README.md +24 -2
- package/dist/HeaderInfoController.d.ts +44 -0
- package/dist/HeaderInfoController.d.ts.map +1 -0
- package/dist/HeaderInfoController.js +112 -0
- package/dist/appearance.d.ts +26 -0
- package/dist/appearance.d.ts.map +1 -0
- package/dist/appearance.js +117 -0
- package/dist/classic/ClassicController.d.ts +124 -0
- package/dist/classic/ClassicController.d.ts.map +1 -0
- package/dist/classic/ClassicController.js +1131 -0
- package/dist/classic/classic.types.d.ts +111 -0
- package/dist/classic/classic.types.d.ts.map +1 -0
- package/dist/classic/classic.types.js +1 -0
- package/dist/classic/index.d.ts +3 -0
- package/dist/classic/index.d.ts.map +1 -0
- package/dist/classic/index.js +2 -0
- package/dist/components.d.ts +253 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +30 -0
- package/dist/directions/DirectionController.d.ts +76 -0
- package/dist/directions/DirectionController.d.ts.map +1 -0
- package/dist/directions/DirectionController.js +467 -0
- package/dist/directions/direction.types.d.ts +81 -0
- package/dist/directions/direction.types.d.ts.map +1 -0
- package/dist/directions/direction.types.js +1 -0
- package/dist/directions/directionPresentation.d.ts +17 -0
- package/dist/directions/directionPresentation.d.ts.map +1 -0
- package/dist/directions/directionPresentation.js +34 -0
- package/dist/flow/DiscoveryFlowController.d.ts +36 -0
- package/dist/flow/DiscoveryFlowController.d.ts.map +1 -0
- package/dist/flow/DiscoveryFlowController.js +162 -0
- package/dist/flow/FlowHistoryController.d.ts +14 -0
- package/dist/flow/FlowHistoryController.d.ts.map +1 -0
- package/dist/flow/FlowHistoryController.js +31 -0
- package/dist/flow/index.d.ts +3 -0
- package/dist/flow/index.d.ts.map +1 -0
- package/dist/flow/index.js +2 -0
- package/dist/gallery/PromotionGalleryController.d.ts +32 -0
- package/dist/gallery/PromotionGalleryController.d.ts.map +1 -0
- package/dist/gallery/PromotionGalleryController.js +80 -0
- package/dist/gallery/index.d.ts +2 -0
- package/dist/gallery/index.d.ts.map +1 -0
- package/dist/gallery/index.js +1 -0
- package/dist/headerInfo.d.ts +27 -0
- package/dist/headerInfo.d.ts.map +1 -0
- package/dist/headerInfo.js +70 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/presentation.d.ts +49 -0
- package/dist/presentation.d.ts.map +1 -0
- package/dist/presentation.js +116 -0
- package/dist/routes/RoutePreviewController.d.ts +61 -0
- package/dist/routes/RoutePreviewController.d.ts.map +1 -0
- package/dist/routes/RoutePreviewController.js +321 -0
- package/dist/routes/playback/RoutePlaybackController.d.ts +26 -0
- package/dist/routes/playback/RoutePlaybackController.d.ts.map +1 -0
- package/dist/routes/playback/RoutePlaybackController.js +115 -0
- package/dist/routes/routePlayback.types.d.ts +38 -0
- package/dist/routes/routePlayback.types.d.ts.map +1 -0
- package/dist/routes/routePlayback.types.js +1 -0
- package/dist/routes/routePreview.types.d.ts +71 -0
- package/dist/routes/routePreview.types.d.ts.map +1 -0
- package/dist/routes/routePreview.types.js +1 -0
- package/dist/routes/routePreviewPresentation.d.ts +8 -0
- package/dist/routes/routePreviewPresentation.d.ts.map +1 -0
- package/dist/routes/routePreviewPresentation.js +26 -0
- package/dist/routes/routeStepIcons.d.ts +15 -0
- package/dist/routes/routeStepIcons.d.ts.map +1 -0
- package/dist/routes/routeStepIcons.js +102 -0
- package/dist/routes/routeStepPresentation.d.ts +5 -0
- package/dist/routes/routeStepPresentation.d.ts.map +1 -0
- package/dist/routes/routeStepPresentation.js +15 -0
- package/dist/routes/routeSteps.types.d.ts +51 -0
- package/dist/routes/routeSteps.types.d.ts.map +1 -0
- package/dist/routes/routeSteps.types.js +1 -0
- package/dist/routes/steps/RouteStepsController.d.ts +49 -0
- package/dist/routes/steps/RouteStepsController.d.ts.map +1 -0
- package/dist/routes/steps/RouteStepsController.js +312 -0
- package/dist/saved-routes/SavedRoutesController.d.ts +76 -0
- package/dist/saved-routes/SavedRoutesController.d.ts.map +1 -0
- package/dist/saved-routes/SavedRoutesController.js +366 -0
- package/dist/storeHours.d.ts +19 -0
- package/dist/storeHours.d.ts.map +1 -0
- package/dist/storeHours.js +155 -0
- package/dist/storeList.d.ts +19 -0
- package/dist/storeList.d.ts.map +1 -0
- package/dist/storeList.js +21 -0
- package/dist/theme.d.ts +42 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +56 -0
- package/package.json +32 -3
|
@@ -0,0 +1,1131 @@
|
|
|
1
|
+
import { toViewerCommandError } from '@wovvmap/contracts';
|
|
2
|
+
import { DiscoveryFlowController } from '../flow/index.js';
|
|
3
|
+
import { DirectionController } from '../directions/DirectionController.js';
|
|
4
|
+
import { resolveViewerAppearance } from '../appearance.js';
|
|
5
|
+
const initialIntent = {
|
|
6
|
+
ready: false,
|
|
7
|
+
screen: 'home',
|
|
8
|
+
rootTab: 'categories',
|
|
9
|
+
category: null,
|
|
10
|
+
subcategory: null,
|
|
11
|
+
amenity: null,
|
|
12
|
+
offers: false,
|
|
13
|
+
hasOffers: false,
|
|
14
|
+
offersError: null,
|
|
15
|
+
detailKey: null,
|
|
16
|
+
group: null,
|
|
17
|
+
members: null,
|
|
18
|
+
membersLoading: false,
|
|
19
|
+
membersError: null,
|
|
20
|
+
actionError: null,
|
|
21
|
+
};
|
|
22
|
+
const message = (error) => error instanceof Error ? error.message : 'Unable to complete this action';
|
|
23
|
+
const sameId = (left, right) => left !== undefined && String(left) === String(right);
|
|
24
|
+
/** Per-instance Classic presentation coordinator, using existing indexed SDK channels.
|
|
25
|
+
* Hinglish: Panel aur clicks ka ek owner; search/index/filter implementation SDK mein hi hai. */
|
|
26
|
+
export class ClassicController {
|
|
27
|
+
viewer;
|
|
28
|
+
directions;
|
|
29
|
+
flow;
|
|
30
|
+
listScrollOffset = 0;
|
|
31
|
+
stores;
|
|
32
|
+
categories;
|
|
33
|
+
subcategories;
|
|
34
|
+
amenities;
|
|
35
|
+
listeners = new Set();
|
|
36
|
+
intent = initialIntent;
|
|
37
|
+
map = null;
|
|
38
|
+
snapshot;
|
|
39
|
+
previousScreen = 'home';
|
|
40
|
+
listReturnScreen = 'home';
|
|
41
|
+
requestId = 0;
|
|
42
|
+
offerRequestId = 0;
|
|
43
|
+
catalogEpoch = 0;
|
|
44
|
+
pendingCatalogRefresh = false;
|
|
45
|
+
memberRequestId = 0;
|
|
46
|
+
selectionRequestId = 0;
|
|
47
|
+
pendingSelection = null;
|
|
48
|
+
pendingClears = new Set();
|
|
49
|
+
filterRequestId = 0;
|
|
50
|
+
pendingFilterRequest = null;
|
|
51
|
+
themeRequestId = 0;
|
|
52
|
+
controlRequestId = 0;
|
|
53
|
+
connectionId = 0;
|
|
54
|
+
constructor(viewer) {
|
|
55
|
+
this.viewer = viewer;
|
|
56
|
+
this.stores = viewer.discovery.getChannel('general', 'stores');
|
|
57
|
+
this.categories = viewer.discovery.getChannel('classic:categories', 'categories');
|
|
58
|
+
this.subcategories = viewer.discovery.getChannel('classic:subcategories', 'subcategories');
|
|
59
|
+
this.amenities = viewer.discovery.getChannel('classic:amenities', 'amenities');
|
|
60
|
+
this.flow =
|
|
61
|
+
viewer.getInteractionState && viewer.restoreInteractionState
|
|
62
|
+
? new DiscoveryFlowController({
|
|
63
|
+
getInteractionState: viewer.getInteractionState,
|
|
64
|
+
restoreInteractionState: viewer.restoreInteractionState,
|
|
65
|
+
}, (a, b) => JSON.stringify([
|
|
66
|
+
a.screen,
|
|
67
|
+
a.directionOpen,
|
|
68
|
+
a.rootTab,
|
|
69
|
+
a.category?.code,
|
|
70
|
+
a.subcategory?.code,
|
|
71
|
+
a.amenity?.id,
|
|
72
|
+
a.offers,
|
|
73
|
+
a.detailKey,
|
|
74
|
+
a.group?.groupId,
|
|
75
|
+
a.group?.index,
|
|
76
|
+
a.query,
|
|
77
|
+
a.sort,
|
|
78
|
+
]) ===
|
|
79
|
+
JSON.stringify([
|
|
80
|
+
b.screen,
|
|
81
|
+
b.directionOpen,
|
|
82
|
+
b.rootTab,
|
|
83
|
+
b.category?.code,
|
|
84
|
+
b.subcategory?.code,
|
|
85
|
+
b.amenity?.id,
|
|
86
|
+
b.offers,
|
|
87
|
+
b.detailKey,
|
|
88
|
+
b.group?.groupId,
|
|
89
|
+
b.group?.index,
|
|
90
|
+
b.query,
|
|
91
|
+
b.sort,
|
|
92
|
+
]))
|
|
93
|
+
: null;
|
|
94
|
+
this.directions = viewer.direction
|
|
95
|
+
? new DirectionController({ ...viewer.direction, discovery: viewer.discovery }, {
|
|
96
|
+
enter: async () => {
|
|
97
|
+
this.selectionRequestId++;
|
|
98
|
+
this.pendingSelection = null;
|
|
99
|
+
if (!this.flow)
|
|
100
|
+
return true;
|
|
101
|
+
const entered = await this.flow.enter(this.captureFlowContext(), () => ({
|
|
102
|
+
...this.captureFlowContext(),
|
|
103
|
+
directionOpen: true,
|
|
104
|
+
}));
|
|
105
|
+
this.publish();
|
|
106
|
+
return entered;
|
|
107
|
+
},
|
|
108
|
+
back: (context) => this.restoreBack(true, context),
|
|
109
|
+
})
|
|
110
|
+
: null;
|
|
111
|
+
this.snapshot = this.readSnapshot();
|
|
112
|
+
}
|
|
113
|
+
getSnapshot = () => this.snapshot;
|
|
114
|
+
subscribe = (listener) => {
|
|
115
|
+
this.listeners.add(listener);
|
|
116
|
+
return () => this.listeners.delete(listener);
|
|
117
|
+
};
|
|
118
|
+
/** Mount subscriptions only; an immediate StrictMode reconnect keeps the committed query.
|
|
119
|
+
* Hinglish: Hooks sirf lifetime bind karte hain; StrictMode replay map/query ko reset nahi karta. */
|
|
120
|
+
connect = () => {
|
|
121
|
+
const connection = ++this.connectionId;
|
|
122
|
+
const unsubscribe = [
|
|
123
|
+
...(this.directions ? [this.directions.connect()] : []),
|
|
124
|
+
this.stores.subscribe(this.publish),
|
|
125
|
+
this.categories.subscribe(this.publish),
|
|
126
|
+
this.subcategories.subscribe(this.publish),
|
|
127
|
+
this.amenities.subscribe(this.publish),
|
|
128
|
+
];
|
|
129
|
+
return () => {
|
|
130
|
+
for (const stop of unsubscribe)
|
|
131
|
+
stop();
|
|
132
|
+
queueMicrotask(() => {
|
|
133
|
+
if (connection !== this.connectionId)
|
|
134
|
+
return;
|
|
135
|
+
this.flow?.reset();
|
|
136
|
+
this.requestId++;
|
|
137
|
+
this.memberRequestId++;
|
|
138
|
+
this.selectionRequestId++;
|
|
139
|
+
this.pendingSelection = null;
|
|
140
|
+
this.pendingClears.clear();
|
|
141
|
+
this.filterRequestId++;
|
|
142
|
+
this.pendingFilterRequest = null;
|
|
143
|
+
this.themeRequestId++;
|
|
144
|
+
this.controlRequestId++;
|
|
145
|
+
this.stores.cancel();
|
|
146
|
+
this.categories.cancel();
|
|
147
|
+
this.subcategories.cancel();
|
|
148
|
+
this.amenities.cancel();
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
/** A committed map identity initializes footer reads once. Temporary readiness loss does not replay.
|
|
153
|
+
* Hinglish: Naye committed map par hi reads init hoti hain; context restore par repeat nahi. */
|
|
154
|
+
syncMap = (map, ready) => {
|
|
155
|
+
this.directions?.syncMap(map, ready);
|
|
156
|
+
const usable = ready && map !== null;
|
|
157
|
+
if (this.intent.ready !== usable)
|
|
158
|
+
this.update({ ready: usable });
|
|
159
|
+
if (!usable) {
|
|
160
|
+
if (map === null && this.map !== null) {
|
|
161
|
+
this.flow?.reset();
|
|
162
|
+
this.pendingCatalogRefresh = false;
|
|
163
|
+
this.map = null;
|
|
164
|
+
this.publish();
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (map === this.map) {
|
|
169
|
+
if (this.pendingCatalogRefresh)
|
|
170
|
+
this.refreshCatalogPresentation();
|
|
171
|
+
else if (this.pendingFilterRequest === null && this.viewer.getDiscoveryFilter)
|
|
172
|
+
this.handleDiscoveryChanged(this.viewer.getDiscoveryFilter());
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.flow?.reset();
|
|
176
|
+
this.listScrollOffset = 0;
|
|
177
|
+
this.map = map;
|
|
178
|
+
this.pendingCatalogRefresh = false;
|
|
179
|
+
++this.requestId;
|
|
180
|
+
this.memberRequestId++;
|
|
181
|
+
this.selectionRequestId++;
|
|
182
|
+
this.pendingSelection = null;
|
|
183
|
+
this.pendingClears.clear();
|
|
184
|
+
this.filterRequestId++;
|
|
185
|
+
this.pendingFilterRequest = null;
|
|
186
|
+
this.themeRequestId++;
|
|
187
|
+
this.controlRequestId++;
|
|
188
|
+
this.previousScreen = 'home';
|
|
189
|
+
this.listReturnScreen = 'home';
|
|
190
|
+
this.intent = { ...initialIntent, ready: true };
|
|
191
|
+
this.stores.reset('stores');
|
|
192
|
+
this.subcategories.reset('subcategories');
|
|
193
|
+
void this.categories.execute({ target: 'categories', pageSize: 20, sortBy: 'asc' }, { immediate: true });
|
|
194
|
+
void this.amenities.execute({ target: 'amenities', pageSize: 20, sortBy: 'asc' }, { immediate: true });
|
|
195
|
+
this.refreshOffers();
|
|
196
|
+
if (this.viewer.getDiscoveryFilter)
|
|
197
|
+
this.handleDiscoveryChanged(this.viewer.getDiscoveryFilter());
|
|
198
|
+
this.publish();
|
|
199
|
+
};
|
|
200
|
+
openNodeDirections = (node) => {
|
|
201
|
+
this.directions?.open({ kind: 'node', key: node.key });
|
|
202
|
+
};
|
|
203
|
+
openGroupDirections = (group) => {
|
|
204
|
+
this.directions?.open({
|
|
205
|
+
kind: 'group',
|
|
206
|
+
request: this.stores.getGroupSelectionRequest(group.groupId),
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
openSearch = () => {
|
|
210
|
+
if (!this.intent.ready)
|
|
211
|
+
return;
|
|
212
|
+
const flowRequest = this.beginFlow();
|
|
213
|
+
this.directions?.close();
|
|
214
|
+
this.clearDetail(false, !this.viewer.setDiscoveryFilter);
|
|
215
|
+
this.listReturnScreen = 'search';
|
|
216
|
+
const hadFilter = this.intent.category ||
|
|
217
|
+
this.intent.amenity ||
|
|
218
|
+
this.intent.offers ||
|
|
219
|
+
this.stores.getSnapshot().filter;
|
|
220
|
+
this.update({
|
|
221
|
+
screen: 'search',
|
|
222
|
+
category: null,
|
|
223
|
+
subcategory: null,
|
|
224
|
+
amenity: null,
|
|
225
|
+
offers: false,
|
|
226
|
+
});
|
|
227
|
+
this.syncFilter(flowRequest);
|
|
228
|
+
if (hadFilter || this.stores.getSnapshot().status === 'idle')
|
|
229
|
+
this.queryStores('');
|
|
230
|
+
};
|
|
231
|
+
closeSearch = () => {
|
|
232
|
+
this.directions?.close();
|
|
233
|
+
if (!this.intent.ready)
|
|
234
|
+
return;
|
|
235
|
+
this.flow?.reset();
|
|
236
|
+
this.clearDetail(false, !this.viewer.setDiscoveryFilter);
|
|
237
|
+
this.listReturnScreen = 'home';
|
|
238
|
+
this.update({
|
|
239
|
+
screen: 'home',
|
|
240
|
+
category: null,
|
|
241
|
+
subcategory: null,
|
|
242
|
+
amenity: null,
|
|
243
|
+
offers: false,
|
|
244
|
+
actionError: null,
|
|
245
|
+
});
|
|
246
|
+
this.syncFilter();
|
|
247
|
+
this.stores.reset('stores');
|
|
248
|
+
this.refreshCategories();
|
|
249
|
+
};
|
|
250
|
+
changeQuery = (query) => {
|
|
251
|
+
if (!this.intent.ready)
|
|
252
|
+
return;
|
|
253
|
+
if (this.intent.amenity)
|
|
254
|
+
this.openSearch();
|
|
255
|
+
this.clearDetail();
|
|
256
|
+
this.update({ screen: 'search' });
|
|
257
|
+
this.queryStores(query);
|
|
258
|
+
};
|
|
259
|
+
changeSort = (sort) => {
|
|
260
|
+
if (!this.intent.ready)
|
|
261
|
+
return;
|
|
262
|
+
if (this.intent.group?.index !== undefined)
|
|
263
|
+
this.clearDetail(false, false);
|
|
264
|
+
// A new order starts at the top; history must not restore the previous order's scroll offset.
|
|
265
|
+
// Hinglish: Sort badle to list shuru se dikhe; purane order ka beech wala scroll na bache.
|
|
266
|
+
this.listScrollOffset = 0;
|
|
267
|
+
void this.stores.setSortBy(sort, undefined, { immediate: true });
|
|
268
|
+
};
|
|
269
|
+
selectRootTab = (tab) => {
|
|
270
|
+
this.directions?.close();
|
|
271
|
+
if (!this.intent.ready || tab === this.intent.rootTab)
|
|
272
|
+
return;
|
|
273
|
+
this.closeSearch();
|
|
274
|
+
this.update({ rootTab: tab });
|
|
275
|
+
};
|
|
276
|
+
selectCategory = (category) => {
|
|
277
|
+
if (!this.intent.ready)
|
|
278
|
+
return;
|
|
279
|
+
const flowRequest = this.beginFlow();
|
|
280
|
+
this.directions?.close();
|
|
281
|
+
this.clearDetail(false, !this.viewer.setDiscoveryFilter);
|
|
282
|
+
const deselect = sameId(this.intent.category?.code, category.code);
|
|
283
|
+
this.update({
|
|
284
|
+
category: deselect ? null : category,
|
|
285
|
+
subcategory: null,
|
|
286
|
+
amenity: null,
|
|
287
|
+
rootTab: 'categories',
|
|
288
|
+
screen: deselect && !this.intent.offers ? 'home' : 'results',
|
|
289
|
+
});
|
|
290
|
+
this.syncFilter(flowRequest);
|
|
291
|
+
if (this.intent.screen === 'home')
|
|
292
|
+
this.stores.reset('stores');
|
|
293
|
+
else
|
|
294
|
+
this.queryStores('');
|
|
295
|
+
if (deselect)
|
|
296
|
+
this.refreshCategories();
|
|
297
|
+
else
|
|
298
|
+
this.refreshSubcategories();
|
|
299
|
+
};
|
|
300
|
+
selectSubcategory = (subcategory) => {
|
|
301
|
+
if (!this.intent.ready || !sameId(this.intent.category?.code, subcategory.categoryCode))
|
|
302
|
+
return;
|
|
303
|
+
const flowRequest = this.beginFlow();
|
|
304
|
+
this.directions?.close();
|
|
305
|
+
this.clearDetail(false, !this.viewer.setDiscoveryFilter);
|
|
306
|
+
this.update({
|
|
307
|
+
subcategory: sameId(this.intent.subcategory?.code, subcategory.code) ? null : subcategory,
|
|
308
|
+
screen: 'results',
|
|
309
|
+
});
|
|
310
|
+
this.syncFilter(flowRequest);
|
|
311
|
+
this.queryStores('');
|
|
312
|
+
};
|
|
313
|
+
selectAmenity = (amenity) => {
|
|
314
|
+
if (!this.intent.ready)
|
|
315
|
+
return;
|
|
316
|
+
const deselect = sameId(this.intent.amenity?.id, amenity.id);
|
|
317
|
+
if (!deselect && (amenity.status === 0 || amenity.memberCount === 0))
|
|
318
|
+
return;
|
|
319
|
+
const flowRequest = this.beginFlow();
|
|
320
|
+
this.directions?.close();
|
|
321
|
+
this.clearDetail(false, !this.viewer.setDiscoveryFilter);
|
|
322
|
+
this.previousScreen = 'home';
|
|
323
|
+
this.listReturnScreen = 'home';
|
|
324
|
+
this.update({
|
|
325
|
+
screen: deselect ? 'home' : 'amenity',
|
|
326
|
+
rootTab: 'amenities',
|
|
327
|
+
category: null,
|
|
328
|
+
subcategory: null,
|
|
329
|
+
amenity: deselect ? null : amenity,
|
|
330
|
+
offers: false,
|
|
331
|
+
});
|
|
332
|
+
this.stores.reset('stores');
|
|
333
|
+
this.syncFilter(flowRequest);
|
|
334
|
+
// The shared SDK resolves every amenity member and any required floor switch, not a stores query.
|
|
335
|
+
// Hinglish: Membership aur floor ka owner SDK hai; UI fake store/member lookup nahi karti.
|
|
336
|
+
};
|
|
337
|
+
toggleOffers = () => {
|
|
338
|
+
if (!this.intent.ready || (!this.intent.hasOffers && !this.intent.offers))
|
|
339
|
+
return;
|
|
340
|
+
const flowRequest = this.beginFlow();
|
|
341
|
+
this.directions?.close();
|
|
342
|
+
this.clearDetail(false, !this.viewer.setDiscoveryFilter);
|
|
343
|
+
const offers = !this.intent.offers;
|
|
344
|
+
this.update({
|
|
345
|
+
offers,
|
|
346
|
+
amenity: null,
|
|
347
|
+
rootTab: 'categories',
|
|
348
|
+
screen: offers || this.intent.category ? 'results' : 'home',
|
|
349
|
+
});
|
|
350
|
+
this.syncFilter(flowRequest);
|
|
351
|
+
if (this.intent.screen === 'home')
|
|
352
|
+
this.stores.reset('stores');
|
|
353
|
+
else
|
|
354
|
+
this.queryStores('');
|
|
355
|
+
if (this.intent.category)
|
|
356
|
+
this.refreshSubcategories();
|
|
357
|
+
else
|
|
358
|
+
this.refreshCategories();
|
|
359
|
+
};
|
|
360
|
+
selectRow = (row) => {
|
|
361
|
+
if (!this.intent.ready)
|
|
362
|
+
return;
|
|
363
|
+
if (row.kind === 'store')
|
|
364
|
+
this.selectMember(row.node);
|
|
365
|
+
else {
|
|
366
|
+
const flowRequest = this.beginFlow();
|
|
367
|
+
if (this.intent.screen === 'search' ||
|
|
368
|
+
this.intent.screen === 'results' ||
|
|
369
|
+
this.intent.screen === 'home') {
|
|
370
|
+
this.previousScreen = this.intent.screen;
|
|
371
|
+
this.listReturnScreen = this.previousScreen;
|
|
372
|
+
}
|
|
373
|
+
this.clearDetail(false, false);
|
|
374
|
+
this.update({
|
|
375
|
+
screen: 'group',
|
|
376
|
+
group: { groupId: row.group.groupId, name: row.group.name, summary: row.group },
|
|
377
|
+
detailKey: null,
|
|
378
|
+
members: null,
|
|
379
|
+
membersLoading: false,
|
|
380
|
+
membersError: null,
|
|
381
|
+
});
|
|
382
|
+
this.selectGroup(row.group.groupId, row.group.representative, flowRequest);
|
|
383
|
+
void this.readMembers(0);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
/** Expansion is a separate click intent; it never selects a node or moves the camera.
|
|
387
|
+
* Hinglish: Chevron sirf inline locations kholta hai; main row aur member click alag hain. */
|
|
388
|
+
toggleGroup = (row, index) => {
|
|
389
|
+
if (!this.intent.ready || row.kind !== 'group')
|
|
390
|
+
return;
|
|
391
|
+
const collapse = this.intent.group?.groupId === row.group.groupId && this.intent.group.index === index;
|
|
392
|
+
this.clearDetail(false, false);
|
|
393
|
+
if (collapse)
|
|
394
|
+
return;
|
|
395
|
+
this.update({
|
|
396
|
+
group: { groupId: row.group.groupId, name: row.group.name, summary: row.group, index },
|
|
397
|
+
});
|
|
398
|
+
void this.readMembers(0);
|
|
399
|
+
};
|
|
400
|
+
selectMember = (node) => {
|
|
401
|
+
if (!this.intent.ready)
|
|
402
|
+
return;
|
|
403
|
+
const flowRequest = this.beginFlow();
|
|
404
|
+
if (this.intent.screen !== 'details')
|
|
405
|
+
this.previousScreen = this.intent.screen;
|
|
406
|
+
const request = ++this.selectionRequestId;
|
|
407
|
+
this.pendingSelection = { request, kind: 'node', key: node.key };
|
|
408
|
+
this.update({ screen: 'details', detailKey: node.key, actionError: null });
|
|
409
|
+
void this.perform(async () => {
|
|
410
|
+
try {
|
|
411
|
+
await this.viewer.selectNode(node.key);
|
|
412
|
+
if (!this.acknowledgeSelection(request))
|
|
413
|
+
return;
|
|
414
|
+
await this.viewer.setFloor(node.floorIndex, true);
|
|
415
|
+
if (request !== this.selectionRequestId || !this.intent.ready)
|
|
416
|
+
return;
|
|
417
|
+
this.acceptFlow(flowRequest);
|
|
418
|
+
await this.viewer.focusNode(node.key);
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
await this.rejectFlow(flowRequest);
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
finally {
|
|
425
|
+
if (this.pendingSelection?.request === request)
|
|
426
|
+
this.pendingSelection = null;
|
|
427
|
+
}
|
|
428
|
+
}, request);
|
|
429
|
+
};
|
|
430
|
+
handleNodeClick = (event) => {
|
|
431
|
+
if (!this.intent.ready)
|
|
432
|
+
return;
|
|
433
|
+
if (!event.key || !event.node) {
|
|
434
|
+
if (this.flow?.isRestoring)
|
|
435
|
+
return;
|
|
436
|
+
if (this.intent.screen === 'details' || this.intent.screen === 'group') {
|
|
437
|
+
if (this.flow)
|
|
438
|
+
this.back();
|
|
439
|
+
else
|
|
440
|
+
this.dismissSelection();
|
|
441
|
+
}
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
// A real pointer click supersedes an in-flight Back; restore-generated selection events do not.
|
|
445
|
+
// Hinglish: Back ka ACK pending ho tab naya map click jeete; restore ka selection event naya click nahi hai.
|
|
446
|
+
this.directions?.close();
|
|
447
|
+
const flowRequest = this.beginFlow(true);
|
|
448
|
+
// The renderer already selects the node; open details and focus without replaying selection.
|
|
449
|
+
// Hinglish: Map click pe renderer selection kare; yahan detail aur focus ho, selection dobara nahi.
|
|
450
|
+
const request = ++this.selectionRequestId;
|
|
451
|
+
this.pendingSelection = null;
|
|
452
|
+
this.memberRequestId++;
|
|
453
|
+
const persistent = this.viewer.getDiscoveryFilter?.();
|
|
454
|
+
this.previousScreen = persistent ? this.listScreen() : 'home';
|
|
455
|
+
if (!persistent)
|
|
456
|
+
this.listReturnScreen = 'home';
|
|
457
|
+
this.update({
|
|
458
|
+
screen: 'details',
|
|
459
|
+
detailKey: event.key,
|
|
460
|
+
group: null,
|
|
461
|
+
members: null,
|
|
462
|
+
membersLoading: false,
|
|
463
|
+
...(!persistent
|
|
464
|
+
? {
|
|
465
|
+
category: null,
|
|
466
|
+
subcategory: null,
|
|
467
|
+
amenity: null,
|
|
468
|
+
offers: false,
|
|
469
|
+
rootTab: 'categories',
|
|
470
|
+
}
|
|
471
|
+
: {}),
|
|
472
|
+
});
|
|
473
|
+
if (!persistent)
|
|
474
|
+
this.refreshCategories();
|
|
475
|
+
this.acceptFlow(flowRequest);
|
|
476
|
+
void this.perform(() => {
|
|
477
|
+
if (request !== this.selectionRequestId || !this.intent.ready)
|
|
478
|
+
return;
|
|
479
|
+
return this.viewer.focusNode(event.key);
|
|
480
|
+
}, request);
|
|
481
|
+
};
|
|
482
|
+
/** External deselection is also authoritative; a detail card must not wait forever for a cleared node.
|
|
483
|
+
* Hinglish: Host selectNode(null) kare to card close ho; selectedNode watcher/effect nahi chahiye. */
|
|
484
|
+
handleNodeSelected = (event) => {
|
|
485
|
+
if (this.flow?.isRestoring || (this.flow && event.source === 'map'))
|
|
486
|
+
return;
|
|
487
|
+
// Null events have no sender ID; the older own command's ACK closes its clear window.
|
|
488
|
+
// Hinglish: Null event ka sender ID nahi hota; purane apne clear ka ACK naya intent safe rakhta hai.
|
|
489
|
+
if (event.key === null) {
|
|
490
|
+
const clearRequest = this.pendingClears.values().next().value;
|
|
491
|
+
if (clearRequest !== undefined && clearRequest < this.selectionRequestId)
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (!this.intent.ready)
|
|
495
|
+
return;
|
|
496
|
+
if (event.key !== null && this.pendingSelection) {
|
|
497
|
+
if (this.pendingSelection.kind !== 'node' || this.pendingSelection.key !== event.key)
|
|
498
|
+
return;
|
|
499
|
+
this.pendingSelection = null;
|
|
500
|
+
}
|
|
501
|
+
if ((this.intent.screen === 'details' && event.key !== this.intent.detailKey) ||
|
|
502
|
+
(this.intent.screen === 'group' && this.intent.group !== null)) {
|
|
503
|
+
if (this.flow && !this.flow.isPending)
|
|
504
|
+
this.flow.reset();
|
|
505
|
+
this.dismissSelection();
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
/** Group events acknowledge the shared selection owner; they never select a representative node.
|
|
509
|
+
* Hinglish: Group event sirf common selection ko confirm kare; representative ka fake node selection nahi. */
|
|
510
|
+
handleNodeGroupSelected = ({ selection, }) => {
|
|
511
|
+
if (!this.intent.ready || this.flow?.isRestoring)
|
|
512
|
+
return;
|
|
513
|
+
if (selection && this.pendingSelection) {
|
|
514
|
+
if (this.pendingSelection.kind !== 'group' || this.pendingSelection.key !== selection.groupId)
|
|
515
|
+
return;
|
|
516
|
+
this.pendingSelection = null;
|
|
517
|
+
}
|
|
518
|
+
if (selection &&
|
|
519
|
+
this.intent.screen === 'group' &&
|
|
520
|
+
this.intent.group?.groupId === selection.groupId) {
|
|
521
|
+
this.update({ group: { ...this.intent.group, name: selection.name, summary: selection } });
|
|
522
|
+
}
|
|
523
|
+
else if (this.intent.screen === 'details' ||
|
|
524
|
+
(this.intent.screen === 'group' && this.intent.group)) {
|
|
525
|
+
if (this.flow && !this.flow.isPending)
|
|
526
|
+
this.flow.reset();
|
|
527
|
+
this.dismissSelection();
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
/** Event projection only: external commands update presentation/read channels, never echo a command.
|
|
531
|
+
* Hinglish: External filter event se UI/list sync ho; event se filter command wapas na bhejein. */
|
|
532
|
+
handleDiscoveryChanged = (state) => {
|
|
533
|
+
if (!this.intent.ready ||
|
|
534
|
+
this.flow?.isRestoring ||
|
|
535
|
+
this.pendingFilterRequest !== null ||
|
|
536
|
+
(state && state.mallId !== this.map?.mallId))
|
|
537
|
+
return;
|
|
538
|
+
const filter = state?.filter;
|
|
539
|
+
const same = String(this.intent.category?.code ?? '') === String(filter?.categoryCode ?? '') &&
|
|
540
|
+
String(this.intent.subcategory?.code ?? '') === String(filter?.subCategoryCode ?? '') &&
|
|
541
|
+
String(this.intent.amenity?.id ?? '') === String(filter?.amenityId ?? '') &&
|
|
542
|
+
this.intent.offers === Boolean(filter?.offersOnly);
|
|
543
|
+
if (same) {
|
|
544
|
+
if (state?.amenity && this.intent.amenity !== state.amenity)
|
|
545
|
+
this.update({ amenity: state.amenity });
|
|
546
|
+
if ((this.intent.screen === 'details' || this.intent.screen === 'group') &&
|
|
547
|
+
!this.viewer.hasSelection?.()) {
|
|
548
|
+
this.clearDetail(false, false);
|
|
549
|
+
this.update({ screen: this.listScreen() });
|
|
550
|
+
}
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (!this.flow?.isPending)
|
|
554
|
+
this.flow?.reset();
|
|
555
|
+
this.clearDetail(false, false);
|
|
556
|
+
this.update({
|
|
557
|
+
category: state?.category ?? null,
|
|
558
|
+
subcategory: state?.subcategory ?? null,
|
|
559
|
+
amenity: state?.amenity ?? null,
|
|
560
|
+
offers: Boolean(filter?.offersOnly),
|
|
561
|
+
rootTab: state?.amenity ? 'amenities' : 'categories',
|
|
562
|
+
screen: state?.amenity ? 'amenity' : state ? 'results' : 'home',
|
|
563
|
+
});
|
|
564
|
+
if (state && !state.amenity)
|
|
565
|
+
this.queryStores('');
|
|
566
|
+
else
|
|
567
|
+
this.stores.reset('stores');
|
|
568
|
+
if (this.intent.category)
|
|
569
|
+
this.refreshSubcategories();
|
|
570
|
+
else if (!this.intent.amenity)
|
|
571
|
+
this.refreshCategories();
|
|
572
|
+
};
|
|
573
|
+
syncFilter(flowRequest) {
|
|
574
|
+
const command = this.viewer.setDiscoveryFilter;
|
|
575
|
+
if (!command) {
|
|
576
|
+
this.acceptFlow(flowRequest);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const request = ++this.filterRequestId;
|
|
580
|
+
this.pendingFilterRequest = request;
|
|
581
|
+
const map = this.map;
|
|
582
|
+
const filter = this.intent.amenity ? { amenityId: this.intent.amenity.id } : this.filter();
|
|
583
|
+
const revision = (this.intent.amenity ? this.amenities : this.categories).getSnapshot().revision;
|
|
584
|
+
const current = () => request === this.filterRequestId && map === this.map;
|
|
585
|
+
// Coalesce synchronous intents; older events/ACKs must not rewind a newer category choice.
|
|
586
|
+
// Hinglish: Jaldi A/B select ho to old event UI ko A par wapas na le jaye; latest ACK se truth padhein.
|
|
587
|
+
void Promise.resolve()
|
|
588
|
+
.then(async () => {
|
|
589
|
+
if (!current())
|
|
590
|
+
return;
|
|
591
|
+
await command(filter
|
|
592
|
+
? {
|
|
593
|
+
...filter,
|
|
594
|
+
mallId: map?.mallId,
|
|
595
|
+
...(revision !== null ? { expectedRevision: revision } : {}),
|
|
596
|
+
}
|
|
597
|
+
: null);
|
|
598
|
+
if (!current())
|
|
599
|
+
return;
|
|
600
|
+
this.pendingFilterRequest = null;
|
|
601
|
+
if (this.viewer.getDiscoveryFilter)
|
|
602
|
+
this.handleDiscoveryChanged(this.viewer.getDiscoveryFilter());
|
|
603
|
+
this.acceptFlow(flowRequest);
|
|
604
|
+
})
|
|
605
|
+
.catch(async (error) => {
|
|
606
|
+
if (!current())
|
|
607
|
+
return;
|
|
608
|
+
this.pendingFilterRequest = null;
|
|
609
|
+
await this.rejectFlow(flowRequest);
|
|
610
|
+
if (!current())
|
|
611
|
+
return;
|
|
612
|
+
if (this.viewer.getDiscoveryFilter)
|
|
613
|
+
this.handleDiscoveryChanged(this.viewer.getDiscoveryFilter());
|
|
614
|
+
if (this.intent.ready)
|
|
615
|
+
this.update({ actionError: message(error) });
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
closeDetails = () => {
|
|
619
|
+
if (!this.intent.ready)
|
|
620
|
+
return;
|
|
621
|
+
if (this.flow && (this.flow.size || this.flow.isPending)) {
|
|
622
|
+
this.back();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (this.intent.screen === 'amenity' && this.intent.amenity) {
|
|
626
|
+
this.selectAmenity(this.intent.amenity);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
this.returnFromDetails();
|
|
630
|
+
};
|
|
631
|
+
returnFromDetails() {
|
|
632
|
+
const screen = this.intent.screen === 'details' ? this.previousScreen : this.listScreen();
|
|
633
|
+
const keepGroup = screen === 'group' || this.intent.group?.index !== undefined;
|
|
634
|
+
const restoreGroup = screen === 'group' ? this.intent.group : null;
|
|
635
|
+
this.clearDetail(keepGroup, !restoreGroup);
|
|
636
|
+
this.update({ screen });
|
|
637
|
+
if (restoreGroup)
|
|
638
|
+
this.selectGroup(restoreGroup.groupId);
|
|
639
|
+
if (!keepGroup) {
|
|
640
|
+
this.memberRequestId++;
|
|
641
|
+
this.update({ group: null, members: null, membersError: null, membersLoading: false });
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
loadMore = () => {
|
|
645
|
+
const query = this.stores.getSnapshot();
|
|
646
|
+
if (this.intent.ready && !query.error)
|
|
647
|
+
void this.stores.loadMore();
|
|
648
|
+
};
|
|
649
|
+
retry = () => {
|
|
650
|
+
if (this.intent.ready)
|
|
651
|
+
void this.stores.retry();
|
|
652
|
+
};
|
|
653
|
+
loadMoreFooter = (target) => {
|
|
654
|
+
const channel = this.footerChannel(target);
|
|
655
|
+
if (this.intent.ready && !channel.getSnapshot().error)
|
|
656
|
+
void channel.loadMore();
|
|
657
|
+
};
|
|
658
|
+
retryFooter = (target) => {
|
|
659
|
+
if (!this.intent.ready)
|
|
660
|
+
return;
|
|
661
|
+
if (this.intent.offersError)
|
|
662
|
+
this.refreshOffers();
|
|
663
|
+
const channel = this.footerChannel(target);
|
|
664
|
+
if (channel.getSnapshot().error)
|
|
665
|
+
void channel.retry();
|
|
666
|
+
};
|
|
667
|
+
loadMoreMembers = () => {
|
|
668
|
+
const page = this.intent.members;
|
|
669
|
+
if (this.intent.ready &&
|
|
670
|
+
page?.hasMore &&
|
|
671
|
+
!this.intent.membersLoading &&
|
|
672
|
+
!this.intent.membersError)
|
|
673
|
+
void this.readMembers(page.nextOffset ?? 0);
|
|
674
|
+
};
|
|
675
|
+
retryMembers = () => {
|
|
676
|
+
if (this.intent.ready && this.intent.membersError && !this.intent.membersLoading)
|
|
677
|
+
void this.readMembers(this.intent.members?.nextOffset ?? 0);
|
|
678
|
+
};
|
|
679
|
+
changeTheme = (theme) => {
|
|
680
|
+
if (!this.intent.ready)
|
|
681
|
+
return;
|
|
682
|
+
const request = ++this.themeRequestId;
|
|
683
|
+
this.update({ actionError: null });
|
|
684
|
+
void this.perform(() => this.viewer.setTheme(resolveViewerAppearance(theme).map), request, 'theme');
|
|
685
|
+
};
|
|
686
|
+
/** Existing SDK controls share the same readiness/error boundary as Classic actions.
|
|
687
|
+
* Hinglish: Zoom/floor jaise controls bhi ready hone par chalte hain; error ka ek owner hai. */
|
|
688
|
+
runCommand = (operation) => {
|
|
689
|
+
if (!this.intent.ready)
|
|
690
|
+
return;
|
|
691
|
+
this.update({ actionError: null });
|
|
692
|
+
void this.perform(operation, ++this.controlRequestId, 'control');
|
|
693
|
+
};
|
|
694
|
+
/** Back is one explicit action shared by all templates; no panel/floor watcher drives restoration.
|
|
695
|
+
* Hinglish: Previous filter/list/detail same SDK command se aaye; template apni history na rakhe. */
|
|
696
|
+
back = () => {
|
|
697
|
+
if (!this.intent.ready || this.flow?.isRestoring)
|
|
698
|
+
return;
|
|
699
|
+
if (this.directions?.getSnapshot().open) {
|
|
700
|
+
this.directions.back();
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
const map = this.map;
|
|
704
|
+
void this.restoreBack().catch((error) => {
|
|
705
|
+
if (map !== this.map)
|
|
706
|
+
return;
|
|
707
|
+
this.update({ actionError: message(error) });
|
|
708
|
+
if (this.viewer.getDiscoveryFilter)
|
|
709
|
+
this.handleDiscoveryChanged(this.viewer.getDiscoveryFilter());
|
|
710
|
+
this.publish();
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
async restoreBack(preserveOrigin = false, context) {
|
|
714
|
+
if (!this.intent.ready || this.flow?.isRestoring)
|
|
715
|
+
return;
|
|
716
|
+
if (!this.flow) {
|
|
717
|
+
this.closeSearch();
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
const selectionRequest = ++this.selectionRequestId;
|
|
721
|
+
this.pendingSelection = null;
|
|
722
|
+
this.filterRequestId++;
|
|
723
|
+
this.pendingFilterRequest = null;
|
|
724
|
+
this.memberRequestId++;
|
|
725
|
+
const map = this.map;
|
|
726
|
+
const operation = this.flow.back((context) => {
|
|
727
|
+
if (!this.stores.hasBookmark(context.bookmark))
|
|
728
|
+
throw new Error('This history list has expired');
|
|
729
|
+
}, (context) => this.restoreFlowContext(context), preserveOrigin ? { preserveOrigin: true } : undefined);
|
|
730
|
+
this.publish();
|
|
731
|
+
try {
|
|
732
|
+
const restored = await operation;
|
|
733
|
+
if (map !== this.map || selectionRequest !== this.selectionRequestId)
|
|
734
|
+
return;
|
|
735
|
+
if (!restored) {
|
|
736
|
+
// A root direction Back clears To atomically and retains only the actual selected From.
|
|
737
|
+
// Hinglish: History na ho to To clear ho; fake/default From na bane aur existing From safe rahe.
|
|
738
|
+
const current = await this.viewer.getInteractionState?.();
|
|
739
|
+
if (map !== this.map || selectionRequest !== this.selectionRequestId)
|
|
740
|
+
return;
|
|
741
|
+
const restore = this.viewer.restoreInteractionState;
|
|
742
|
+
if (!current || !restore)
|
|
743
|
+
throw new Error('Map is not ready for history restoration');
|
|
744
|
+
if ((context?.mallId !== undefined && context.mallId !== current.mallId) ||
|
|
745
|
+
(context?.expectedRevision !== undefined && context.expectedRevision !== current.revision))
|
|
746
|
+
throw new Error('Map changed during direction Back');
|
|
747
|
+
await restore({
|
|
748
|
+
...current,
|
|
749
|
+
filter: null,
|
|
750
|
+
selection: null,
|
|
751
|
+
...(current.endpoints
|
|
752
|
+
? {
|
|
753
|
+
endpoints: {
|
|
754
|
+
origin: preserveOrigin ? current.endpoints.origin : null,
|
|
755
|
+
destination: null,
|
|
756
|
+
},
|
|
757
|
+
}
|
|
758
|
+
: {}),
|
|
759
|
+
});
|
|
760
|
+
if (map !== this.map || selectionRequest !== this.selectionRequestId)
|
|
761
|
+
return;
|
|
762
|
+
this.closeSearch();
|
|
763
|
+
}
|
|
764
|
+
else
|
|
765
|
+
this.publish();
|
|
766
|
+
}
|
|
767
|
+
catch (error) {
|
|
768
|
+
if (map === this.map && selectionRequest === this.selectionRequestId)
|
|
769
|
+
throw error;
|
|
770
|
+
}
|
|
771
|
+
finally {
|
|
772
|
+
if (map === this.map)
|
|
773
|
+
this.publish();
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
/** Scroll samples are presentation-only and do not notify subscribers per pixel.
|
|
777
|
+
* Hinglish: Scroll position save ho; har pixel par root re-render ya SDK call na ho. */
|
|
778
|
+
setListScrollOffset = (offset) => {
|
|
779
|
+
if (Number.isFinite(offset))
|
|
780
|
+
this.listScrollOffset = Math.max(0, offset);
|
|
781
|
+
};
|
|
782
|
+
captureFlowContext() {
|
|
783
|
+
const { screen, rootTab, category, subcategory, amenity, offers, detailKey, group } = this.intent;
|
|
784
|
+
const stores = this.stores.getSnapshot();
|
|
785
|
+
return Object.freeze({
|
|
786
|
+
screen,
|
|
787
|
+
rootTab,
|
|
788
|
+
category,
|
|
789
|
+
subcategory,
|
|
790
|
+
amenity,
|
|
791
|
+
offers,
|
|
792
|
+
detailKey,
|
|
793
|
+
group,
|
|
794
|
+
members: this.intent.members,
|
|
795
|
+
catalogEpoch: this.catalogEpoch,
|
|
796
|
+
bookmark: this.stores.captureBookmark(),
|
|
797
|
+
query: stores.query,
|
|
798
|
+
sort: stores.sortBy,
|
|
799
|
+
scrollOffset: this.listScrollOffset,
|
|
800
|
+
previousScreen: this.previousScreen,
|
|
801
|
+
listReturnScreen: this.listReturnScreen,
|
|
802
|
+
directionOpen: this.directions?.getSnapshot().open ?? false,
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
beginFlow(mapClick = false) {
|
|
806
|
+
return this.flow?.begin(this.captureFlowContext(), mapClick);
|
|
807
|
+
}
|
|
808
|
+
acceptFlow(id) {
|
|
809
|
+
if (id === undefined || !this.flow)
|
|
810
|
+
return;
|
|
811
|
+
void this.flow
|
|
812
|
+
.accept(id, () => this.captureFlowContext())
|
|
813
|
+
.then(this.publish)
|
|
814
|
+
.catch(async (error) => {
|
|
815
|
+
if (await this.rejectFlow(id))
|
|
816
|
+
this.update({ actionError: message(error) });
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
async rejectFlow(id) {
|
|
820
|
+
if (id === undefined || !this.flow)
|
|
821
|
+
return false;
|
|
822
|
+
const context = await this.flow.reject(id);
|
|
823
|
+
if (context && this.stores.hasBookmark(context.bookmark))
|
|
824
|
+
this.restoreFlowContext(context);
|
|
825
|
+
return context !== null;
|
|
826
|
+
}
|
|
827
|
+
restoreFlowContext(context) {
|
|
828
|
+
this.directions?.restorePresentation(context.directionOpen);
|
|
829
|
+
this.memberRequestId++;
|
|
830
|
+
this.previousScreen = context.previousScreen;
|
|
831
|
+
this.listReturnScreen = context.listReturnScreen;
|
|
832
|
+
this.listScrollOffset = context.scrollOffset;
|
|
833
|
+
const stale = context.catalogEpoch !== this.catalogEpoch;
|
|
834
|
+
const currentGroup = stale ? this.viewer.getSelectedNodeGroup?.() : undefined;
|
|
835
|
+
this.stores.restoreBookmark(context.bookmark);
|
|
836
|
+
this.update({
|
|
837
|
+
screen: context.screen,
|
|
838
|
+
rootTab: context.rootTab,
|
|
839
|
+
category: context.category,
|
|
840
|
+
subcategory: context.subcategory,
|
|
841
|
+
amenity: context.amenity,
|
|
842
|
+
offers: context.offers,
|
|
843
|
+
detailKey: context.detailKey,
|
|
844
|
+
group: stale && context.group
|
|
845
|
+
? { ...context.group, summary: currentGroup ?? undefined }
|
|
846
|
+
: context.group,
|
|
847
|
+
members: stale ? null : context.members,
|
|
848
|
+
membersLoading: false,
|
|
849
|
+
membersError: null,
|
|
850
|
+
actionError: null,
|
|
851
|
+
});
|
|
852
|
+
if (context.category)
|
|
853
|
+
this.refreshSubcategories();
|
|
854
|
+
else if (!context.amenity)
|
|
855
|
+
this.refreshCategories();
|
|
856
|
+
if (context.group && (stale || !context.members))
|
|
857
|
+
void this.readMembers(0);
|
|
858
|
+
}
|
|
859
|
+
filter() {
|
|
860
|
+
const { category, subcategory, offers } = this.intent;
|
|
861
|
+
if (!category && !offers)
|
|
862
|
+
return undefined;
|
|
863
|
+
return {
|
|
864
|
+
...(category ? { categoryCode: category.code } : {}),
|
|
865
|
+
...(subcategory ? { subCategoryCode: subcategory.code } : {}),
|
|
866
|
+
...(offers ? { offersOnly: true } : {}),
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
queryStores(query) {
|
|
870
|
+
this.listScrollOffset = 0;
|
|
871
|
+
const priorSort = this.stores.getSnapshot().sortBy;
|
|
872
|
+
const sortBy = !query.trim() && (priorSort === 'relevance' || priorSort?.startsWith('paid_promotion_'))
|
|
873
|
+
? 'asc'
|
|
874
|
+
: (priorSort ?? (query.trim() ? 'relevance' : 'asc'));
|
|
875
|
+
void this.stores.execute({
|
|
876
|
+
target: 'stores',
|
|
877
|
+
query,
|
|
878
|
+
mode: query.trim() ? 'search' : 'catalog',
|
|
879
|
+
filter: this.filter(),
|
|
880
|
+
sortBy,
|
|
881
|
+
pageSize: 20,
|
|
882
|
+
groupMultiLocation: true,
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
refreshCategories() {
|
|
886
|
+
const current = this.categories.getSnapshot();
|
|
887
|
+
if (current.status !== 'idle' && Boolean(current.filter?.offersOnly) === this.intent.offers)
|
|
888
|
+
return;
|
|
889
|
+
void this.categories.execute({
|
|
890
|
+
target: 'categories',
|
|
891
|
+
filter: this.intent.offers ? { offersOnly: true } : undefined,
|
|
892
|
+
pageSize: 20,
|
|
893
|
+
sortBy: 'asc',
|
|
894
|
+
}, { immediate: true });
|
|
895
|
+
}
|
|
896
|
+
/** Offer availability is a catalog event, not a floor/selection dependency effect.
|
|
897
|
+
* Hinglish: Shared event count refresh kare; doosra timer ya business watcher nahi. */
|
|
898
|
+
handleCatalogChanged = () => {
|
|
899
|
+
this.catalogEpoch++;
|
|
900
|
+
this.pendingCatalogRefresh = true;
|
|
901
|
+
this.refreshCatalogPresentation();
|
|
902
|
+
};
|
|
903
|
+
// Defer visible reads while context is unavailable, but retire old history immediately.
|
|
904
|
+
// Hinglish: Context loss mein history stale mark ho; actual UI reads restore par ek baar chalein.
|
|
905
|
+
refreshCatalogPresentation() {
|
|
906
|
+
if (!this.intent.ready)
|
|
907
|
+
return;
|
|
908
|
+
this.pendingCatalogRefresh = false;
|
|
909
|
+
if (this.viewer.getDiscoveryFilter)
|
|
910
|
+
this.handleDiscoveryChanged(this.viewer.getDiscoveryFilter());
|
|
911
|
+
if (this.intent.group) {
|
|
912
|
+
const selection = this.viewer.getSelectedNodeGroup?.();
|
|
913
|
+
if (selection && this.intent.screen === 'group')
|
|
914
|
+
this.handleNodeGroupSelected({ selection });
|
|
915
|
+
// Retire in-flight/public member pages; reload only the bounded visible group page.
|
|
916
|
+
// Hinglish: Purane group pages retire hon; sirf current group ka chhota page dobara aaye.
|
|
917
|
+
this.memberRequestId++;
|
|
918
|
+
this.update({ members: null, membersLoading: false });
|
|
919
|
+
void this.readMembers(0);
|
|
920
|
+
}
|
|
921
|
+
this.refreshOffers();
|
|
922
|
+
}
|
|
923
|
+
refreshOffers() {
|
|
924
|
+
const request = this.requestId;
|
|
925
|
+
const offerRequest = ++this.offerRequestId;
|
|
926
|
+
this.update({ offersError: null });
|
|
927
|
+
// Count-only public query; never fetch all stores just to enable an Offers button.
|
|
928
|
+
// Hinglish: Offers button ke liye sirf count; failure par explicit retry se wahi read dobara hogi.
|
|
929
|
+
void this.viewer
|
|
930
|
+
.getCatalog({ target: 'stores', filter: { offersOnly: true }, pagination: { limit: 0 } })
|
|
931
|
+
.then((page) => {
|
|
932
|
+
if (request === this.requestId && offerRequest === this.offerRequestId)
|
|
933
|
+
this.update({ hasOffers: page.totalRows > 0 });
|
|
934
|
+
})
|
|
935
|
+
.catch((error) => {
|
|
936
|
+
if (request === this.requestId && offerRequest === this.offerRequestId)
|
|
937
|
+
this.update({ offersError: message(error) });
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
refreshSubcategories() {
|
|
941
|
+
if (!this.intent.category)
|
|
942
|
+
return;
|
|
943
|
+
void this.subcategories.execute({
|
|
944
|
+
target: 'subcategories',
|
|
945
|
+
filter: {
|
|
946
|
+
categoryCode: this.intent.category.code,
|
|
947
|
+
...(this.intent.offers ? { offersOnly: true } : {}),
|
|
948
|
+
},
|
|
949
|
+
pageSize: 20,
|
|
950
|
+
sortBy: 'asc',
|
|
951
|
+
}, { immediate: true });
|
|
952
|
+
}
|
|
953
|
+
footerChannel(target) {
|
|
954
|
+
// Templates may show categories beside an amenity sheet; page the visible catalog, not the selected tab.
|
|
955
|
+
// Hinglish: Amenity sheet ke saath category rail ho to usi visible catalog ka page aaye.
|
|
956
|
+
if (target === 'categories' || target === 'subcategories' || target === 'amenities')
|
|
957
|
+
return this[target];
|
|
958
|
+
return this.intent.rootTab === 'amenities'
|
|
959
|
+
? this.amenities
|
|
960
|
+
: this.intent.category
|
|
961
|
+
? this.subcategories
|
|
962
|
+
: this.categories;
|
|
963
|
+
}
|
|
964
|
+
listScreen() {
|
|
965
|
+
if (this.intent.amenity)
|
|
966
|
+
return 'amenity';
|
|
967
|
+
return this.intent.category || this.intent.offers ? 'results' : this.listReturnScreen;
|
|
968
|
+
}
|
|
969
|
+
clearDetail(keepGroup = false, clearSelection = true) {
|
|
970
|
+
const hadPendingSelection = this.pendingSelection !== null;
|
|
971
|
+
this.selectionRequestId++;
|
|
972
|
+
this.pendingSelection = null;
|
|
973
|
+
// Pending commands need their ordered clear; a failed preview alone does not own SDK selection.
|
|
974
|
+
// Hinglish: Pending command ko clear bhejein; SDK empty ho to failed card se extra clear na bane.
|
|
975
|
+
const hasSelection = clearSelection &&
|
|
976
|
+
(hadPendingSelection ||
|
|
977
|
+
(this.viewer.hasSelection?.() ??
|
|
978
|
+
(this.intent.detailKey !== null ||
|
|
979
|
+
(this.intent.screen === 'group' && this.intent.group !== null))));
|
|
980
|
+
if (!keepGroup) {
|
|
981
|
+
this.memberRequestId++;
|
|
982
|
+
this.update({ group: null, members: null, membersError: null, membersLoading: false });
|
|
983
|
+
}
|
|
984
|
+
this.update({ detailKey: null, actionError: null });
|
|
985
|
+
if (clearSelection && hasSelection) {
|
|
986
|
+
const request = this.selectionRequestId;
|
|
987
|
+
this.pendingClears.add(request);
|
|
988
|
+
void this.perform(async () => {
|
|
989
|
+
try {
|
|
990
|
+
await this.viewer.selectNode(null);
|
|
991
|
+
}
|
|
992
|
+
finally {
|
|
993
|
+
this.pendingClears.delete(request);
|
|
994
|
+
}
|
|
995
|
+
}, request);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
/** The channel supplies the same pinned search/filter scope for selection and member pages.
|
|
999
|
+
* Hinglish: Group selection aur member pages ko wahi query/filter context mile; keys UI mein na nikalein. */
|
|
1000
|
+
selectGroup(groupId, representative, flowRequest) {
|
|
1001
|
+
const request = ++this.selectionRequestId;
|
|
1002
|
+
this.pendingSelection = { request, kind: 'group', key: groupId };
|
|
1003
|
+
this.update({ actionError: null });
|
|
1004
|
+
void this.perform(async () => {
|
|
1005
|
+
try {
|
|
1006
|
+
await this.stores.selectNodeGroup(groupId);
|
|
1007
|
+
if (!this.acknowledgeSelection(request))
|
|
1008
|
+
return;
|
|
1009
|
+
if (!representative) {
|
|
1010
|
+
this.acceptFlow(flowRequest);
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
await this.viewer.setFloor(representative.floorIndex, true);
|
|
1014
|
+
if (request !== this.selectionRequestId || !this.intent.ready)
|
|
1015
|
+
return;
|
|
1016
|
+
this.acceptFlow(flowRequest);
|
|
1017
|
+
await this.viewer.focusNode(representative.key);
|
|
1018
|
+
}
|
|
1019
|
+
catch (error) {
|
|
1020
|
+
await this.rejectFlow(flowRequest);
|
|
1021
|
+
throw error;
|
|
1022
|
+
}
|
|
1023
|
+
finally {
|
|
1024
|
+
if (this.pendingSelection?.request === request)
|
|
1025
|
+
this.pendingSelection = null;
|
|
1026
|
+
}
|
|
1027
|
+
}, request);
|
|
1028
|
+
}
|
|
1029
|
+
/** A current selection ACK supersedes older clears; reconcile any later clear before moving the camera.
|
|
1030
|
+
* Hinglish: Latest selection ACK purane clears retire kare; SDK empty ho to card/camera dobara na chale. */
|
|
1031
|
+
acknowledgeSelection(request) {
|
|
1032
|
+
if (request !== this.selectionRequestId || !this.intent.ready)
|
|
1033
|
+
return false;
|
|
1034
|
+
this.pendingClears.clear();
|
|
1035
|
+
if (this.viewer.hasSelection?.() === false) {
|
|
1036
|
+
this.flow?.reset();
|
|
1037
|
+
this.dismissSelection();
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
return true;
|
|
1041
|
+
}
|
|
1042
|
+
dismissSelection() {
|
|
1043
|
+
const screen = this.listScreen();
|
|
1044
|
+
this.clearDetail(false, false);
|
|
1045
|
+
this.update({ screen });
|
|
1046
|
+
}
|
|
1047
|
+
async readMembers(offset) {
|
|
1048
|
+
const group = this.intent.group;
|
|
1049
|
+
if (!group || this.intent.membersLoading)
|
|
1050
|
+
return;
|
|
1051
|
+
const request = ++this.memberRequestId;
|
|
1052
|
+
this.update({ membersLoading: true, membersError: null });
|
|
1053
|
+
try {
|
|
1054
|
+
const page = await this.stores.getGroupMembers({
|
|
1055
|
+
groupId: group.groupId,
|
|
1056
|
+
pagination: { offset, limit: 20 },
|
|
1057
|
+
});
|
|
1058
|
+
if (request !== this.memberRequestId)
|
|
1059
|
+
return;
|
|
1060
|
+
if (!page)
|
|
1061
|
+
throw new Error('These locations are no longer available');
|
|
1062
|
+
const previous = this.intent.members;
|
|
1063
|
+
this.update({
|
|
1064
|
+
members: {
|
|
1065
|
+
groupId: page.groupId,
|
|
1066
|
+
items: offset > 0 && previous ? [...previous.items, ...page.items] : page.items,
|
|
1067
|
+
totalMemberCount: page.totalMemberCount,
|
|
1068
|
+
hasMore: page.hasMore,
|
|
1069
|
+
nextOffset: page.nextOffset,
|
|
1070
|
+
},
|
|
1071
|
+
membersLoading: false,
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
catch (error) {
|
|
1075
|
+
if (request === this.memberRequestId)
|
|
1076
|
+
this.update({ membersLoading: false, membersError: message(error) });
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
async perform(action, request, kind = 'selection') {
|
|
1080
|
+
try {
|
|
1081
|
+
await action();
|
|
1082
|
+
}
|
|
1083
|
+
catch (error) {
|
|
1084
|
+
const publicError = toViewerCommandError(error);
|
|
1085
|
+
const current = kind === 'theme'
|
|
1086
|
+
? this.themeRequestId
|
|
1087
|
+
: kind === 'control'
|
|
1088
|
+
? this.controlRequestId
|
|
1089
|
+
: this.selectionRequestId;
|
|
1090
|
+
if (publicError && request === current && this.intent.ready)
|
|
1091
|
+
this.update({ actionError: publicError.message });
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
update(patch) {
|
|
1095
|
+
if (Object.entries(patch).every(([key, value]) => Object.is(this.intent[key], value)))
|
|
1096
|
+
return;
|
|
1097
|
+
this.intent = { ...this.intent, ...patch };
|
|
1098
|
+
this.publish();
|
|
1099
|
+
}
|
|
1100
|
+
readSnapshot() {
|
|
1101
|
+
const name = this.intent.subcategory?.name ?? this.intent.category?.name;
|
|
1102
|
+
return {
|
|
1103
|
+
...this.intent,
|
|
1104
|
+
historyDepth: this.flow?.size ?? 0,
|
|
1105
|
+
historyPending: this.flow?.isRestoring ?? false,
|
|
1106
|
+
listScrollOffset: this.listScrollOffset,
|
|
1107
|
+
title: this.intent.amenity?.name ??
|
|
1108
|
+
(name
|
|
1109
|
+
? `${name}${this.intent.offers ? ' · Offers' : ''}`
|
|
1110
|
+
: this.intent.offers
|
|
1111
|
+
? 'Stores with offers'
|
|
1112
|
+
: 'Explore stores'),
|
|
1113
|
+
stores: this.stores.getSnapshot(),
|
|
1114
|
+
categories: this.categories.getSnapshot(),
|
|
1115
|
+
subcategories: this.subcategories.getSnapshot(),
|
|
1116
|
+
amenities: this.amenities.getSnapshot(),
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
publish = () => {
|
|
1120
|
+
if (this.intent.rootTab === 'categories' &&
|
|
1121
|
+
!this.intent.category &&
|
|
1122
|
+
!this.intent.offers &&
|
|
1123
|
+
this.categories.getSnapshot().status === 'empty' &&
|
|
1124
|
+
this.amenities.getSnapshot().totalRows > 0) {
|
|
1125
|
+
this.intent = { ...this.intent, rootTab: 'amenities' };
|
|
1126
|
+
}
|
|
1127
|
+
this.snapshot = this.readSnapshot();
|
|
1128
|
+
for (const listener of this.listeners)
|
|
1129
|
+
listener();
|
|
1130
|
+
};
|
|
1131
|
+
}
|