@wix/himalaya-cli 0.2019.0 → 0.2021.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/cli.mjs +103 -18
- package/guides/widgets.md +7 -1
- package/package.json +2 -2
- package/templates/beauty-salon-owner/dev/index.ts +1 -1
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/community-club-owner/dev/index.ts +1 -1
- package/templates/community-club-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/community-club-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/events-meetups-owner/dev/index.ts +1 -1
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/gym-fitness-owner/dev/index.ts +1 -1
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/nonprofit-cause-owner/dev/index.ts +1 -1
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/owner-lite/dev/index.ts +1 -1
- package/templates/owner-lite/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/owner-lite/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/podcast-creator-owner/dev/index.ts +1 -1
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/portfolio-creative-owner/dev/index.ts +1 -1
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/restaurant-owner/dev/index.ts +1 -1
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/retail-store-owner/dev/index.ts +1 -1
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
- package/templates/yoga-studio-owner/dev/index.ts +1 -1
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-today/glance.ts +36 -1
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-today/index.ts +44 -10
|
@@ -23,7 +23,7 @@ import { queryEvents } from "@himalaya/wix-events";
|
|
|
23
23
|
import { queryDraftPosts } from "@himalaya/wix-blog";
|
|
24
24
|
import {
|
|
25
25
|
str, hhmm, sameLocalDay, dayLabel, rankItems, glanceFields, bookingItems, orderItems, eventItems, blogItems, shownUntil,
|
|
26
|
-
GLANCE_COPY, type GlanceFields,
|
|
26
|
+
GLANCE_COPY, focusFields, focusList, type GlanceFields, type GlanceFocus, type GlanceFocusOption,
|
|
27
27
|
} from "./glance.js";
|
|
28
28
|
|
|
29
29
|
export { isSectionUnavailable, isSignedOut, dayLabel };
|
|
@@ -46,6 +46,10 @@ export interface TodayBooking {
|
|
|
46
46
|
/** The glance ("what matters now", glance.ts) rides on the same state: the existing fields stay
|
|
47
47
|
* for the embedding hosts that bind them (the embedding guide), the glance fields are added. */
|
|
48
48
|
export interface TodayState extends GlanceFields {
|
|
49
|
+
/** The glance for each focus a widget may be set to ("now" + the provisioned areas). */
|
|
50
|
+
focuses: Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
51
|
+
/** Those focuses with owner-facing titles, in order — the widget picker's list. */
|
|
52
|
+
focusList: GlanceFocusOption[];
|
|
49
53
|
eventsReady: boolean;
|
|
50
54
|
blogReady: boolean;
|
|
51
55
|
status: "loading" | "ready" | "error" | "signedOut";
|
|
@@ -147,7 +151,7 @@ function upcoming(rows: Rec[] | null, statuses: string[], now: Date): Rec[] {
|
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
/** Pure: shape what was read into the widget state. `now` is injectable for tests. */
|
|
150
|
-
export function shape(sources: Sources, now: Date, siteName: string): TodayState {
|
|
154
|
+
export function shape(sources: Sources, now: Date, siteName: string, provisioned: Verticals = buildVerticals()): TodayState {
|
|
151
155
|
const bookingsReady = sources.bookings !== null && sources.requests !== null;
|
|
152
156
|
const ordersReady = sources.orders !== null;
|
|
153
157
|
// Re-filtered even though the queries filter: a server (or a fixture) that returns a
|
|
@@ -184,14 +188,30 @@ export function shape(sources: Sources, now: Date, siteName: string): TodayState
|
|
|
184
188
|
// the next booking already did: the frame's lifetime ends at the first of them.
|
|
185
189
|
const headAt = shownUntil(ranked);
|
|
186
190
|
// Nothing could be read at all: the glance shows the degrade line, never "All clear".
|
|
187
|
-
const glance = nothing
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
const glance = nothing ? degradeGlance(COPY.nothing) : glanceFields(ranked, GLANCE_COPY);
|
|
192
|
+
// One glance per focus a widget may be set to (PR 2): "now" is the glance above, an area keeps
|
|
193
|
+
// only its own items. The phone publishes one frame per focus from the same descriptors.
|
|
194
|
+
const options = focusList(provisioned);
|
|
195
|
+
// Each focus's frame ends when an item IT shows starts — an Events widget headlines an event
|
|
196
|
+
// that may be 4th in "now" — so it carries its own `validUntil`, laid over the state's.
|
|
197
|
+
const ownEnd = (f: GlanceFocus) => f === "now"
|
|
198
|
+
? Math.floor(Math.min(midnight, nextStart, headAt) / 1000)
|
|
199
|
+
: Math.floor(Math.min(midnight, shownUntil(ranked.filter((i) => i.area === f))) / 1000);
|
|
200
|
+
// An area focus stands only on its own read: when that read failed (428/404/403, a network
|
|
201
|
+
// error) the widget pinned to it shows the degrade line, never an All clear it cannot vouch for.
|
|
202
|
+
const areaReady: Record<GlanceFocus, boolean> = {
|
|
203
|
+
now: !nothing, bookings: bookingsReady, store: ordersReady, events: eventsReady, blog: blogReady,
|
|
204
|
+
};
|
|
205
|
+
const focuses = Object.fromEntries(options.map((f) => [f.id, {
|
|
206
|
+
...(!areaReady[f.id]
|
|
207
|
+
? { ...degradeGlance(COPY.nothing), glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel }
|
|
208
|
+
: focusFields(ranked, f.id, GLANCE_COPY)),
|
|
209
|
+
validUntil: ownEnd(f.id),
|
|
210
|
+
}])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
193
211
|
return {
|
|
194
212
|
...glance,
|
|
213
|
+
focuses,
|
|
214
|
+
focusList: options,
|
|
195
215
|
eventsReady,
|
|
196
216
|
blogReady,
|
|
197
217
|
validUntil: Math.floor(Math.min(midnight, nextStart, headAt) / 1000),
|
|
@@ -228,11 +248,25 @@ export function degraded(status: "error" | "signedOut" | "loading", siteName: st
|
|
|
228
248
|
// validUntil pinned too: shape() derives it from LOCAL midnight, so even at a fixed instant it
|
|
229
249
|
// would vary with the build machine's timezone and change the baked services hash.
|
|
230
250
|
// The glance shows the degrade line too, never "All clear": a frame that could not read the
|
|
231
|
-
// business must not tell the owner nothing is waiting.
|
|
251
|
+
// business must not tell the owner nothing is waiting. Every focus says the same line.
|
|
252
|
+
const line = degradeGlance(message);
|
|
232
253
|
return {
|
|
233
254
|
...base, status, message, hideMessage: !message, validUntil: 0,
|
|
255
|
+
...line,
|
|
256
|
+
// Each focus keeps its own header ("Orders"), only the line is the degrade one.
|
|
257
|
+
focuses: Object.fromEntries(base.focusList.map((f) => [f.id,
|
|
258
|
+
{ ...line, glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel, validUntil: 0 }])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The glance of a frame that could not read the business: its one line in every slot, never
|
|
263
|
+
* "All clear", and never an empty Lock Screen circle. */
|
|
264
|
+
function degradeGlance(message: string): GlanceFields {
|
|
265
|
+
return {
|
|
266
|
+
...glanceFields([], GLANCE_COPY),
|
|
234
267
|
glanceHeadline: message, glanceDetail: "", glanceAllClear: false, glanceSymbol: "",
|
|
235
|
-
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
268
|
+
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
269
|
+
lockCircValue: message ? "—" : "", lockCircLabel: message ? "Owner" : "",
|
|
236
270
|
};
|
|
237
271
|
}
|
|
238
272
|
|
|
@@ -69262,7 +69262,7 @@ const SCREENS = runtimeSetting({
|
|
|
69262
69262
|
"package": "himalaya",
|
|
69263
69263
|
"type": "Text",
|
|
69264
69264
|
"props": {
|
|
69265
|
-
"text": "
|
|
69265
|
+
"text": "$service:ownerToday.glanceLabel",
|
|
69266
69266
|
"style": "caption",
|
|
69267
69267
|
"color": "textSecondary",
|
|
69268
69268
|
"maxLines": 1
|
|
@@ -67,6 +67,8 @@ export interface GlanceFields {
|
|
|
67
67
|
glanceSecondary: string;
|
|
68
68
|
hideGlanceSecondary: boolean;
|
|
69
69
|
glanceAllClear: boolean;
|
|
70
|
+
/** The widget header: "Now" for the ranking, the area's name for a pinned focus. */
|
|
71
|
+
glanceLabel: string;
|
|
70
72
|
lockInline: string;
|
|
71
73
|
lockCircValue: string;
|
|
72
74
|
lockCircLabel: string;
|
|
@@ -234,6 +236,38 @@ export function rankItems(items: GlanceItem[]): GlanceItem[] {
|
|
|
234
236
|
|| AREA_ORDER.indexOf(a.area) - AREA_ORDER.indexOf(b.area));
|
|
235
237
|
}
|
|
236
238
|
|
|
239
|
+
/** What one placed widget shows: everything ranked ("now"), or one area only. */
|
|
240
|
+
export type GlanceFocus = "now" | GlanceArea;
|
|
241
|
+
|
|
242
|
+
export interface GlanceFocusOption {
|
|
243
|
+
id: GlanceFocus;
|
|
244
|
+
title: string;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The small widget's header for the ranking: short, because it sits beside an icon in 2×2. */
|
|
248
|
+
const NOW_LABEL = "Now";
|
|
249
|
+
|
|
250
|
+
const FOCUS_TITLES: Record<GlanceFocus, string> = {
|
|
251
|
+
now: "What matters now",
|
|
252
|
+
bookings: "Bookings",
|
|
253
|
+
store: "Orders",
|
|
254
|
+
events: "Events",
|
|
255
|
+
blog: "Blog",
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/** The focuses a widget may be set to: "now", then the areas this build provisions, in the
|
|
259
|
+
* canonical order. Stable from first launch: it follows the build, not what a read returned. */
|
|
260
|
+
export function focusList(provisioned: Record<GlanceArea, boolean>): GlanceFocusOption[] {
|
|
261
|
+
return (["now", ...AREA_ORDER.filter((a) => provisioned[a])] as GlanceFocus[]).map((id) => ({ id, title: FOCUS_TITLES[id] }));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The glance for one focus: "now" is the whole ranking; an area keeps only its own items, so a
|
|
265
|
+
* widget pinned to Orders never shows a booking. An area with nothing is its own All clear. */
|
|
266
|
+
export function focusFields(ranked: GlanceItem[], focus: GlanceFocus, copy: GlanceCopy): GlanceFields {
|
|
267
|
+
const fields = glanceFields(focus === "now" ? ranked : ranked.filter((i) => i.area === focus), copy);
|
|
268
|
+
return { ...fields, glanceLabel: focus === "now" ? NOW_LABEL : FOCUS_TITLES[focus] };
|
|
269
|
+
}
|
|
270
|
+
|
|
237
271
|
/** When the frame stops being true: the earliest moment among the items it SHOWS (the headline
|
|
238
272
|
* and the two on the secondary line). A started booking, event or post is no longer "next". */
|
|
239
273
|
export function shownUntil(ranked: GlanceItem[]): number {
|
|
@@ -247,7 +281,7 @@ export function glanceFields(ranked: GlanceItem[], copy: GlanceCopy): GlanceFiel
|
|
|
247
281
|
if (!head) {
|
|
248
282
|
return {
|
|
249
283
|
glanceHeadline: copy.allClear, glanceDetail: copy.nothingWaiting, glanceTime: "", hideGlanceTime: true,
|
|
250
|
-
glanceSymbol: "checkmark", glanceSecondary: "", hideGlanceSecondary: true, glanceAllClear: true,
|
|
284
|
+
glanceSymbol: "checkmark", glanceSecondary: "", hideGlanceSecondary: true, glanceAllClear: true, glanceLabel: NOW_LABEL,
|
|
251
285
|
lockInline: copy.allClear, lockCircValue: "0", lockCircLabel: "waiting",
|
|
252
286
|
lockRectTitle: copy.allClear, lockRectDetail: copy.nothingWaiting, lockRectSecondary: "", lockHideSecondary: true,
|
|
253
287
|
};
|
|
@@ -263,6 +297,7 @@ export function glanceFields(ranked: GlanceItem[], copy: GlanceCopy): GlanceFiel
|
|
|
263
297
|
glanceSecondary: secondary,
|
|
264
298
|
hideGlanceSecondary: !secondary,
|
|
265
299
|
glanceAllClear: false,
|
|
300
|
+
glanceLabel: NOW_LABEL,
|
|
266
301
|
lockInline: rest[0] ? `${head.lockTitle} · ${rest[0]}` : head.lockTitle,
|
|
267
302
|
lockCircValue: head.circValue,
|
|
268
303
|
lockCircLabel: head.circLabel,
|
|
@@ -23,7 +23,7 @@ import { queryEvents } from "@himalaya/wix-events";
|
|
|
23
23
|
import { queryDraftPosts } from "@himalaya/wix-blog";
|
|
24
24
|
import {
|
|
25
25
|
str, hhmm, sameLocalDay, dayLabel, rankItems, glanceFields, bookingItems, orderItems, eventItems, blogItems, shownUntil,
|
|
26
|
-
GLANCE_COPY, type GlanceFields,
|
|
26
|
+
GLANCE_COPY, focusFields, focusList, type GlanceFields, type GlanceFocus, type GlanceFocusOption,
|
|
27
27
|
} from "./glance.js";
|
|
28
28
|
|
|
29
29
|
export { isSectionUnavailable, isSignedOut, dayLabel };
|
|
@@ -46,6 +46,10 @@ export interface TodayBooking {
|
|
|
46
46
|
/** The glance ("what matters now", glance.ts) rides on the same state: the existing fields stay
|
|
47
47
|
* for the embedding hosts that bind them (the embedding guide), the glance fields are added. */
|
|
48
48
|
export interface TodayState extends GlanceFields {
|
|
49
|
+
/** The glance for each focus a widget may be set to ("now" + the provisioned areas). */
|
|
50
|
+
focuses: Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
51
|
+
/** Those focuses with owner-facing titles, in order — the widget picker's list. */
|
|
52
|
+
focusList: GlanceFocusOption[];
|
|
49
53
|
eventsReady: boolean;
|
|
50
54
|
blogReady: boolean;
|
|
51
55
|
status: "loading" | "ready" | "error" | "signedOut";
|
|
@@ -147,7 +151,7 @@ function upcoming(rows: Rec[] | null, statuses: string[], now: Date): Rec[] {
|
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
/** Pure: shape what was read into the widget state. `now` is injectable for tests. */
|
|
150
|
-
export function shape(sources: Sources, now: Date, siteName: string): TodayState {
|
|
154
|
+
export function shape(sources: Sources, now: Date, siteName: string, provisioned: Verticals = buildVerticals()): TodayState {
|
|
151
155
|
const bookingsReady = sources.bookings !== null && sources.requests !== null;
|
|
152
156
|
const ordersReady = sources.orders !== null;
|
|
153
157
|
// Re-filtered even though the queries filter: a server (or a fixture) that returns a
|
|
@@ -184,14 +188,30 @@ export function shape(sources: Sources, now: Date, siteName: string): TodayState
|
|
|
184
188
|
// the next booking already did: the frame's lifetime ends at the first of them.
|
|
185
189
|
const headAt = shownUntil(ranked);
|
|
186
190
|
// Nothing could be read at all: the glance shows the degrade line, never "All clear".
|
|
187
|
-
const glance = nothing
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
const glance = nothing ? degradeGlance(COPY.nothing) : glanceFields(ranked, GLANCE_COPY);
|
|
192
|
+
// One glance per focus a widget may be set to (PR 2): "now" is the glance above, an area keeps
|
|
193
|
+
// only its own items. The phone publishes one frame per focus from the same descriptors.
|
|
194
|
+
const options = focusList(provisioned);
|
|
195
|
+
// Each focus's frame ends when an item IT shows starts — an Events widget headlines an event
|
|
196
|
+
// that may be 4th in "now" — so it carries its own `validUntil`, laid over the state's.
|
|
197
|
+
const ownEnd = (f: GlanceFocus) => f === "now"
|
|
198
|
+
? Math.floor(Math.min(midnight, nextStart, headAt) / 1000)
|
|
199
|
+
: Math.floor(Math.min(midnight, shownUntil(ranked.filter((i) => i.area === f))) / 1000);
|
|
200
|
+
// An area focus stands only on its own read: when that read failed (428/404/403, a network
|
|
201
|
+
// error) the widget pinned to it shows the degrade line, never an All clear it cannot vouch for.
|
|
202
|
+
const areaReady: Record<GlanceFocus, boolean> = {
|
|
203
|
+
now: !nothing, bookings: bookingsReady, store: ordersReady, events: eventsReady, blog: blogReady,
|
|
204
|
+
};
|
|
205
|
+
const focuses = Object.fromEntries(options.map((f) => [f.id, {
|
|
206
|
+
...(!areaReady[f.id]
|
|
207
|
+
? { ...degradeGlance(COPY.nothing), glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel }
|
|
208
|
+
: focusFields(ranked, f.id, GLANCE_COPY)),
|
|
209
|
+
validUntil: ownEnd(f.id),
|
|
210
|
+
}])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
193
211
|
return {
|
|
194
212
|
...glance,
|
|
213
|
+
focuses,
|
|
214
|
+
focusList: options,
|
|
195
215
|
eventsReady,
|
|
196
216
|
blogReady,
|
|
197
217
|
validUntil: Math.floor(Math.min(midnight, nextStart, headAt) / 1000),
|
|
@@ -228,11 +248,25 @@ export function degraded(status: "error" | "signedOut" | "loading", siteName: st
|
|
|
228
248
|
// validUntil pinned too: shape() derives it from LOCAL midnight, so even at a fixed instant it
|
|
229
249
|
// would vary with the build machine's timezone and change the baked services hash.
|
|
230
250
|
// The glance shows the degrade line too, never "All clear": a frame that could not read the
|
|
231
|
-
// business must not tell the owner nothing is waiting.
|
|
251
|
+
// business must not tell the owner nothing is waiting. Every focus says the same line.
|
|
252
|
+
const line = degradeGlance(message);
|
|
232
253
|
return {
|
|
233
254
|
...base, status, message, hideMessage: !message, validUntil: 0,
|
|
255
|
+
...line,
|
|
256
|
+
// Each focus keeps its own header ("Orders"), only the line is the degrade one.
|
|
257
|
+
focuses: Object.fromEntries(base.focusList.map((f) => [f.id,
|
|
258
|
+
{ ...line, glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel, validUntil: 0 }])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The glance of a frame that could not read the business: its one line in every slot, never
|
|
263
|
+
* "All clear", and never an empty Lock Screen circle. */
|
|
264
|
+
function degradeGlance(message: string): GlanceFields {
|
|
265
|
+
return {
|
|
266
|
+
...glanceFields([], GLANCE_COPY),
|
|
234
267
|
glanceHeadline: message, glanceDetail: "", glanceAllClear: false, glanceSymbol: "",
|
|
235
|
-
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
268
|
+
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
269
|
+
lockCircValue: message ? "—" : "", lockCircLabel: message ? "Owner" : "",
|
|
236
270
|
};
|
|
237
271
|
}
|
|
238
272
|
|
|
@@ -68879,7 +68879,7 @@ const SCREENS = runtimeSetting({
|
|
|
68879
68879
|
"package": "himalaya",
|
|
68880
68880
|
"type": "Text",
|
|
68881
68881
|
"props": {
|
|
68882
|
-
"text": "
|
|
68882
|
+
"text": "$service:ownerToday.glanceLabel",
|
|
68883
68883
|
"style": "caption",
|
|
68884
68884
|
"color": "textSecondary",
|
|
68885
68885
|
"maxLines": 1
|
|
@@ -67,6 +67,8 @@ export interface GlanceFields {
|
|
|
67
67
|
glanceSecondary: string;
|
|
68
68
|
hideGlanceSecondary: boolean;
|
|
69
69
|
glanceAllClear: boolean;
|
|
70
|
+
/** The widget header: "Now" for the ranking, the area's name for a pinned focus. */
|
|
71
|
+
glanceLabel: string;
|
|
70
72
|
lockInline: string;
|
|
71
73
|
lockCircValue: string;
|
|
72
74
|
lockCircLabel: string;
|
|
@@ -234,6 +236,38 @@ export function rankItems(items: GlanceItem[]): GlanceItem[] {
|
|
|
234
236
|
|| AREA_ORDER.indexOf(a.area) - AREA_ORDER.indexOf(b.area));
|
|
235
237
|
}
|
|
236
238
|
|
|
239
|
+
/** What one placed widget shows: everything ranked ("now"), or one area only. */
|
|
240
|
+
export type GlanceFocus = "now" | GlanceArea;
|
|
241
|
+
|
|
242
|
+
export interface GlanceFocusOption {
|
|
243
|
+
id: GlanceFocus;
|
|
244
|
+
title: string;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The small widget's header for the ranking: short, because it sits beside an icon in 2×2. */
|
|
248
|
+
const NOW_LABEL = "Now";
|
|
249
|
+
|
|
250
|
+
const FOCUS_TITLES: Record<GlanceFocus, string> = {
|
|
251
|
+
now: "What matters now",
|
|
252
|
+
bookings: "Bookings",
|
|
253
|
+
store: "Orders",
|
|
254
|
+
events: "Events",
|
|
255
|
+
blog: "Blog",
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/** The focuses a widget may be set to: "now", then the areas this build provisions, in the
|
|
259
|
+
* canonical order. Stable from first launch: it follows the build, not what a read returned. */
|
|
260
|
+
export function focusList(provisioned: Record<GlanceArea, boolean>): GlanceFocusOption[] {
|
|
261
|
+
return (["now", ...AREA_ORDER.filter((a) => provisioned[a])] as GlanceFocus[]).map((id) => ({ id, title: FOCUS_TITLES[id] }));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The glance for one focus: "now" is the whole ranking; an area keeps only its own items, so a
|
|
265
|
+
* widget pinned to Orders never shows a booking. An area with nothing is its own All clear. */
|
|
266
|
+
export function focusFields(ranked: GlanceItem[], focus: GlanceFocus, copy: GlanceCopy): GlanceFields {
|
|
267
|
+
const fields = glanceFields(focus === "now" ? ranked : ranked.filter((i) => i.area === focus), copy);
|
|
268
|
+
return { ...fields, glanceLabel: focus === "now" ? NOW_LABEL : FOCUS_TITLES[focus] };
|
|
269
|
+
}
|
|
270
|
+
|
|
237
271
|
/** When the frame stops being true: the earliest moment among the items it SHOWS (the headline
|
|
238
272
|
* and the two on the secondary line). A started booking, event or post is no longer "next". */
|
|
239
273
|
export function shownUntil(ranked: GlanceItem[]): number {
|
|
@@ -247,7 +281,7 @@ export function glanceFields(ranked: GlanceItem[], copy: GlanceCopy): GlanceFiel
|
|
|
247
281
|
if (!head) {
|
|
248
282
|
return {
|
|
249
283
|
glanceHeadline: copy.allClear, glanceDetail: copy.nothingWaiting, glanceTime: "", hideGlanceTime: true,
|
|
250
|
-
glanceSymbol: "checkmark", glanceSecondary: "", hideGlanceSecondary: true, glanceAllClear: true,
|
|
284
|
+
glanceSymbol: "checkmark", glanceSecondary: "", hideGlanceSecondary: true, glanceAllClear: true, glanceLabel: NOW_LABEL,
|
|
251
285
|
lockInline: copy.allClear, lockCircValue: "0", lockCircLabel: "waiting",
|
|
252
286
|
lockRectTitle: copy.allClear, lockRectDetail: copy.nothingWaiting, lockRectSecondary: "", lockHideSecondary: true,
|
|
253
287
|
};
|
|
@@ -263,6 +297,7 @@ export function glanceFields(ranked: GlanceItem[], copy: GlanceCopy): GlanceFiel
|
|
|
263
297
|
glanceSecondary: secondary,
|
|
264
298
|
hideGlanceSecondary: !secondary,
|
|
265
299
|
glanceAllClear: false,
|
|
300
|
+
glanceLabel: NOW_LABEL,
|
|
266
301
|
lockInline: rest[0] ? `${head.lockTitle} · ${rest[0]}` : head.lockTitle,
|
|
267
302
|
lockCircValue: head.circValue,
|
|
268
303
|
lockCircLabel: head.circLabel,
|
|
@@ -23,7 +23,7 @@ import { queryEvents } from "@himalaya/wix-events";
|
|
|
23
23
|
import { queryDraftPosts } from "@himalaya/wix-blog";
|
|
24
24
|
import {
|
|
25
25
|
str, hhmm, sameLocalDay, dayLabel, rankItems, glanceFields, bookingItems, orderItems, eventItems, blogItems, shownUntil,
|
|
26
|
-
GLANCE_COPY, type GlanceFields,
|
|
26
|
+
GLANCE_COPY, focusFields, focusList, type GlanceFields, type GlanceFocus, type GlanceFocusOption,
|
|
27
27
|
} from "./glance.js";
|
|
28
28
|
|
|
29
29
|
export { isSectionUnavailable, isSignedOut, dayLabel };
|
|
@@ -46,6 +46,10 @@ export interface TodayBooking {
|
|
|
46
46
|
/** The glance ("what matters now", glance.ts) rides on the same state: the existing fields stay
|
|
47
47
|
* for the embedding hosts that bind them (the embedding guide), the glance fields are added. */
|
|
48
48
|
export interface TodayState extends GlanceFields {
|
|
49
|
+
/** The glance for each focus a widget may be set to ("now" + the provisioned areas). */
|
|
50
|
+
focuses: Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
51
|
+
/** Those focuses with owner-facing titles, in order — the widget picker's list. */
|
|
52
|
+
focusList: GlanceFocusOption[];
|
|
49
53
|
eventsReady: boolean;
|
|
50
54
|
blogReady: boolean;
|
|
51
55
|
status: "loading" | "ready" | "error" | "signedOut";
|
|
@@ -147,7 +151,7 @@ function upcoming(rows: Rec[] | null, statuses: string[], now: Date): Rec[] {
|
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
/** Pure: shape what was read into the widget state. `now` is injectable for tests. */
|
|
150
|
-
export function shape(sources: Sources, now: Date, siteName: string): TodayState {
|
|
154
|
+
export function shape(sources: Sources, now: Date, siteName: string, provisioned: Verticals = buildVerticals()): TodayState {
|
|
151
155
|
const bookingsReady = sources.bookings !== null && sources.requests !== null;
|
|
152
156
|
const ordersReady = sources.orders !== null;
|
|
153
157
|
// Re-filtered even though the queries filter: a server (or a fixture) that returns a
|
|
@@ -184,14 +188,30 @@ export function shape(sources: Sources, now: Date, siteName: string): TodayState
|
|
|
184
188
|
// the next booking already did: the frame's lifetime ends at the first of them.
|
|
185
189
|
const headAt = shownUntil(ranked);
|
|
186
190
|
// Nothing could be read at all: the glance shows the degrade line, never "All clear".
|
|
187
|
-
const glance = nothing
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
const glance = nothing ? degradeGlance(COPY.nothing) : glanceFields(ranked, GLANCE_COPY);
|
|
192
|
+
// One glance per focus a widget may be set to (PR 2): "now" is the glance above, an area keeps
|
|
193
|
+
// only its own items. The phone publishes one frame per focus from the same descriptors.
|
|
194
|
+
const options = focusList(provisioned);
|
|
195
|
+
// Each focus's frame ends when an item IT shows starts — an Events widget headlines an event
|
|
196
|
+
// that may be 4th in "now" — so it carries its own `validUntil`, laid over the state's.
|
|
197
|
+
const ownEnd = (f: GlanceFocus) => f === "now"
|
|
198
|
+
? Math.floor(Math.min(midnight, nextStart, headAt) / 1000)
|
|
199
|
+
: Math.floor(Math.min(midnight, shownUntil(ranked.filter((i) => i.area === f))) / 1000);
|
|
200
|
+
// An area focus stands only on its own read: when that read failed (428/404/403, a network
|
|
201
|
+
// error) the widget pinned to it shows the degrade line, never an All clear it cannot vouch for.
|
|
202
|
+
const areaReady: Record<GlanceFocus, boolean> = {
|
|
203
|
+
now: !nothing, bookings: bookingsReady, store: ordersReady, events: eventsReady, blog: blogReady,
|
|
204
|
+
};
|
|
205
|
+
const focuses = Object.fromEntries(options.map((f) => [f.id, {
|
|
206
|
+
...(!areaReady[f.id]
|
|
207
|
+
? { ...degradeGlance(COPY.nothing), glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel }
|
|
208
|
+
: focusFields(ranked, f.id, GLANCE_COPY)),
|
|
209
|
+
validUntil: ownEnd(f.id),
|
|
210
|
+
}])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
193
211
|
return {
|
|
194
212
|
...glance,
|
|
213
|
+
focuses,
|
|
214
|
+
focusList: options,
|
|
195
215
|
eventsReady,
|
|
196
216
|
blogReady,
|
|
197
217
|
validUntil: Math.floor(Math.min(midnight, nextStart, headAt) / 1000),
|
|
@@ -228,11 +248,25 @@ export function degraded(status: "error" | "signedOut" | "loading", siteName: st
|
|
|
228
248
|
// validUntil pinned too: shape() derives it from LOCAL midnight, so even at a fixed instant it
|
|
229
249
|
// would vary with the build machine's timezone and change the baked services hash.
|
|
230
250
|
// The glance shows the degrade line too, never "All clear": a frame that could not read the
|
|
231
|
-
// business must not tell the owner nothing is waiting.
|
|
251
|
+
// business must not tell the owner nothing is waiting. Every focus says the same line.
|
|
252
|
+
const line = degradeGlance(message);
|
|
232
253
|
return {
|
|
233
254
|
...base, status, message, hideMessage: !message, validUntil: 0,
|
|
255
|
+
...line,
|
|
256
|
+
// Each focus keeps its own header ("Orders"), only the line is the degrade one.
|
|
257
|
+
focuses: Object.fromEntries(base.focusList.map((f) => [f.id,
|
|
258
|
+
{ ...line, glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel, validUntil: 0 }])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The glance of a frame that could not read the business: its one line in every slot, never
|
|
263
|
+
* "All clear", and never an empty Lock Screen circle. */
|
|
264
|
+
function degradeGlance(message: string): GlanceFields {
|
|
265
|
+
return {
|
|
266
|
+
...glanceFields([], GLANCE_COPY),
|
|
234
267
|
glanceHeadline: message, glanceDetail: "", glanceAllClear: false, glanceSymbol: "",
|
|
235
|
-
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
268
|
+
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
269
|
+
lockCircValue: message ? "—" : "", lockCircLabel: message ? "Owner" : "",
|
|
236
270
|
};
|
|
237
271
|
}
|
|
238
272
|
|
|
@@ -69256,7 +69256,7 @@ const SCREENS = runtimeSetting({
|
|
|
69256
69256
|
"package": "himalaya",
|
|
69257
69257
|
"type": "Text",
|
|
69258
69258
|
"props": {
|
|
69259
|
-
"text": "
|
|
69259
|
+
"text": "$service:ownerToday.glanceLabel",
|
|
69260
69260
|
"style": "caption",
|
|
69261
69261
|
"color": "textSecondary",
|
|
69262
69262
|
"maxLines": 1
|
|
@@ -67,6 +67,8 @@ export interface GlanceFields {
|
|
|
67
67
|
glanceSecondary: string;
|
|
68
68
|
hideGlanceSecondary: boolean;
|
|
69
69
|
glanceAllClear: boolean;
|
|
70
|
+
/** The widget header: "Now" for the ranking, the area's name for a pinned focus. */
|
|
71
|
+
glanceLabel: string;
|
|
70
72
|
lockInline: string;
|
|
71
73
|
lockCircValue: string;
|
|
72
74
|
lockCircLabel: string;
|
|
@@ -234,6 +236,38 @@ export function rankItems(items: GlanceItem[]): GlanceItem[] {
|
|
|
234
236
|
|| AREA_ORDER.indexOf(a.area) - AREA_ORDER.indexOf(b.area));
|
|
235
237
|
}
|
|
236
238
|
|
|
239
|
+
/** What one placed widget shows: everything ranked ("now"), or one area only. */
|
|
240
|
+
export type GlanceFocus = "now" | GlanceArea;
|
|
241
|
+
|
|
242
|
+
export interface GlanceFocusOption {
|
|
243
|
+
id: GlanceFocus;
|
|
244
|
+
title: string;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The small widget's header for the ranking: short, because it sits beside an icon in 2×2. */
|
|
248
|
+
const NOW_LABEL = "Now";
|
|
249
|
+
|
|
250
|
+
const FOCUS_TITLES: Record<GlanceFocus, string> = {
|
|
251
|
+
now: "What matters now",
|
|
252
|
+
bookings: "Bookings",
|
|
253
|
+
store: "Orders",
|
|
254
|
+
events: "Events",
|
|
255
|
+
blog: "Blog",
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/** The focuses a widget may be set to: "now", then the areas this build provisions, in the
|
|
259
|
+
* canonical order. Stable from first launch: it follows the build, not what a read returned. */
|
|
260
|
+
export function focusList(provisioned: Record<GlanceArea, boolean>): GlanceFocusOption[] {
|
|
261
|
+
return (["now", ...AREA_ORDER.filter((a) => provisioned[a])] as GlanceFocus[]).map((id) => ({ id, title: FOCUS_TITLES[id] }));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The glance for one focus: "now" is the whole ranking; an area keeps only its own items, so a
|
|
265
|
+
* widget pinned to Orders never shows a booking. An area with nothing is its own All clear. */
|
|
266
|
+
export function focusFields(ranked: GlanceItem[], focus: GlanceFocus, copy: GlanceCopy): GlanceFields {
|
|
267
|
+
const fields = glanceFields(focus === "now" ? ranked : ranked.filter((i) => i.area === focus), copy);
|
|
268
|
+
return { ...fields, glanceLabel: focus === "now" ? NOW_LABEL : FOCUS_TITLES[focus] };
|
|
269
|
+
}
|
|
270
|
+
|
|
237
271
|
/** When the frame stops being true: the earliest moment among the items it SHOWS (the headline
|
|
238
272
|
* and the two on the secondary line). A started booking, event or post is no longer "next". */
|
|
239
273
|
export function shownUntil(ranked: GlanceItem[]): number {
|
|
@@ -247,7 +281,7 @@ export function glanceFields(ranked: GlanceItem[], copy: GlanceCopy): GlanceFiel
|
|
|
247
281
|
if (!head) {
|
|
248
282
|
return {
|
|
249
283
|
glanceHeadline: copy.allClear, glanceDetail: copy.nothingWaiting, glanceTime: "", hideGlanceTime: true,
|
|
250
|
-
glanceSymbol: "checkmark", glanceSecondary: "", hideGlanceSecondary: true, glanceAllClear: true,
|
|
284
|
+
glanceSymbol: "checkmark", glanceSecondary: "", hideGlanceSecondary: true, glanceAllClear: true, glanceLabel: NOW_LABEL,
|
|
251
285
|
lockInline: copy.allClear, lockCircValue: "0", lockCircLabel: "waiting",
|
|
252
286
|
lockRectTitle: copy.allClear, lockRectDetail: copy.nothingWaiting, lockRectSecondary: "", lockHideSecondary: true,
|
|
253
287
|
};
|
|
@@ -263,6 +297,7 @@ export function glanceFields(ranked: GlanceItem[], copy: GlanceCopy): GlanceFiel
|
|
|
263
297
|
glanceSecondary: secondary,
|
|
264
298
|
hideGlanceSecondary: !secondary,
|
|
265
299
|
glanceAllClear: false,
|
|
300
|
+
glanceLabel: NOW_LABEL,
|
|
266
301
|
lockInline: rest[0] ? `${head.lockTitle} · ${rest[0]}` : head.lockTitle,
|
|
267
302
|
lockCircValue: head.circValue,
|
|
268
303
|
lockCircLabel: head.circLabel,
|
|
@@ -23,7 +23,7 @@ import { queryEvents } from "@himalaya/wix-events";
|
|
|
23
23
|
import { queryDraftPosts } from "@himalaya/wix-blog";
|
|
24
24
|
import {
|
|
25
25
|
str, hhmm, sameLocalDay, dayLabel, rankItems, glanceFields, bookingItems, orderItems, eventItems, blogItems, shownUntil,
|
|
26
|
-
GLANCE_COPY, type GlanceFields,
|
|
26
|
+
GLANCE_COPY, focusFields, focusList, type GlanceFields, type GlanceFocus, type GlanceFocusOption,
|
|
27
27
|
} from "./glance.js";
|
|
28
28
|
|
|
29
29
|
export { isSectionUnavailable, isSignedOut, dayLabel };
|
|
@@ -46,6 +46,10 @@ export interface TodayBooking {
|
|
|
46
46
|
/** The glance ("what matters now", glance.ts) rides on the same state: the existing fields stay
|
|
47
47
|
* for the embedding hosts that bind them (the embedding guide), the glance fields are added. */
|
|
48
48
|
export interface TodayState extends GlanceFields {
|
|
49
|
+
/** The glance for each focus a widget may be set to ("now" + the provisioned areas). */
|
|
50
|
+
focuses: Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
51
|
+
/** Those focuses with owner-facing titles, in order — the widget picker's list. */
|
|
52
|
+
focusList: GlanceFocusOption[];
|
|
49
53
|
eventsReady: boolean;
|
|
50
54
|
blogReady: boolean;
|
|
51
55
|
status: "loading" | "ready" | "error" | "signedOut";
|
|
@@ -147,7 +151,7 @@ function upcoming(rows: Rec[] | null, statuses: string[], now: Date): Rec[] {
|
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
/** Pure: shape what was read into the widget state. `now` is injectable for tests. */
|
|
150
|
-
export function shape(sources: Sources, now: Date, siteName: string): TodayState {
|
|
154
|
+
export function shape(sources: Sources, now: Date, siteName: string, provisioned: Verticals = buildVerticals()): TodayState {
|
|
151
155
|
const bookingsReady = sources.bookings !== null && sources.requests !== null;
|
|
152
156
|
const ordersReady = sources.orders !== null;
|
|
153
157
|
// Re-filtered even though the queries filter: a server (or a fixture) that returns a
|
|
@@ -184,14 +188,30 @@ export function shape(sources: Sources, now: Date, siteName: string): TodayState
|
|
|
184
188
|
// the next booking already did: the frame's lifetime ends at the first of them.
|
|
185
189
|
const headAt = shownUntil(ranked);
|
|
186
190
|
// Nothing could be read at all: the glance shows the degrade line, never "All clear".
|
|
187
|
-
const glance = nothing
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
const glance = nothing ? degradeGlance(COPY.nothing) : glanceFields(ranked, GLANCE_COPY);
|
|
192
|
+
// One glance per focus a widget may be set to (PR 2): "now" is the glance above, an area keeps
|
|
193
|
+
// only its own items. The phone publishes one frame per focus from the same descriptors.
|
|
194
|
+
const options = focusList(provisioned);
|
|
195
|
+
// Each focus's frame ends when an item IT shows starts — an Events widget headlines an event
|
|
196
|
+
// that may be 4th in "now" — so it carries its own `validUntil`, laid over the state's.
|
|
197
|
+
const ownEnd = (f: GlanceFocus) => f === "now"
|
|
198
|
+
? Math.floor(Math.min(midnight, nextStart, headAt) / 1000)
|
|
199
|
+
: Math.floor(Math.min(midnight, shownUntil(ranked.filter((i) => i.area === f))) / 1000);
|
|
200
|
+
// An area focus stands only on its own read: when that read failed (428/404/403, a network
|
|
201
|
+
// error) the widget pinned to it shows the degrade line, never an All clear it cannot vouch for.
|
|
202
|
+
const areaReady: Record<GlanceFocus, boolean> = {
|
|
203
|
+
now: !nothing, bookings: bookingsReady, store: ordersReady, events: eventsReady, blog: blogReady,
|
|
204
|
+
};
|
|
205
|
+
const focuses = Object.fromEntries(options.map((f) => [f.id, {
|
|
206
|
+
...(!areaReady[f.id]
|
|
207
|
+
? { ...degradeGlance(COPY.nothing), glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel }
|
|
208
|
+
: focusFields(ranked, f.id, GLANCE_COPY)),
|
|
209
|
+
validUntil: ownEnd(f.id),
|
|
210
|
+
}])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>;
|
|
193
211
|
return {
|
|
194
212
|
...glance,
|
|
213
|
+
focuses,
|
|
214
|
+
focusList: options,
|
|
195
215
|
eventsReady,
|
|
196
216
|
blogReady,
|
|
197
217
|
validUntil: Math.floor(Math.min(midnight, nextStart, headAt) / 1000),
|
|
@@ -228,11 +248,25 @@ export function degraded(status: "error" | "signedOut" | "loading", siteName: st
|
|
|
228
248
|
// validUntil pinned too: shape() derives it from LOCAL midnight, so even at a fixed instant it
|
|
229
249
|
// would vary with the build machine's timezone and change the baked services hash.
|
|
230
250
|
// The glance shows the degrade line too, never "All clear": a frame that could not read the
|
|
231
|
-
// business must not tell the owner nothing is waiting.
|
|
251
|
+
// business must not tell the owner nothing is waiting. Every focus says the same line.
|
|
252
|
+
const line = degradeGlance(message);
|
|
232
253
|
return {
|
|
233
254
|
...base, status, message, hideMessage: !message, validUntil: 0,
|
|
255
|
+
...line,
|
|
256
|
+
// Each focus keeps its own header ("Orders"), only the line is the degrade one.
|
|
257
|
+
focuses: Object.fromEntries(base.focusList.map((f) => [f.id,
|
|
258
|
+
{ ...line, glanceLabel: focusFields([], f.id, GLANCE_COPY).glanceLabel, validUntil: 0 }])) as Record<GlanceFocus, GlanceFields & { validUntil: number }>,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The glance of a frame that could not read the business: its one line in every slot, never
|
|
263
|
+
* "All clear", and never an empty Lock Screen circle. */
|
|
264
|
+
function degradeGlance(message: string): GlanceFields {
|
|
265
|
+
return {
|
|
266
|
+
...glanceFields([], GLANCE_COPY),
|
|
234
267
|
glanceHeadline: message, glanceDetail: "", glanceAllClear: false, glanceSymbol: "",
|
|
235
|
-
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
268
|
+
lockInline: message, lockRectTitle: message, lockRectDetail: "",
|
|
269
|
+
lockCircValue: message ? "—" : "", lockCircLabel: message ? "Owner" : "",
|
|
236
270
|
};
|
|
237
271
|
}
|
|
238
272
|
|
|
@@ -69186,7 +69186,7 @@ const SCREENS = runtimeSetting({
|
|
|
69186
69186
|
"package": "himalaya",
|
|
69187
69187
|
"type": "Text",
|
|
69188
69188
|
"props": {
|
|
69189
|
-
"text": "
|
|
69189
|
+
"text": "$service:ownerToday.glanceLabel",
|
|
69190
69190
|
"style": "caption",
|
|
69191
69191
|
"color": "textSecondary",
|
|
69192
69192
|
"maxLines": 1
|