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

74 lines
1.9 KiB
JavaScript
Raw Normal View History

import * as ACTIONS from 'constants/action_types';
import { shell } from 'electron';
2017-04-28 17:14:44 +02:00
import {
2018-04-18 06:03:01 +02:00
Lbry,
batchActions,
doAbandonClaim,
selectMyClaimsOutpoints,
selectFileInfosByOutpoint,
selectTotalDownloadProgress,
2018-04-19 18:51:18 +02:00
doHideNotification,
2018-04-18 06:03:01 +02:00
} from 'lbry-redux';
import { doHistoryBack } from 'redux/actions/navigation';
import setProgressBar from 'util/setProgressBar';
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 byOutpoint = selectFileInfosByOutpoint(state);
const fileInfo = byOutpoint[outpoint];
if (fileInfo) {
2017-12-05 15:45:35 +01:00
const txid = fileInfo.outpoint.slice(0, -2);
2017-12-11 08:21:18 +01:00
const nout = Number(fileInfo.outpoint.slice(-1));
2017-10-24 15:10:27 +02:00
2017-11-01 21:23:30 +01:00
dispatch(doAbandonClaim(txid, nout));
}
}
dispatch({
type: ACTIONS.FILE_DELETE,
data: {
2017-06-06 23:19:12 +02:00
outpoint,
},
});
const totalProgress = selectTotalDownloadProgress(getState());
setProgressBar(totalProgress);
};
}
export function doDeleteFileAndGoBack(fileInfo, deleteFromComputer, abandonClaim) {
return dispatch => {
const actions = [];
2018-04-19 18:51:18 +02:00
actions.push(doHideNotification());
actions.push(doHistoryBack());
actions.push(doDeleteFile(fileInfo, deleteFromComputer, abandonClaim));
dispatch(batchActions(...actions));
2017-06-06 23:19:12 +02:00
};
}