wait to go back until claim has been abandoned

This commit is contained in:
Sean Yesmunt 2020-07-22 18:39:24 -04:00
parent 1ad430f463
commit 0f51cf8986

View file

@ -2,7 +2,14 @@ import * as ACTIONS from 'constants/action_types';
// @if TARGET='app'
import { shell } from 'electron';
// @endif
import { Lbry, batchActions, doAbandonClaim, makeSelectFileInfoForUri, makeSelectClaimForUri } from 'lbry-redux';
import {
Lbry,
batchActions,
doAbandonClaim,
makeSelectFileInfoForUri,
makeSelectClaimForUri,
ABANDON_STATES,
} from 'lbry-redux';
import { doHideModal } from 'redux/actions/app';
import { goBack } from 'connected-react-router';
import { doSetPlayingUri } from 'redux/actions/content';
@ -23,11 +30,11 @@ export function doOpenFileInShell(path) {
};
}
export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim, cb) {
return dispatch => {
if (abandonClaim) {
const [txid, nout] = outpoint.split(':');
dispatch(doAbandonClaim(txid, Number(nout)));
dispatch(doAbandonClaim(txid, Number(nout), cb));
}
// @if TARGET='app'
@ -54,8 +61,21 @@ export function doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim
const { nout, txid } = makeSelectClaimForUri(uri)(state);
const claimOutpoint = `${txid}:${nout}`;
const actions = [];
if (!abandonClaim) {
actions.push(doHideModal());
actions.push(doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim));
}
actions.push(
doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim, abandonState => {
if (abandonState === ABANDON_STATES.DONE) {
if (abandonClaim) {
dispatch(goBack());
dispatch(doHideModal());
}
}
})
);
if (playingUri === uri) {
actions.push(doSetPlayingUri(null));
@ -64,8 +84,5 @@ export function doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim
// we need to alter autoplay to not start downloading again after you delete it
dispatch(batchActions(...actions));
if (abandonClaim) {
dispatch(goBack());
}
};
}