Made sure doAction's promise resolves or rejects
This commit is contained in:
@@ -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<any | void> {
|
||||
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<void>((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;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user