2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { Modal } from 'modal/modal';
|
2019-12-06 21:57:07 +01:00
|
|
|
import { FormField } from 'component/common/form';
|
2019-07-18 00:22:47 +02:00
|
|
|
import Button from 'component/button';
|
2019-09-27 20:56:15 +02:00
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
2019-12-06 21:57:07 +01:00
|
|
|
import Card from 'component/common/card';
|
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-09-02 22:08:37 +02:00
|
|
|
import LbcSymbol from 'component/common/lbc-symbol';
|
2017-07-02 20:23:38 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
2019-08-15 04:50:41 +02:00
|
|
|
uri: string,
|
2019-05-10 01:26:03 +02:00
|
|
|
claim: StreamClaim,
|
2018-03-26 23:32:43 +02:00
|
|
|
claimIsMine: boolean,
|
2021-06-24 16:33:11 +02:00
|
|
|
doResolveUri: (string) => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
closeModal: () => void,
|
2021-06-24 16:33:11 +02:00
|
|
|
deleteFile: (string, boolean, boolean, boolean) => void,
|
|
|
|
doGoBack: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
title: string,
|
2019-03-12 20:15:11 +01:00
|
|
|
fileInfo?: {
|
|
|
|
outpoint: ?string,
|
2018-03-26 23:32:43 +02:00
|
|
|
},
|
2020-07-24 16:42:56 +02:00
|
|
|
isAbandoning: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2019-07-11 04:57:24 +02:00
|
|
|
function ModalRemoveFile(props: Props) {
|
2021-06-24 16:33:11 +02:00
|
|
|
const { uri, claimIsMine, doResolveUri, closeModal, deleteFile, doGoBack = true, title, claim, isAbandoning } = props;
|
2019-07-11 04:57:24 +02:00
|
|
|
const [deleteChecked, setDeleteChecked] = usePersistedState('modal-remove-file:delete', true);
|
|
|
|
const [abandonChecked, setAbandonChecked] = usePersistedState('modal-remove-file:abandon', true);
|
2017-07-02 20:23:38 +02:00
|
|
|
|
2021-06-24 16:33:11 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (uri) {
|
|
|
|
doResolveUri(uri);
|
|
|
|
}
|
|
|
|
}, [uri, doResolveUri]);
|
|
|
|
|
2019-07-11 04:57:24 +02:00
|
|
|
return (
|
2019-12-06 21:57:07 +01:00
|
|
|
<Modal isOpen contentLabel={__('Confirm File Remove')} type="card" onAborted={closeModal}>
|
|
|
|
<Card
|
2020-09-09 04:01:52 +02:00
|
|
|
title={__('Remove File')}
|
2019-12-06 21:57:07 +01:00
|
|
|
subtitle={
|
|
|
|
<I18nMessage tokens={{ title: <cite>{`"${title}"`}</cite> }}>
|
2021-07-07 16:21:17 +02:00
|
|
|
Are you sure you'd like to remove %title%?
|
2019-12-06 21:57:07 +01:00
|
|
|
</I18nMessage>
|
|
|
|
}
|
|
|
|
body={
|
|
|
|
<React.Fragment>
|
|
|
|
{/* @if TARGET='app' */}
|
2019-10-17 03:25:58 +02:00
|
|
|
<FormField
|
2019-12-06 21:57:07 +01:00
|
|
|
name="file_delete"
|
|
|
|
label={__('Delete this file from my computer')}
|
2019-10-17 03:25:58 +02:00
|
|
|
type="checkbox"
|
2019-12-06 21:57:07 +01:00
|
|
|
checked={deleteChecked}
|
|
|
|
onChange={() => setDeleteChecked(!deleteChecked)}
|
2019-10-17 03:25:58 +02:00
|
|
|
/>
|
2019-12-06 21:57:07 +01:00
|
|
|
{/* @endif */}
|
2019-11-17 19:32:31 +01:00
|
|
|
|
2019-12-06 21:57:07 +01:00
|
|
|
{claimIsMine && (
|
|
|
|
<React.Fragment>
|
|
|
|
<FormField
|
|
|
|
name="claim_abandon"
|
2020-09-02 22:08:37 +02:00
|
|
|
label={
|
2021-07-21 21:06:40 +02:00
|
|
|
<I18nMessage tokens={{ lbc: <LbcSymbol postfix={claim.amount} /> }}>
|
2021-07-07 16:21:17 +02:00
|
|
|
Remove from blockchain (%lbc%)
|
2020-09-02 22:08:37 +02:00
|
|
|
</I18nMessage>
|
|
|
|
}
|
2019-12-06 21:57:07 +01:00
|
|
|
type="checkbox"
|
|
|
|
checked={abandonChecked}
|
|
|
|
onChange={() => setAbandonChecked(!abandonChecked)}
|
|
|
|
/>
|
|
|
|
{abandonChecked === true && (
|
2021-07-07 16:21:17 +02:00
|
|
|
<p className="help error__text">{__('This action is permanent and cannot be undone')}</p>
|
2019-12-06 21:57:07 +01:00
|
|
|
)}
|
|
|
|
|
|
|
|
{/* @if TARGET='app' */}
|
|
|
|
{abandonChecked === false && deleteChecked && (
|
2020-05-28 23:14:16 +02:00
|
|
|
<p className="help">{__('This file will be removed from your Library and Downloads folder.')}</p>
|
2019-12-06 21:57:07 +01:00
|
|
|
)}
|
|
|
|
{!deleteChecked && (
|
|
|
|
<p className="help">
|
2020-07-23 03:33:12 +02:00
|
|
|
{__('This file will be removed from your Library but will remain in your Downloads folder.')}
|
2019-12-06 21:57:07 +01:00
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
{/* @endif */}
|
|
|
|
</React.Fragment>
|
2019-11-17 19:32:31 +01:00
|
|
|
)}
|
2019-12-06 21:57:07 +01:00
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
actions={
|
2020-07-23 03:33:12 +02:00
|
|
|
<>
|
|
|
|
<div className="section__actions">
|
|
|
|
<Button
|
|
|
|
button="primary"
|
2020-07-30 18:58:24 +02:00
|
|
|
label={isAbandoning ? __('Removing...') : __('OK')}
|
2021-07-07 16:21:17 +02:00
|
|
|
disabled={isAbandoning || !(deleteChecked || abandonChecked)}
|
2021-06-24 16:33:11 +02:00
|
|
|
onClick={() => deleteFile(uri, deleteChecked, claimIsMine ? abandonChecked : false, doGoBack)}
|
2020-07-23 03:33:12 +02:00
|
|
|
/>
|
|
|
|
<Button button="link" label={__('Cancel')} onClick={closeModal} />
|
|
|
|
</div>
|
|
|
|
<p className="help">{__('These changes will appear shortly.')}</p>
|
|
|
|
</>
|
2019-12-06 21:57:07 +01:00
|
|
|
}
|
|
|
|
/>
|
2019-07-11 04:57:24 +02:00
|
|
|
</Modal>
|
|
|
|
);
|
2017-07-02 20:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ModalRemoveFile;
|