fix #2132: Remember ModalRemoveFile check boxes #2625

Merged
derek-yesmunt merged 1 commit from master into master 2019-07-11 05:00:28 +02:00
3 changed files with 43 additions and 71 deletions

View file

@ -2,6 +2,7 @@
import React from 'react';
import { Modal } from 'modal/modal';
import { FormField } from 'component/common/form';
import usePersistedState from 'util/use-persisted-state';
type Props = {
claim: StreamClaim,
@ -14,40 +15,10 @@ type Props = {
},
};
type State = {
deleteChecked: boolean,
abandonClaimChecked: boolean,
};
class ModalRemoveFile extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
deleteChecked: false,
abandonClaimChecked: true,
};
(this: any).handleDeleteCheckboxClicked = this.handleDeleteCheckboxClicked.bind(this);
(this: any).handleAbandonClaimCheckboxClicked = this.handleAbandonClaimCheckboxClicked.bind(this);
}
handleDeleteCheckboxClicked() {
const { deleteChecked } = this.state;
this.setState({
deleteChecked: !deleteChecked,
});
}
handleAbandonClaimCheckboxClicked() {
const { abandonClaimChecked } = this.state;
this.setState({
abandonClaimChecked: !abandonClaimChecked,
});
}
render() {
const { claim, claimIsMine, closeModal, deleteFile, fileInfo, title } = this.props;
const { deleteChecked, abandonClaimChecked } = this.state;
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}`;
@ -58,7 +29,8 @@ class ModalRemoveFile extends React.PureComponent<Props, State> {
contentLabel={__('Confirm File Remove')}
type="confirm"
confirmButtonLabel={__('Remove')}
onConfirmed={() => deleteFile(outpoint || '', deleteChecked, abandonClaimChecked)}
confirmButtonDisabled={!deleteChecked && !abandonChecked}
onConfirmed={() => deleteFile(outpoint || '', deleteChecked, abandonChecked)}
onAborted={closeModal}
>
<section className="card__content">
@ -72,7 +44,7 @@ class ModalRemoveFile extends React.PureComponent<Props, State> {
label={__('Also delete this file from my computer')}
type="checkbox"
checked={deleteChecked}
onChange={this.handleDeleteCheckboxClicked}
onChange={() => setDeleteChecked(!deleteChecked)}
/>
{claimIsMine && (
@ -80,14 +52,13 @@ class ModalRemoveFile extends React.PureComponent<Props, State> {
name="claim_abandon"
label={__('Abandon the claim for this URI')}
type="checkbox"
checked={abandonClaimChecked}
onChange={this.handleAbandonClaimCheckboxClicked}
checked={abandonChecked}
onChange={() => setAbandonChecked(!abandonChecked)}
/>
)}
</section>
</Modal>
);
}
}
export default ModalRemoveFile;

View file

@ -14,7 +14,7 @@ export default function usePersistedState(key, firstTimeDefault) {
}
}
if (!defaultValue) {
if (!defaultValue && defaultValue !== false) {
defaultValue = firstTimeDefault;
}

View file

@ -540,5 +540,6 @@
"During the alpha, comments are not decentralized or censorship resistant (but we repeat ourselves).": "During the alpha, comments are not decentralized or censorship resistant (but we repeat ourselves).",
"When the alpha ends, we will attempt to transition comments, but do not promise to do so. Any transition will likely involve publishing previous comments under a single archive handle.": "When the alpha ends, we will attempt to transition comments, but do not promise to do so. Any transition will likely involve publishing previous comments under a single archive handle.",
"Upgrade is ready to install": "Upgrade is ready to install",
"Upgrade is ready": "Upgrade is ready"
"Upgrade is ready": "Upgrade is ready",
"Abandon the claim for this URI": "Abandon the claim for this URI"
}