lbry-desktop/src/ui/modal/modalRemoveFile/view.jsx

67 lines
2.2 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
import { Modal } from 'modal/modal';
2019-07-18 00:22:47 +02:00
import { Form, FormField } from 'component/common/form';
import Button from 'component/button';
import usePersistedState from 'util/use-persisted-state';
2017-07-02 20:23:38 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
claim: StreamClaim,
2018-03-26 23:32:43 +02:00
claimIsMine: boolean,
closeModal: () => void,
deleteFile: (string, boolean, boolean) => void,
title: string,
fileInfo?: {
outpoint: ?string,
2018-03-26 23:32:43 +02:00
},
};
function ModalRemoveFile(props: Props) {
const { claim, claimIsMine, closeModal, deleteFile, fileInfo, title } = props;
const [deleteChecked, setDeleteChecked] = usePersistedState('modal-remove-file:delete', true);
const [abandonChecked, setAbandonChecked] = usePersistedState('modal-remove-file:abandon', true);
const { txid, nout } = claim;
const outpoint = fileInfo ? fileInfo.outpoint : `${txid}:${nout}`;
2017-07-02 20:23:38 +02:00
return (
2019-07-18 00:22:47 +02:00
<Modal isOpen title="Remove File" contentLabel={__('Confirm File Remove')} type="custom" onAborted={closeModal}>
2019-07-21 23:31:22 +02:00
<section>
<p>
{__("Are you sure you'd like to remove")} <cite>{`"${title}"`}</cite> {__('from the LBRY app?')}
</p>
</section>
2019-07-21 23:31:22 +02:00
<Form onSubmit={() => deleteFile(outpoint || '', deleteChecked, abandonChecked)}>
<FormField
2019-08-02 08:28:14 +02:00
name="file_delete"
label={__('Also delete this file from my computer')}
type="checkbox"
2019-08-02 08:28:14 +02:00
checked={deleteChecked}
onChange={() => setDeleteChecked(!deleteChecked)}
/>
2017-07-02 20:23:38 +02:00
{claimIsMine && (
2019-02-13 17:27:20 +01:00
<FormField
name="claim_abandon"
label={__('Abandon the claim for this URI')}
2019-02-13 17:27:20 +01:00
type="checkbox"
checked={abandonChecked}
onChange={() => setAbandonChecked(!abandonChecked)}
2019-02-13 17:27:20 +01:00
/>
)}
2019-07-18 00:22:47 +02:00
<div className="card__actions">
<Button
autoFocus
button="primary"
label={__('OK')}
disabled={!deleteChecked && !abandonChecked}
2019-08-14 05:56:11 +02:00
onClick={() => deleteFile(outpoint || '', deleteChecked, claimIsMine ? abandonChecked : false)}
2019-07-18 00:22:47 +02:00
/>
<Button button="link" label={__('Cancel')} onClick={closeModal} />
</div>
</Form>
</Modal>
);
2017-07-02 20:23:38 +02:00
}
export default ModalRemoveFile;