Clear the editor when clicking on the active bang.

This commit is contained in:
Bauke 2022-03-15 11:30:35 +01:00
parent d66b43e9fd
commit 28123cfb3f
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 12 additions and 3 deletions

View File

@ -120,9 +120,18 @@ export class PageMain extends Component<Props, State> {
const availableBangs = bangs.map((bang) => {
const active = bang.id === this.state.editorBang.id ? 'active' : '';
const onClick = () => {
this.setState({
editorBang: {...bang},
});
const allEqual = Object.entries(this.state.editorBang).every(
([key, value]) => bang[key as keyof BangParameters] === value,
);
if (allEqual) {
this.setState({
editorBang: {...this.emptyBang},
});
} else {
this.setState({
editorBang: {...bang},
});
}
};
return html`