Improve file deletion proccess and redirection

This commit is contained in:
saltrafael 2021-07-26 11:19:09 -03:00
parent 077207e203
commit 2205228cde
No known key found for this signature in database
GPG key ID: 9C7F1DC0B0F54515
4 changed files with 18 additions and 20 deletions

View file

@ -189,7 +189,7 @@ function ClaimMenuList(props: Props) {
if (!repostedClaim && !isChannel) { if (!repostedClaim && !isChannel) {
openModal(MODALS.CONFIRM_FILE_REMOVE, { uri, doGoBack: false }); openModal(MODALS.CONFIRM_FILE_REMOVE, { uri, doGoBack: false });
} else { } else {
openModal(MODALS.CONFIRM_CLAIM_REVOKE, { claim, cb: isChannel && (() => replace(`/$/${PAGES.CHANNELS}`)) }); openModal(MODALS.CONFIRM_CLAIM_REVOKE, { claim });
} }
} }

View file

@ -20,8 +20,8 @@ const select = (state, props) => ({
const perform = dispatch => ({ const perform = dispatch => ({
closeModal: () => dispatch(doHideModal()), closeModal: () => dispatch(doHideModal()),
doResolveUri: (uri) => dispatch(doResolveUri(uri)), doResolveUri: (uri) => dispatch(doResolveUri(uri)),
deleteFile: (uri, deleteFromComputer, abandonClaim, doGoBack) => { deleteFile: (uri, deleteFromComputer, abandonClaim) => {
dispatch(doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, doGoBack)); dispatch(doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, false));
}, },
}); });

View file

@ -15,7 +15,6 @@ type Props = {
doResolveUri: (string) => void, doResolveUri: (string) => void,
closeModal: () => void, closeModal: () => void,
deleteFile: (string, boolean, boolean, boolean) => void, deleteFile: (string, boolean, boolean, boolean) => void,
doGoBack: boolean,
title: string, title: string,
fileInfo?: { fileInfo?: {
outpoint: ?string, outpoint: ?string,
@ -24,7 +23,7 @@ type Props = {
}; };
function ModalRemoveFile(props: Props) { function ModalRemoveFile(props: Props) {
const { uri, claimIsMine, doResolveUri, closeModal, deleteFile, doGoBack = true, title, claim, isAbandoning } = props; const { uri, claimIsMine, doResolveUri, closeModal, deleteFile, title, claim, isAbandoning } = props;
const [deleteChecked, setDeleteChecked] = usePersistedState('modal-remove-file:delete', true); const [deleteChecked, setDeleteChecked] = usePersistedState('modal-remove-file:delete', true);
const [abandonChecked, setAbandonChecked] = usePersistedState('modal-remove-file:abandon', true); const [abandonChecked, setAbandonChecked] = usePersistedState('modal-remove-file:abandon', true);
@ -34,6 +33,11 @@ function ModalRemoveFile(props: Props) {
} }
}, [uri, doResolveUri]); }, [uri, doResolveUri]);
let disabled = isAbandoning || !(deleteChecked || abandonChecked);
// @if TARGET='web'
disabled = isAbandoning || !abandonChecked;
// @endif
return ( return (
<Modal isOpen contentLabel={__('Confirm File Remove')} type="card" onAborted={closeModal}> <Modal isOpen contentLabel={__('Confirm File Remove')} type="card" onAborted={closeModal}>
<Card <Card
@ -68,12 +72,12 @@ function ModalRemoveFile(props: Props) {
checked={abandonChecked} checked={abandonChecked}
onChange={() => setAbandonChecked(!abandonChecked)} onChange={() => setAbandonChecked(!abandonChecked)}
/> />
{abandonChecked === true && ( {abandonChecked && (
<p className="help error__text">{__('This action is permanent and cannot be undone')}</p> <p className="help error__text">{__('This action is permanent and cannot be undone')}</p>
)} )}
{/* @if TARGET='app' */} {/* @if TARGET='app' */}
{abandonChecked === false && deleteChecked && ( {!abandonChecked && deleteChecked && (
<p className="help">{__('This file will be removed from your Library and Downloads folder.')}</p> <p className="help">{__('This file will be removed from your Library and Downloads folder.')}</p>
)} )}
{!deleteChecked && ( {!deleteChecked && (
@ -92,8 +96,8 @@ function ModalRemoveFile(props: Props) {
<Button <Button
button="primary" button="primary"
label={isAbandoning ? __('Removing...') : __('OK')} label={isAbandoning ? __('Removing...') : __('OK')}
disabled={isAbandoning || !(deleteChecked || abandonChecked)} disabled={disabled}
onClick={() => deleteFile(uri, deleteChecked, claimIsMine ? abandonChecked : false, doGoBack)} onClick={() => deleteFile(uri, deleteChecked, claimIsMine ? abandonChecked : false)}
/> />
<Button button="link" label={__('Cancel')} onClick={closeModal} /> <Button button="link" label={__('Cancel')} onClick={closeModal} />
</div> </div>

View file

@ -53,7 +53,7 @@ export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim, cb) {
}; };
} }
export function doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, doGoBack) { export function doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim, doGoBack = true) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const playingUri = selectPlayingUri(state); const playingUri = selectPlayingUri(state);
@ -62,21 +62,15 @@ export function doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim
const claimOutpoint = `${txid}:${nout}`; const claimOutpoint = `${txid}:${nout}`;
const actions = []; const actions = [];
if (!abandonClaim) {
actions.push(doHideModal());
}
actions.push( actions.push(
doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim, (abandonState) => { doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim, (abandonState) => {
if (abandonState === ABANDON_STATES.DONE) { if (abandonState === ABANDON_STATES.DONE) {
if (abandonClaim) { if (doGoBack) {
if (doGoBack) { dispatch(goBack());
dispatch(goBack());
}
dispatch(doHideModal());
} }
} }
}) }),
doHideModal(),
); );
if (playingUri && playingUri.uri === uri) { if (playingUri && playingUri.uri === uri) {