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

64 lines
1.7 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, selectMyClaimsOutpoints } 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';
2017-04-28 17:14:44 +02:00
export function doOpenFileInFolder(path) {
return () => {
shell.showItemInFolder(path);
};
}
export function doOpenFileInShell(path) {
return dispatch => {
const success = shell.openItem(path);
if (!success) {
dispatch(doOpenFileInFolder(path));
}
2017-06-06 23:19:12 +02:00
};
}
export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
return (dispatch, getState) => {
const state = getState();
Lbry.file_delete({
2017-12-13 22:36:30 +01:00
outpoint,
delete_from_download_dir: deleteFromComputer,
});
// If the file is for a claim we published then also abandon the claim
const myClaimsOutpoints = selectMyClaimsOutpoints(state);
if (abandonClaim && myClaimsOutpoints.indexOf(outpoint) !== -1) {
const [txid, nout] = outpoint.split(':');
dispatch(doAbandonClaim(txid, Number(nout)));
}
dispatch({
type: ACTIONS.FILE_DELETE,
data: {
2017-06-06 23:19:12 +02:00
outpoint,
},
});
};
}
export function doDeleteFileAndMaybeGoBack(fileInfo, deleteFromComputer, abandonClaim) {
return dispatch => {
const actions = [];
actions.push(doHideModal());
actions.push(doDeleteFile(fileInfo, deleteFromComputer, abandonClaim));
2019-08-14 05:56:11 +02:00
actions.push(doSetPlayingUri(null));
dispatch(batchActions(...actions));
2019-08-14 05:56:11 +02:00
if (abandonClaim) {
dispatch(goBack());
}
2017-06-06 23:19:12 +02:00
};
}