anastasis-webui: return promises in anastasis reducer hook
This commit is contained in:
parent
c2d8dd76c3
commit
4ebeb00243
@ -1,5 +1,12 @@
|
||||
import { TalerErrorCode } from "@gnu-taler/taler-util";
|
||||
import { BackupStates, getBackupStartState, getRecoveryStartState, RecoveryStates, reduceAction, ReducerState } from "anastasis-core";
|
||||
import {
|
||||
BackupStates,
|
||||
getBackupStartState,
|
||||
getRecoveryStartState,
|
||||
RecoveryStates,
|
||||
reduceAction,
|
||||
ReducerState,
|
||||
} from "anastasis-core";
|
||||
import { useState } from "preact/hooks";
|
||||
|
||||
const reducerBaseUrl = "http://localhost:5000/";
|
||||
@ -98,13 +105,15 @@ export interface AnastasisReducerApi {
|
||||
startBackup: () => void;
|
||||
startRecover: () => void;
|
||||
reset: () => void;
|
||||
back: () => void;
|
||||
transition(action: string, args: any): void;
|
||||
back: () => Promise<void>;
|
||||
transition(action: string, args: any): Promise<void>;
|
||||
/**
|
||||
* Run multiple reducer steps in a transaction without
|
||||
* affecting the UI-visible transition state in-between.
|
||||
*/
|
||||
runTransaction(f: (h: ReducerTransactionHandle) => Promise<void>): void;
|
||||
runTransaction(
|
||||
f: (h: ReducerTransactionHandle) => Promise<void>,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
function storageGet(key: string): string | null {
|
||||
@ -222,9 +231,9 @@ export function useAnastasisReducer(): AnastasisReducerApi {
|
||||
}
|
||||
},
|
||||
transition(action: string, args: any) {
|
||||
doTransition(action, args);
|
||||
return doTransition(action, args);
|
||||
},
|
||||
back() {
|
||||
async back() {
|
||||
const reducerState = anastasisState.reducerState;
|
||||
if (!reducerState) {
|
||||
return;
|
||||
@ -239,7 +248,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
|
||||
reducerState: undefined,
|
||||
});
|
||||
} else {
|
||||
doTransition("back", {});
|
||||
await doTransition("back", {});
|
||||
}
|
||||
},
|
||||
dismissError() {
|
||||
@ -252,8 +261,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
|
||||
reducerState: undefined,
|
||||
});
|
||||
},
|
||||
runTransaction(f) {
|
||||
async function run() {
|
||||
async runTransaction(f) {
|
||||
const txHandle = new ReducerTxImpl(anastasisState.reducerState!);
|
||||
try {
|
||||
await f(txHandle);
|
||||
@ -274,8 +282,6 @@ export function useAnastasisReducer(): AnastasisReducerApi {
|
||||
currentError: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
run();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user