Remove files from downloading list when they are deleted mid download

This commit is contained in:
6ea86b96 2017-07-21 15:13:45 +07:00
parent b99d58c3f9
commit af96d40ead
3 changed files with 26 additions and 5 deletions

View file

@ -10,8 +10,11 @@ import {
selectIsFetchingFileList, selectIsFetchingFileList,
selectFileInfosByOutpoint, selectFileInfosByOutpoint,
selectUrisLoading, selectUrisLoading,
selectTotalDownloadProgress,
} from "selectors/file_info"; } from "selectors/file_info";
import { doCloseModal } from "actions/app"; import { doCloseModal, doHistoryBack } from "actions/app";
import setProgressBar from "util/setProgressBar";
import batchActions from "util/batchActions";
const { shell } = require("electron"); const { shell } = require("electron");
@ -119,7 +122,22 @@ export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
}, },
}); });
dispatch(doCloseModal()); const totalProgress = selectTotalDownloadProgress(getState());
setProgressBar(totalProgress);
};
}
export function doDeleteFileAndGoBack(
fileInfo,
deleteFromComputer,
abandonClaim
) {
return function(dispatch, getState) {
const actions = [];
actions.push(doCloseModal());
actions.push(doHistoryBack());
actions.push(doDeleteFile(fileInfo, deleteFromComputer, abandonClaim));
dispatch(batchActions(...actions));
}; };
} }

View file

@ -1,8 +1,9 @@
import React from "react"; import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { doCloseModal, doHistoryBack } from "actions/app"; import { doCloseModal, doHistoryBack } from "actions/app";
import { doDeleteFile } from "actions/file_info"; import { doDeleteFileAndGoBack } from "actions/file_info";
import { makeSelectClaimForUriIsMine } from "selectors/claims"; import { makeSelectClaimForUriIsMine } from "selectors/claims";
import batchActions from "util/batchActions";
import ModalRemoveFile from "./view"; import ModalRemoveFile from "./view";
@ -19,8 +20,7 @@ const makeSelect = () => {
const perform = dispatch => ({ const perform = dispatch => ({
closeModal: () => dispatch(doCloseModal()), closeModal: () => dispatch(doCloseModal()),
deleteFile: (fileInfo, deleteFromComputer, abandonClaim) => { deleteFile: (fileInfo, deleteFromComputer, abandonClaim) => {
dispatch(doHistoryBack()); dispatch(doDeleteFileAndGoBack(fileInfo, deleteFromComputer, abandonClaim));
dispatch(doDeleteFile(fileInfo, deleteFromComputer, abandonClaim));
}, },
}); });

View file

@ -106,11 +106,14 @@ reducers[types.FILE_DELETE] = function(state, action) {
const { outpoint } = action.data; const { outpoint } = action.data;
const newByOutpoint = Object.assign({}, state.byOutpoint); const newByOutpoint = Object.assign({}, state.byOutpoint);
const downloadingByOutpoint = Object.assign({}, state.downloadingByOutpoint);
delete newByOutpoint[outpoint]; delete newByOutpoint[outpoint];
delete downloadingByOutpoint[outpoint];
return Object.assign({}, state, { return Object.assign({}, state, {
byOutpoint: newByOutpoint, byOutpoint: newByOutpoint,
downloadingByOutpoint,
}); });
}; };