fix #2132: Remember ModalRemoveFile check boxes #2625
3 changed files with 43 additions and 71 deletions
|
@ -2,6 +2,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Modal } from 'modal/modal';
|
import { Modal } from 'modal/modal';
|
||||||
import { FormField } from 'component/common/form';
|
import { FormField } from 'component/common/form';
|
||||||
|
import usePersistedState from 'util/use-persisted-state';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
claim: StreamClaim,
|
claim: StreamClaim,
|
||||||
|
@ -14,40 +15,10 @@ type Props = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
function ModalRemoveFile(props: Props) {
|
||||||
deleteChecked: boolean,
|
const { claim, claimIsMine, closeModal, deleteFile, fileInfo, title } = props;
|
||||||
abandonClaimChecked: boolean,
|
const [deleteChecked, setDeleteChecked] = usePersistedState('modal-remove-file:delete', true);
|
||||||
};
|
const [abandonChecked, setAbandonChecked] = usePersistedState('modal-remove-file:abandon', true);
|
||||||
|
|
||||||
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;
|
|
||||||
const { txid, nout } = claim;
|
const { txid, nout } = claim;
|
||||||
const outpoint = fileInfo ? fileInfo.outpoint : `${txid}:${nout}`;
|
const outpoint = fileInfo ? fileInfo.outpoint : `${txid}:${nout}`;
|
||||||
|
|
||||||
|
@ -58,7 +29,8 @@ class ModalRemoveFile extends React.PureComponent<Props, State> {
|
||||||
contentLabel={__('Confirm File Remove')}
|
contentLabel={__('Confirm File Remove')}
|
||||||
type="confirm"
|
type="confirm"
|
||||||
confirmButtonLabel={__('Remove')}
|
confirmButtonLabel={__('Remove')}
|
||||||
onConfirmed={() => deleteFile(outpoint || '', deleteChecked, abandonClaimChecked)}
|
confirmButtonDisabled={!deleteChecked && !abandonChecked}
|
||||||
|
onConfirmed={() => deleteFile(outpoint || '', deleteChecked, abandonChecked)}
|
||||||
onAborted={closeModal}
|
onAborted={closeModal}
|
||||||
>
|
>
|
||||||
<section className="card__content">
|
<section className="card__content">
|
||||||
|
@ -72,7 +44,7 @@ class ModalRemoveFile extends React.PureComponent<Props, State> {
|
||||||
label={__('Also delete this file from my computer')}
|
label={__('Also delete this file from my computer')}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={deleteChecked}
|
checked={deleteChecked}
|
||||||
onChange={this.handleDeleteCheckboxClicked}
|
onChange={() => setDeleteChecked(!deleteChecked)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{claimIsMine && (
|
{claimIsMine && (
|
||||||
|
@ -80,14 +52,13 @@ class ModalRemoveFile extends React.PureComponent<Props, State> {
|
||||||
name="claim_abandon"
|
name="claim_abandon"
|
||||||
label={__('Abandon the claim for this URI')}
|
label={__('Abandon the claim for this URI')}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={abandonClaimChecked}
|
checked={abandonChecked}
|
||||||
onChange={this.handleAbandonClaimCheckboxClicked}
|
onChange={() => setAbandonChecked(!abandonChecked)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export default ModalRemoveFile;
|
export default ModalRemoveFile;
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default function usePersistedState(key, firstTimeDefault) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defaultValue) {
|
if (!defaultValue && defaultValue !== false) {
|
||||||
defaultValue = firstTimeDefault;
|
defaultValue = firstTimeDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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).",
|
"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.",
|
"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 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"
|
||||||
}
|
}
|
Loading…
Reference in a new issue