From 417d1287a69f635db24f138c904167b98373881e Mon Sep 17 00:00:00 2001 From: ThaumRystra Date: Tue, 29 Oct 2024 17:01:51 +0200 Subject: [PATCH] Made sure doAction's promise resolves or rejects --- .../client/ui/creature/actions/doAction.ts | 15 ++++++++++----- .../properties/components/actions/ActionCard.vue | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/imports/client/ui/creature/actions/doAction.ts b/app/imports/client/ui/creature/actions/doAction.ts index 293a78c1..3973cdcc 100644 --- a/app/imports/client/ui/creature/actions/doAction.ts +++ b/app/imports/client/ui/creature/actions/doAction.ts @@ -30,7 +30,7 @@ type DoActionParams = BaseDoActionParams & { * the decisions the user makes, then applying the action as a method call to the server with the * saved decisions, which will persist the action results. */ -export default async function doAction({ propId, creatureId, $store, elementId, task }: DoActionParams | DoTaskParams) { +export default async function doAction({ propId, creatureId, $store, elementId, task }: DoActionParams | DoTaskParams): Promise { if (!task) { if (!propId) throw new Meteor.Error('no-prop-id', 'Either propId or task must be provided'); task = { @@ -64,7 +64,7 @@ export default async function doAction({ propId, creatureId, $store, elementId, return callActionMethod(finishedAction); } catch (e) { if (e !== 'input-requested') throw e; - return new Promise(resolve => { + return new Promise((resolve, reject) => { $store.commit('pushDialogStack', { component: 'action-dialog', elementId, @@ -72,9 +72,14 @@ export default async function doAction({ propId, creatureId, $store, elementId, actionId, task, }, - callback(action: EngineAction) { - if (!action) return; - resolve(callActionMethod(action)); + async callback(action: EngineAction) { + try { + if (action) await callActionMethod(action); + resolve(); + } + catch (e) { + reject(e); + } return elementId; }, }); diff --git a/app/imports/client/ui/properties/components/actions/ActionCard.vue b/app/imports/client/ui/properties/components/actions/ActionCard.vue index 42c1a14f..ab3dfce4 100644 --- a/app/imports/client/ui/properties/components/actions/ActionCard.vue +++ b/app/imports/client/ui/properties/components/actions/ActionCard.vue @@ -11,7 +11,7 @@ outlined style="font-size: 16px; letter-spacing: normal;" class="mr-2" - data-id="do-action-button" + :data-id="`${model._id}-do-action-button`" :color="model.color || 'primary'" :loading="doActionLoading" :disabled="model.insufficientResources || !context.editPermission || !!targetingError" @@ -228,7 +228,7 @@ export default { propId: this.model._id, creatureId: this.model.root.id, $store: this.$store, - elementId: 'do-action-button', + elementId: `${this.model._id}-do-action-button`, }).catch((e) => { console.error(e); }).finally(() => {