lbry-desktop/ui/redux/actions/file.js

89 lines
2.3 KiB
JavaScript
Raw Normal View History

import * as ACTIONS from 'constants/action_types';
2019-03-05 05:46:57 +01:00
// @if TARGET='app'
import { shell } from 'electron';
2019-03-05 05:46:57 +01:00
// @endif
import {
Lbry,
batchActions,
doAbandonClaim,
makeSelectFileInfoForUri,
makeSelectClaimForUri,
ABANDON_STATES,
} from 'lbry-redux';
import { doHideModal } from 'redux/actions/app';
import { goBack } from 'connected-react-router';
2019-08-14 05:56:11 +02:00
import { doSetPlayingUri } from 'redux/actions/content';
import { selectPlayingUri } from 'redux/selectors/content';
2017-04-28 17:14:44 +02:00
export function doOpenFileInFolder(path) {
return () => {
shell.showItemInFolder(path);
};
}
export function doOpenFileInShell(path) {
return (dispatch) => {
2020-10-16 01:06:05 +02:00
const success = shell.openPath(path);
if (!success) {
dispatch(doOpenFileInFolder(path));
}
2017-06-06 23:19:12 +02:00
};
}
export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim, cb) {
return (dispatch) => {
if (abandonClaim) {
const [txid, nout] = outpoint.split(':');
dispatch(doAbandonClaim(txid, Number(nout), cb));
}
2020-03-27 17:49:41 +01:00
// @if TARGET='app'
2020-04-28 00:22:09 +02:00
Lbry.file_delete({
outpoint,
delete_from_download_dir: deleteFromComputer,
});
dispatch({
type: ACTIONS.FILE_DELETE,
data: {
2017-06-06 23:19:12 +02:00
outpoint,
},
});
2020-03-27 17:49:41 +01:00
// @endif
};
}
export function doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim) {
return (dispatch, getState) => {
const state = getState();
const playingUri = selectPlayingUri(state);
const { outpoint } = makeSelectFileInfoForUri(uri)(state) || '';
const { nout, txid } = makeSelectClaimForUri(uri)(state);
const claimOutpoint = `${txid}:${nout}`;
const actions = [];
if (!abandonClaim) {
actions.push(doHideModal());
}
actions.push(
doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim, (abandonState) => {
if (abandonState === ABANDON_STATES.DONE) {
if (abandonClaim) {
dispatch(goBack());
dispatch(doHideModal());
}
}
})
);
if (playingUri && playingUri.uri === uri) {
2020-12-21 16:31:34 +01:00
actions.push(doSetPlayingUri({ uri: null }));
}
2019-08-30 16:01:39 +02:00
// it would be nice to stay on the claim if you just want to delete it
// we need to alter autoplay to not start downloading again after you delete it
dispatch(batchActions(...actions));
2017-06-06 23:19:12 +02:00
};
}