@wix/himalaya-cli 0.1211.0 → 0.1213.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 +20 -21
- package/dist/preview-assets.generated.bin +0 -0
- package/package.json +2 -2
- package/templates/beauty-salon-owner/dev/index.ts +218 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/community-club-owner/dev/index.ts +327 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/community-club-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/community-club-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/events-meetups-owner/dev/index.ts +218 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/gym-fitness-owner/dev/index.ts +327 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/nonprofit-cause-owner/dev/index.ts +218 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/owner-lite/dev/index.ts +327 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/owner-lite/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/owner-lite/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/podcast-creator-owner/dev/index.ts +327 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/portfolio-creative-owner/dev/index.ts +218 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/restaurant-owner/dev/index.ts +327 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/retail-store-owner/dev/index.ts +218 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
- package/templates/yoga-studio-owner/dev/index.ts +218 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
|
@@ -59,6 +59,9 @@ interface ProductState {
|
|
|
59
59
|
/** Non-empty when showing owner-preview-demo sample data (web preview, no owner bridge). */
|
|
60
60
|
demoNote: string;
|
|
61
61
|
notDemo: boolean;
|
|
62
|
+
/** #3158 — Delete ARMS a confirmation; only confirmDelete reaches the API. */
|
|
63
|
+
deletePending: boolean;
|
|
64
|
+
noDeleteConfirmation: boolean;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -143,6 +146,9 @@ function shape(s: Partial<ProductState>): ProductState {
|
|
|
143
146
|
hideHide: !visible || status !== "ready",
|
|
144
147
|
demoNote: s.demoNote ?? "",
|
|
145
148
|
notDemo: !s.demoNote,
|
|
149
|
+
// Only a loaded entity can be pending deletion; every other action disarms it (`disarm`).
|
|
150
|
+
deletePending: !!s.deletePending && hasEntity,
|
|
151
|
+
noDeleteConfirmation: !(s.deletePending && hasEntity),
|
|
146
152
|
};
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -265,16 +271,33 @@ async function setVisibility(s: ProductState, visible: boolean, msg: string): Pr
|
|
|
265
271
|
}
|
|
266
272
|
}
|
|
267
273
|
|
|
274
|
+
/** #3158 — a confirmed delete in flight. Synchronous and module-level on purpose: two
|
|
275
|
+
* confirmDelete dispatches (a double tap) both start from a state that says "armed", and only a
|
|
276
|
+
* flag set BEFORE the first await stops the second from issuing its own DELETE — whose late 404
|
|
277
|
+
* would otherwise land after, and overwrite, the first one's "deleted". */
|
|
278
|
+
let deleteInFlight = false;
|
|
279
|
+
|
|
280
|
+
/** #3158 — the confirmation describes THIS visit. Never take it from a persisted snapshot, or a
|
|
281
|
+
* reopened record comes back with "Delete this …?" already armed. */
|
|
282
|
+
const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
|
|
283
|
+
|
|
284
|
+
/** #3158 — clear an armed delete confirmation. */
|
|
285
|
+
const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
|
|
286
|
+
|
|
268
287
|
const svc = defineService<ProductState, {
|
|
269
288
|
load: (s: ProductState, arg?: unknown) => Promise<ProductState>;
|
|
270
289
|
retry: (s: ProductState) => Promise<ProductState>;
|
|
271
290
|
show: (s: ProductState) => Promise<ProductState>;
|
|
272
291
|
hide: (s: ProductState) => Promise<ProductState>;
|
|
273
292
|
delete: (s: ProductState) => Promise<ProductState>;
|
|
293
|
+
cancelDelete: (s: ProductState) => Promise<ProductState>;
|
|
294
|
+
confirmDelete: (s: ProductState) => Promise<ProductState | undefined>;
|
|
274
295
|
}>("himiOwnerLiteProduct", {
|
|
275
296
|
state: shape({ status: "loading" }),
|
|
297
|
+
notHydrated: [...DELETE_RUN_KEYS],
|
|
276
298
|
actions: {
|
|
277
|
-
load: async (
|
|
299
|
+
load: async (s0, arg) => {
|
|
300
|
+
const s = disarm(s0);
|
|
278
301
|
stashCopy(arg); // absorb the descriptor's onAppear copy-pack param
|
|
279
302
|
const id = idFrom(arg, s.id) || inputId();
|
|
280
303
|
if (!id) return shape({ ...s, status: "error", error: copyParam("ownerProduct.errorNoId", "no product id") });
|
|
@@ -297,7 +320,8 @@ const svc = defineService<ProductState, {
|
|
|
297
320
|
return shape({ ...s, id, status: "error", error: ownerLoadError(e) });
|
|
298
321
|
}
|
|
299
322
|
},
|
|
300
|
-
retry: async (
|
|
323
|
+
retry: async (s0) => {
|
|
324
|
+
const s = disarm(s0);
|
|
301
325
|
if (!s.id) return shape({ ...s, status: "error", error: copyParam("ownerProduct.errorNoId", "no product id") });
|
|
302
326
|
if (isOwnerPreviewDemo()) {
|
|
303
327
|
const demo = demoDetail(s, s.id);
|
|
@@ -317,25 +341,46 @@ const svc = defineService<ProductState, {
|
|
|
317
341
|
return shape({ ...s, status: "error", error: ownerLoadError(e) });
|
|
318
342
|
}
|
|
319
343
|
},
|
|
320
|
-
show: async (
|
|
321
|
-
hide: async (
|
|
322
|
-
delete
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
344
|
+
show: async (s0) => { const s = disarm(s0); return setVisibility(s, true, copyParam("ownerProduct.shownMessage", "Product is now visible in your store.")); },
|
|
345
|
+
hide: async (s0) => { const s = disarm(s0); return setVisibility(s, false, copyParam("ownerProduct.hiddenMessage", "Product hidden from your store.")); },
|
|
346
|
+
// #3158 — destructive, so two steps. `delete` (the Manage card's Delete button)
|
|
347
|
+
// only ARMS the inline confirmation, which names the record and says it cannot
|
|
348
|
+
// be undone; `cancelDelete` disarms it; only `confirmDelete` deletes. Anything
|
|
349
|
+
// that dispatches `delete` directly therefore still asks first.
|
|
350
|
+
delete: async (s) => shape({ ...s, deletePending: true, actionMessage: "" }),
|
|
351
|
+
cancelDelete: async (s) => shape({ ...s, deletePending: false }),
|
|
352
|
+
confirmDelete: async (s0) => {
|
|
353
|
+
// Nothing armed (a stray dispatch, a rehydrated snapshot) or a delete already running
|
|
354
|
+
// (a second tap): ignore it — `undefined` leaves the state exactly as it is.
|
|
355
|
+
if (!s0.deletePending || deleteInFlight) return undefined;
|
|
356
|
+
deleteInFlight = true;
|
|
327
357
|
try {
|
|
328
|
-
|
|
329
|
-
return shape({ ...s,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
358
|
+
const s = disarm(s0);
|
|
359
|
+
if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
360
|
+
if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerProduct.noIdMessage", "No product id.") });
|
|
361
|
+
// Optimistic local delete — the list drops the row immediately.
|
|
362
|
+
await cacheDrop(s.id);
|
|
363
|
+
try {
|
|
364
|
+
await deleteProduct(s.id);
|
|
365
|
+
return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerProduct.deletedEmpty", "Product deleted."), actionMessage: "" });
|
|
366
|
+
} catch (e) {
|
|
367
|
+
if (shouldQueueOwnerWrite(e)) {
|
|
368
|
+
await queueWrite("tier5.himiOwnerLiteProduct.delete", { id: s.id });
|
|
369
|
+
return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerProduct.deletedEmpty", "Product deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
370
|
+
}
|
|
371
|
+
return shape({ ...s, actionMessage: ownerLoadError(e) });
|
|
334
372
|
}
|
|
335
|
-
|
|
373
|
+
} finally {
|
|
374
|
+
deleteInFlight = false;
|
|
336
375
|
}
|
|
337
376
|
},
|
|
338
377
|
},
|
|
339
378
|
});
|
|
340
379
|
|
|
380
|
+
// The same reset on a runtime from before `notHydrated` (an older binary on a new bundle).
|
|
381
|
+
if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
|
|
382
|
+
const booted = svc.getState?.() as unknown as Record<string, unknown> | undefined;
|
|
383
|
+
if (booted && typeof booted === "object") Object.assign(booted, { deletePending: false, noDeleteConfirmation: true });
|
|
384
|
+
}
|
|
385
|
+
|
|
341
386
|
export { svc };
|
|
@@ -69238,6 +69238,115 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
|
|
|
69238
69238
|
}
|
|
69239
69239
|
}
|
|
69240
69240
|
},
|
|
69241
|
+
{
|
|
69242
|
+
"id": "event_delete_confirmation",
|
|
69243
|
+
"body": {
|
|
69244
|
+
"package": "himalaya",
|
|
69245
|
+
"type": "VStack",
|
|
69246
|
+
"props": {
|
|
69247
|
+
"spacing": 10,
|
|
69248
|
+
"alignment": "leading",
|
|
69249
|
+
"children": [
|
|
69250
|
+
{
|
|
69251
|
+
"id": "event_delete_confirmation.title",
|
|
69252
|
+
"body": {
|
|
69253
|
+
"package": "himalaya",
|
|
69254
|
+
"type": "Text",
|
|
69255
|
+
"props": {
|
|
69256
|
+
"text": "Delete this session?",
|
|
69257
|
+
"style": "bodyEmphasis"
|
|
69258
|
+
}
|
|
69259
|
+
}
|
|
69260
|
+
},
|
|
69261
|
+
{
|
|
69262
|
+
"id": "event_delete_confirmation.record",
|
|
69263
|
+
"body": {
|
|
69264
|
+
"package": "himalaya",
|
|
69265
|
+
"type": "Text",
|
|
69266
|
+
"props": {
|
|
69267
|
+
"text": "$service:himiOwnerLiteEvent.title",
|
|
69268
|
+
"style": "body",
|
|
69269
|
+
"color": "textSecondary",
|
|
69270
|
+
"maxLines": 2
|
|
69271
|
+
}
|
|
69272
|
+
}
|
|
69273
|
+
},
|
|
69274
|
+
{
|
|
69275
|
+
"id": "",
|
|
69276
|
+
"body": {
|
|
69277
|
+
"package": "himalaya",
|
|
69278
|
+
"type": "Text",
|
|
69279
|
+
"props": {
|
|
69280
|
+
"text": "This cannot be undone.",
|
|
69281
|
+
"style": "footnote",
|
|
69282
|
+
"color": "textSecondary"
|
|
69283
|
+
}
|
|
69284
|
+
}
|
|
69285
|
+
},
|
|
69286
|
+
{
|
|
69287
|
+
"id": "",
|
|
69288
|
+
"body": {
|
|
69289
|
+
"package": "himalaya",
|
|
69290
|
+
"type": "HStack",
|
|
69291
|
+
"props": {
|
|
69292
|
+
"spacing": 8,
|
|
69293
|
+
"children": [
|
|
69294
|
+
{
|
|
69295
|
+
"id": "event_delete_cancel",
|
|
69296
|
+
"body": {
|
|
69297
|
+
"package": "himalaya",
|
|
69298
|
+
"type": "Button",
|
|
69299
|
+
"props": {
|
|
69300
|
+
"title": "Cancel",
|
|
69301
|
+
"style": "secondary",
|
|
69302
|
+
"action": {
|
|
69303
|
+
"actionId": "tier5.himiOwnerLiteEvent.cancelDelete"
|
|
69304
|
+
}
|
|
69305
|
+
}
|
|
69306
|
+
}
|
|
69307
|
+
},
|
|
69308
|
+
{
|
|
69309
|
+
"id": "event_delete_confirm",
|
|
69310
|
+
"body": {
|
|
69311
|
+
"package": "himalaya",
|
|
69312
|
+
"type": "Button",
|
|
69313
|
+
"props": {
|
|
69314
|
+
"title": "Delete",
|
|
69315
|
+
"style": "destructive",
|
|
69316
|
+
"action": {
|
|
69317
|
+
"actionId": "tier5.himiOwnerLiteEvent.confirmDelete"
|
|
69318
|
+
}
|
|
69319
|
+
}
|
|
69320
|
+
}
|
|
69321
|
+
}
|
|
69322
|
+
]
|
|
69323
|
+
}
|
|
69324
|
+
}
|
|
69325
|
+
}
|
|
69326
|
+
]
|
|
69327
|
+
}
|
|
69328
|
+
},
|
|
69329
|
+
"modifiers": {
|
|
69330
|
+
"background": {
|
|
69331
|
+
"token": "surfaceElevated"
|
|
69332
|
+
},
|
|
69333
|
+
"border": {
|
|
69334
|
+
"width": 1,
|
|
69335
|
+
"color": {
|
|
69336
|
+
"token": "danger"
|
|
69337
|
+
}
|
|
69338
|
+
},
|
|
69339
|
+
"cornerRadius": 12,
|
|
69340
|
+
"padding": {
|
|
69341
|
+
"leading": 14,
|
|
69342
|
+
"trailing": 14,
|
|
69343
|
+
"top": 14,
|
|
69344
|
+
"bottom": 14
|
|
69345
|
+
},
|
|
69346
|
+
"fillMaxWidth": true,
|
|
69347
|
+
"hiddenPath": "$service:himiOwnerLiteEvent.noDeleteConfirmation"
|
|
69348
|
+
}
|
|
69349
|
+
},
|
|
69241
69350
|
{
|
|
69242
69351
|
"id": "",
|
|
69243
69352
|
"body": {
|
|
@@ -70099,6 +70208,115 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
|
|
|
70099
70208
|
}
|
|
70100
70209
|
}
|
|
70101
70210
|
},
|
|
70211
|
+
{
|
|
70212
|
+
"id": "post_delete_confirmation",
|
|
70213
|
+
"body": {
|
|
70214
|
+
"package": "himalaya",
|
|
70215
|
+
"type": "VStack",
|
|
70216
|
+
"props": {
|
|
70217
|
+
"spacing": 10,
|
|
70218
|
+
"alignment": "leading",
|
|
70219
|
+
"children": [
|
|
70220
|
+
{
|
|
70221
|
+
"id": "post_delete_confirmation.title",
|
|
70222
|
+
"body": {
|
|
70223
|
+
"package": "himalaya",
|
|
70224
|
+
"type": "Text",
|
|
70225
|
+
"props": {
|
|
70226
|
+
"text": "Delete this announcement?",
|
|
70227
|
+
"style": "bodyEmphasis"
|
|
70228
|
+
}
|
|
70229
|
+
}
|
|
70230
|
+
},
|
|
70231
|
+
{
|
|
70232
|
+
"id": "post_delete_confirmation.record",
|
|
70233
|
+
"body": {
|
|
70234
|
+
"package": "himalaya",
|
|
70235
|
+
"type": "Text",
|
|
70236
|
+
"props": {
|
|
70237
|
+
"text": "$service:himiOwnerLitePost.title",
|
|
70238
|
+
"style": "body",
|
|
70239
|
+
"color": "textSecondary",
|
|
70240
|
+
"maxLines": 2
|
|
70241
|
+
}
|
|
70242
|
+
}
|
|
70243
|
+
},
|
|
70244
|
+
{
|
|
70245
|
+
"id": "",
|
|
70246
|
+
"body": {
|
|
70247
|
+
"package": "himalaya",
|
|
70248
|
+
"type": "Text",
|
|
70249
|
+
"props": {
|
|
70250
|
+
"text": "This cannot be undone.",
|
|
70251
|
+
"style": "footnote",
|
|
70252
|
+
"color": "textSecondary"
|
|
70253
|
+
}
|
|
70254
|
+
}
|
|
70255
|
+
},
|
|
70256
|
+
{
|
|
70257
|
+
"id": "",
|
|
70258
|
+
"body": {
|
|
70259
|
+
"package": "himalaya",
|
|
70260
|
+
"type": "HStack",
|
|
70261
|
+
"props": {
|
|
70262
|
+
"spacing": 8,
|
|
70263
|
+
"children": [
|
|
70264
|
+
{
|
|
70265
|
+
"id": "post_delete_cancel",
|
|
70266
|
+
"body": {
|
|
70267
|
+
"package": "himalaya",
|
|
70268
|
+
"type": "Button",
|
|
70269
|
+
"props": {
|
|
70270
|
+
"title": "Cancel",
|
|
70271
|
+
"style": "secondary",
|
|
70272
|
+
"action": {
|
|
70273
|
+
"actionId": "tier5.himiOwnerLitePost.cancelDelete"
|
|
70274
|
+
}
|
|
70275
|
+
}
|
|
70276
|
+
}
|
|
70277
|
+
},
|
|
70278
|
+
{
|
|
70279
|
+
"id": "post_delete_confirm",
|
|
70280
|
+
"body": {
|
|
70281
|
+
"package": "himalaya",
|
|
70282
|
+
"type": "Button",
|
|
70283
|
+
"props": {
|
|
70284
|
+
"title": "Delete",
|
|
70285
|
+
"style": "destructive",
|
|
70286
|
+
"action": {
|
|
70287
|
+
"actionId": "tier5.himiOwnerLitePost.confirmDelete"
|
|
70288
|
+
}
|
|
70289
|
+
}
|
|
70290
|
+
}
|
|
70291
|
+
}
|
|
70292
|
+
]
|
|
70293
|
+
}
|
|
70294
|
+
}
|
|
70295
|
+
}
|
|
70296
|
+
]
|
|
70297
|
+
}
|
|
70298
|
+
},
|
|
70299
|
+
"modifiers": {
|
|
70300
|
+
"background": {
|
|
70301
|
+
"token": "surfaceElevated"
|
|
70302
|
+
},
|
|
70303
|
+
"border": {
|
|
70304
|
+
"width": 1,
|
|
70305
|
+
"color": {
|
|
70306
|
+
"token": "danger"
|
|
70307
|
+
}
|
|
70308
|
+
},
|
|
70309
|
+
"cornerRadius": 12,
|
|
70310
|
+
"padding": {
|
|
70311
|
+
"leading": 14,
|
|
70312
|
+
"trailing": 14,
|
|
70313
|
+
"top": 14,
|
|
70314
|
+
"bottom": 14
|
|
70315
|
+
},
|
|
70316
|
+
"fillMaxWidth": true,
|
|
70317
|
+
"hiddenPath": "$service:himiOwnerLitePost.noDeleteConfirmation"
|
|
70318
|
+
}
|
|
70319
|
+
},
|
|
70102
70320
|
{
|
|
70103
70321
|
"id": "",
|
|
70104
70322
|
"body": {
|
|
@@ -62,6 +62,9 @@ interface EventState {
|
|
|
62
62
|
/** Non-empty when showing owner-preview-demo sample data (web preview, no owner bridge). */
|
|
63
63
|
demoNote: string;
|
|
64
64
|
notDemo: boolean;
|
|
65
|
+
/** #3158 — Delete ARMS a confirmation; only confirmDelete reaches the API. */
|
|
66
|
+
deletePending: boolean;
|
|
67
|
+
noDeleteConfirmation: boolean;
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -139,6 +142,9 @@ function shape(s: Partial<EventState>): EventState {
|
|
|
139
142
|
noCover: !image,
|
|
140
143
|
demoNote: s.demoNote ?? "",
|
|
141
144
|
notDemo: !s.demoNote,
|
|
145
|
+
// Only a loaded entity can be pending deletion; every other action disarms it (`disarm`).
|
|
146
|
+
deletePending: !!s.deletePending && hasEntity,
|
|
147
|
+
noDeleteConfirmation: !(s.deletePending && hasEntity),
|
|
142
148
|
};
|
|
143
149
|
}
|
|
144
150
|
|
|
@@ -224,15 +230,32 @@ async function refresh(prev: EventState, id: string): Promise<EventState> {
|
|
|
224
230
|
});
|
|
225
231
|
}
|
|
226
232
|
|
|
233
|
+
/** #3158 — a confirmed delete in flight. Synchronous and module-level on purpose: two
|
|
234
|
+
* confirmDelete dispatches (a double tap) both start from a state that says "armed", and only a
|
|
235
|
+
* flag set BEFORE the first await stops the second from issuing its own DELETE — whose late 404
|
|
236
|
+
* would otherwise land after, and overwrite, the first one's "deleted". */
|
|
237
|
+
let deleteInFlight = false;
|
|
238
|
+
|
|
239
|
+
/** #3158 — the confirmation describes THIS visit. Never take it from a persisted snapshot, or a
|
|
240
|
+
* reopened record comes back with "Delete this …?" already armed. */
|
|
241
|
+
const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
|
|
242
|
+
|
|
243
|
+
/** #3158 — clear an armed delete confirmation. */
|
|
244
|
+
const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
|
|
245
|
+
|
|
227
246
|
const svc = defineService<EventState, {
|
|
228
247
|
load: (s: EventState, arg?: unknown) => Promise<EventState>;
|
|
229
248
|
retry: (s: EventState) => Promise<EventState>;
|
|
230
249
|
delete: (s: EventState) => Promise<EventState>;
|
|
250
|
+
cancelDelete: (s: EventState) => Promise<EventState>;
|
|
251
|
+
confirmDelete: (s: EventState) => Promise<EventState | undefined>;
|
|
231
252
|
openLink: (s: EventState, arg?: unknown) => Promise<EventState>;
|
|
232
253
|
}>("himiOwnerLiteEvent", {
|
|
233
254
|
state: shape({ status: "loading" }),
|
|
255
|
+
notHydrated: [...DELETE_RUN_KEYS],
|
|
234
256
|
actions: {
|
|
235
|
-
load: async (
|
|
257
|
+
load: async (s0, arg) => {
|
|
258
|
+
const s = disarm(s0);
|
|
236
259
|
stashCopy(arg); // absorb the descriptor's onAppear copy-pack param
|
|
237
260
|
const id = idFrom(arg, s.id) || inputId();
|
|
238
261
|
if (!id) return shape({ ...s, status: "error", error: copyParam("ownerEvent.errorNoId", "no event id") });
|
|
@@ -257,7 +280,8 @@ const svc = defineService<EventState, {
|
|
|
257
280
|
return shape({ ...s, id, status: "error", error: ownerLoadError(e) });
|
|
258
281
|
}
|
|
259
282
|
},
|
|
260
|
-
retry: async (
|
|
283
|
+
retry: async (s0) => {
|
|
284
|
+
const s = disarm(s0);
|
|
261
285
|
if (!s.id) return shape({ ...s, status: "error", error: copyParam("ownerEvent.errorNoId", "no event id") });
|
|
262
286
|
if (isOwnerPreviewDemo()) {
|
|
263
287
|
const demo = demoDetail(s, s.id);
|
|
@@ -279,20 +303,35 @@ const svc = defineService<EventState, {
|
|
|
279
303
|
return shape({ ...s, status: "error", error: ownerLoadError(e) });
|
|
280
304
|
}
|
|
281
305
|
},
|
|
282
|
-
delete
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
306
|
+
// #3158 — destructive, so two steps. `delete` (the Manage card's Delete button)
|
|
307
|
+
// only ARMS the inline confirmation, which names the record and says it cannot
|
|
308
|
+
// be undone; `cancelDelete` disarms it; only `confirmDelete` deletes. Anything
|
|
309
|
+
// that dispatches `delete` directly therefore still asks first.
|
|
310
|
+
delete: async (s) => shape({ ...s, deletePending: true, actionMessage: "" }),
|
|
311
|
+
cancelDelete: async (s) => shape({ ...s, deletePending: false }),
|
|
312
|
+
confirmDelete: async (s0) => {
|
|
313
|
+
// Nothing armed (a stray dispatch, a rehydrated snapshot) or a delete already running
|
|
314
|
+
// (a second tap): ignore it — `undefined` leaves the state exactly as it is.
|
|
315
|
+
if (!s0.deletePending || deleteInFlight) return undefined;
|
|
316
|
+
deleteInFlight = true;
|
|
287
317
|
try {
|
|
288
|
-
|
|
289
|
-
return shape({ ...s,
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
318
|
+
const s = disarm(s0);
|
|
319
|
+
if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
320
|
+
if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerEvent.noIdMessage", "No event id.") });
|
|
321
|
+
// Optimistic local delete — the list drops the row immediately.
|
|
322
|
+
await cacheDrop(s.id);
|
|
323
|
+
try {
|
|
324
|
+
await deleteEvent(s.id);
|
|
325
|
+
return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerEvent.deletedEmpty", "Event deleted."), actionMessage: "" });
|
|
326
|
+
} catch (e) {
|
|
327
|
+
if (shouldQueueOwnerWrite(e)) {
|
|
328
|
+
await queueWrite("tier5.himiOwnerLiteEvent.delete", { id: s.id });
|
|
329
|
+
return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerEvent.deletedEmpty", "Event deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
330
|
+
}
|
|
331
|
+
return shape({ ...s, actionMessage: ownerLoadError(e) });
|
|
294
332
|
}
|
|
295
|
-
|
|
333
|
+
} finally {
|
|
334
|
+
deleteInFlight = false;
|
|
296
335
|
}
|
|
297
336
|
},
|
|
298
337
|
// [rico] #3499 — a link tapped in the RichContent description.
|
|
@@ -303,4 +342,10 @@ const svc = defineService<EventState, {
|
|
|
303
342
|
},
|
|
304
343
|
});
|
|
305
344
|
|
|
345
|
+
// The same reset on a runtime from before `notHydrated` (an older binary on a new bundle).
|
|
346
|
+
if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
|
|
347
|
+
const booted = svc.getState?.() as unknown as Record<string, unknown> | undefined;
|
|
348
|
+
if (booted && typeof booted === "object") Object.assign(booted, { deletePending: false, noDeleteConfirmation: true });
|
|
349
|
+
}
|
|
350
|
+
|
|
306
351
|
export { svc };
|
|
@@ -80,6 +80,9 @@ interface PostState {
|
|
|
80
80
|
/** Non-empty when showing owner-preview-demo sample data (web preview, no owner bridge). */
|
|
81
81
|
demoNote: string;
|
|
82
82
|
notDemo: boolean;
|
|
83
|
+
/** #3158 — Delete ARMS a confirmation; only confirmDelete reaches the API. */
|
|
84
|
+
deletePending: boolean;
|
|
85
|
+
noDeleteConfirmation: boolean;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -159,6 +162,9 @@ function shape(s: Partial<PostState>): PostState {
|
|
|
159
162
|
hideUnpublish: !published || status !== "ready",
|
|
160
163
|
demoNote: s.demoNote ?? "",
|
|
161
164
|
notDemo: !s.demoNote,
|
|
165
|
+
// Only a loaded entity can be pending deletion; every other action disarms it (`disarm`).
|
|
166
|
+
deletePending: !!s.deletePending && hasEntity,
|
|
167
|
+
noDeleteConfirmation: !(s.deletePending && hasEntity),
|
|
162
168
|
};
|
|
163
169
|
}
|
|
164
170
|
|
|
@@ -276,18 +282,35 @@ async function refresh(prev: PostState, id: string, actionMessage = ""): Promise
|
|
|
276
282
|
});
|
|
277
283
|
}
|
|
278
284
|
|
|
285
|
+
/** #3158 — a confirmed delete in flight. Synchronous and module-level on purpose: two
|
|
286
|
+
* confirmDelete dispatches (a double tap) both start from a state that says "armed", and only a
|
|
287
|
+
* flag set BEFORE the first await stops the second from issuing its own DELETE — whose late 404
|
|
288
|
+
* would otherwise land after, and overwrite, the first one's "deleted". */
|
|
289
|
+
let deleteInFlight = false;
|
|
290
|
+
|
|
291
|
+
/** #3158 — the confirmation describes THIS visit. Never take it from a persisted snapshot, or a
|
|
292
|
+
* reopened record comes back with "Delete this …?" already armed. */
|
|
293
|
+
const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
|
|
294
|
+
|
|
295
|
+
/** #3158 — clear an armed delete confirmation. */
|
|
296
|
+
const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
|
|
297
|
+
|
|
279
298
|
const svc = defineService<PostState, {
|
|
280
299
|
load: (s: PostState, arg?: unknown) => Promise<PostState>;
|
|
281
300
|
retry: (s: PostState) => Promise<PostState>;
|
|
282
301
|
publish: (s: PostState) => Promise<PostState>;
|
|
283
302
|
unpublish: (s: PostState) => Promise<PostState>;
|
|
284
303
|
delete: (s: PostState) => Promise<PostState>;
|
|
304
|
+
cancelDelete: (s: PostState) => Promise<PostState>;
|
|
305
|
+
confirmDelete: (s: PostState) => Promise<PostState | undefined>;
|
|
285
306
|
/** [rico] #3370 — RichContent's on_link: `{ url }` of the tapped link. */
|
|
286
307
|
openLink: (s: PostState, arg?: unknown) => Promise<PostState>;
|
|
287
308
|
}>("himiOwnerLitePost", {
|
|
288
309
|
state: shape({ status: "loading" }),
|
|
310
|
+
notHydrated: [...DELETE_RUN_KEYS],
|
|
289
311
|
actions: {
|
|
290
|
-
load: async (
|
|
312
|
+
load: async (s0, arg) => {
|
|
313
|
+
const s = disarm(s0);
|
|
291
314
|
stashCopy(arg); // absorb the descriptor's onAppear copy-pack param
|
|
292
315
|
const id = idFrom(arg, s.id) || inputId();
|
|
293
316
|
if (!id) return shape({ ...s, status: "error", error: copyParam("ownerPost.errorNoId", "no post id") });
|
|
@@ -312,7 +335,8 @@ const svc = defineService<PostState, {
|
|
|
312
335
|
return shape({ ...s, id, status: "error", error: ownerLoadError(e) });
|
|
313
336
|
}
|
|
314
337
|
},
|
|
315
|
-
retry: async (
|
|
338
|
+
retry: async (s0) => {
|
|
339
|
+
const s = disarm(s0);
|
|
316
340
|
if (!s.id) return shape({ ...s, status: "error", error: copyParam("ownerPost.errorNoId", "no post id") });
|
|
317
341
|
if (isOwnerPreviewDemo()) {
|
|
318
342
|
const demo = demoDetail(s, s.id);
|
|
@@ -334,7 +358,8 @@ const svc = defineService<PostState, {
|
|
|
334
358
|
return shape({ ...s, status: "error", error: ownerLoadError(e) });
|
|
335
359
|
}
|
|
336
360
|
},
|
|
337
|
-
publish: async (
|
|
361
|
+
publish: async (s0) => {
|
|
362
|
+
const s = disarm(s0);
|
|
338
363
|
if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
339
364
|
if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerPost.noIdMessage", "No post id.") });
|
|
340
365
|
if (s.postStatusRaw === "PUBLISHED") return shape({ ...s, actionMessage: copyParam("ownerPost.alreadyPublished", "Post is already published.") });
|
|
@@ -352,7 +377,8 @@ const svc = defineService<PostState, {
|
|
|
352
377
|
return shape({ ...s, actionMessage: ownerLoadError(e) });
|
|
353
378
|
}
|
|
354
379
|
},
|
|
355
|
-
unpublish: async (
|
|
380
|
+
unpublish: async (s0) => {
|
|
381
|
+
const s = disarm(s0);
|
|
356
382
|
if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
357
383
|
if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerPost.noIdMessage", "No post id.") });
|
|
358
384
|
if (s.postStatusRaw !== "PUBLISHED" && s.postStatusRaw !== "SCHEDULED") {
|
|
@@ -372,20 +398,35 @@ const svc = defineService<PostState, {
|
|
|
372
398
|
return shape({ ...s, actionMessage: ownerLoadError(e) });
|
|
373
399
|
}
|
|
374
400
|
},
|
|
375
|
-
delete
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
401
|
+
// #3158 — destructive, so two steps. `delete` (the Manage card's Delete button)
|
|
402
|
+
// only ARMS the inline confirmation, which names the record and says it cannot
|
|
403
|
+
// be undone; `cancelDelete` disarms it; only `confirmDelete` deletes. Anything
|
|
404
|
+
// that dispatches `delete` directly therefore still asks first.
|
|
405
|
+
delete: async (s) => shape({ ...s, deletePending: true, actionMessage: "" }),
|
|
406
|
+
cancelDelete: async (s) => shape({ ...s, deletePending: false }),
|
|
407
|
+
confirmDelete: async (s0) => {
|
|
408
|
+
// Nothing armed (a stray dispatch, a rehydrated snapshot) or a delete already running
|
|
409
|
+
// (a second tap): ignore it — `undefined` leaves the state exactly as it is.
|
|
410
|
+
if (!s0.deletePending || deleteInFlight) return undefined;
|
|
411
|
+
deleteInFlight = true;
|
|
380
412
|
try {
|
|
381
|
-
|
|
382
|
-
return shape({ ...s,
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
413
|
+
const s = disarm(s0);
|
|
414
|
+
if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
415
|
+
if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerPost.noIdMessage", "No post id.") });
|
|
416
|
+
// Optimistic local delete — the list drops the row immediately.
|
|
417
|
+
await cacheDrop(s.id);
|
|
418
|
+
try {
|
|
419
|
+
await deleteDraftPost(s.id);
|
|
420
|
+
return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerPost.deletedEmpty", "Post deleted."), actionMessage: "" });
|
|
421
|
+
} catch (e) {
|
|
422
|
+
if (shouldQueueOwnerWrite(e)) {
|
|
423
|
+
await queueWrite("tier5.himiOwnerLitePost.delete", { id: s.id });
|
|
424
|
+
return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerPost.deletedEmpty", "Post deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
|
|
425
|
+
}
|
|
426
|
+
return shape({ ...s, actionMessage: ownerLoadError(e) });
|
|
387
427
|
}
|
|
388
|
-
|
|
428
|
+
} finally {
|
|
429
|
+
deleteInFlight = false;
|
|
389
430
|
}
|
|
390
431
|
},
|
|
391
432
|
// Only http(s), mailto and tel links reach open_url; a refused link, or one nothing opened, says so, and
|
|
@@ -397,4 +438,10 @@ const svc = defineService<PostState, {
|
|
|
397
438
|
},
|
|
398
439
|
});
|
|
399
440
|
|
|
441
|
+
// The same reset on a runtime from before `notHydrated` (an older binary on a new bundle).
|
|
442
|
+
if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
|
|
443
|
+
const booted = svc.getState?.() as unknown as Record<string, unknown> | undefined;
|
|
444
|
+
if (booted && typeof booted === "object") Object.assign(booted, { deletePending: false, noDeleteConfirmation: true });
|
|
445
|
+
}
|
|
446
|
+
|
|
400
447
|
export { svc };
|