2017-12-21 14:32:51 -03:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2017-12-27 20:48:11 -03:00
|
|
|
import { shell } from 'electron';
|
2017-04-28 22:14:44 +07:00
|
|
|
import {
|
2018-04-18 00:03:01 -04:00
|
|
|
Lbry,
|
|
|
|
batchActions,
|
|
|
|
doAbandonClaim,
|
2017-06-29 14:44:34 +07:00
|
|
|
selectMyClaimsOutpoints,
|
|
|
|
selectFileInfosByOutpoint,
|
2017-07-21 15:13:45 +07:00
|
|
|
selectTotalDownloadProgress,
|
2018-04-18 00:03:01 -04:00
|
|
|
} from 'lbry-redux';
|
|
|
|
import { doCloseModal } from 'redux/actions/app';
|
|
|
|
import { doHistoryBack } from 'redux/actions/navigation';
|
2017-12-27 20:48:11 -03:00
|
|
|
import setProgressBar from 'util/setProgressBar';
|
2017-04-28 22:14:44 +07:00
|
|
|
|
2017-12-21 14:32:51 -03:00
|
|
|
export function doOpenFileInFolder(path) {
|
2017-12-27 20:48:11 -03:00
|
|
|
return () => {
|
2017-12-21 14:32:51 -03:00
|
|
|
shell.showItemInFolder(path);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-20 08:47:08 -04:00
|
|
|
export function doOpenFileInShell(path) {
|
2017-12-27 20:48:11 -03:00
|
|
|
return dispatch => {
|
2017-09-20 08:47:08 -04:00
|
|
|
const success = shell.openItem(path);
|
2017-08-06 19:18:38 -04:00
|
|
|
if (!success) {
|
2017-09-20 08:47:08 -04:00
|
|
|
dispatch(doOpenFileInFolder(path));
|
2017-08-06 19:18:38 -04:00
|
|
|
}
|
2017-06-06 17:19:12 -04:00
|
|
|
};
|
2017-04-30 00:02:25 +07:00
|
|
|
}
|
|
|
|
|
2017-06-29 14:44:34 +07:00
|
|
|
export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
|
2017-12-27 20:48:11 -03:00
|
|
|
return (dispatch, getState) => {
|
2017-06-29 14:44:34 +07:00
|
|
|
const state = getState();
|
|
|
|
|
2017-12-21 14:32:51 -03:00
|
|
|
Lbry.file_delete({
|
2017-12-13 18:36:30 -03:00
|
|
|
outpoint,
|
2017-06-29 14:44:34 +07:00
|
|
|
delete_from_download_dir: deleteFromComputer,
|
|
|
|
});
|
|
|
|
|
2017-12-27 20:48:11 -03:00
|
|
|
// If the file is for a claim we published then also abandon the claim
|
2017-06-29 14:44:34 +07:00
|
|
|
const myClaimsOutpoints = selectMyClaimsOutpoints(state);
|
|
|
|
if (abandonClaim && myClaimsOutpoints.indexOf(outpoint) !== -1) {
|
|
|
|
const byOutpoint = selectFileInfosByOutpoint(state);
|
|
|
|
const fileInfo = byOutpoint[outpoint];
|
|
|
|
|
|
|
|
if (fileInfo) {
|
2017-12-05 20:15:35 +05:30
|
|
|
const txid = fileInfo.outpoint.slice(0, -2);
|
2017-12-11 12:51:18 +05:30
|
|
|
const nout = Number(fileInfo.outpoint.slice(-1));
|
2017-10-24 18:40:27 +05:30
|
|
|
|
2017-11-02 01:53:30 +05:30
|
|
|
dispatch(doAbandonClaim(txid, nout));
|
2017-06-29 14:44:34 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-30 00:02:25 +07:00
|
|
|
dispatch({
|
2017-12-21 14:32:51 -03:00
|
|
|
type: ACTIONS.FILE_DELETE,
|
2017-04-30 00:02:25 +07:00
|
|
|
data: {
|
2017-06-06 17:19:12 -04:00
|
|
|
outpoint,
|
|
|
|
},
|
|
|
|
});
|
2017-04-30 00:02:25 +07:00
|
|
|
|
2017-07-21 15:13:45 +07:00
|
|
|
const totalProgress = selectTotalDownloadProgress(getState());
|
|
|
|
setProgressBar(totalProgress);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-21 14:32:51 -03:00
|
|
|
export function doDeleteFileAndGoBack(fileInfo, deleteFromComputer, abandonClaim) {
|
2017-12-27 20:48:11 -03:00
|
|
|
return dispatch => {
|
2017-07-21 15:13:45 +07:00
|
|
|
const actions = [];
|
|
|
|
actions.push(doCloseModal());
|
|
|
|
actions.push(doHistoryBack());
|
|
|
|
actions.push(doDeleteFile(fileInfo, deleteFromComputer, abandonClaim));
|
|
|
|
dispatch(batchActions(...actions));
|
2017-06-06 17:19:12 -04:00
|
|
|
};
|
2017-04-30 23:01:43 +07:00
|
|
|
}
|