diff --git a/package.json b/package.json index f3634502..bf2ac914 100644 --- a/package.json +++ b/package.json @@ -28,13 +28,13 @@ "weather-icons-react": "1.2.0" }, "devDependencies": { - "@babel/core": "^7.15.0", - "@babel/eslint-parser": "^7.15.0", + "@babel/core": "^7.15.5", + "@babel/eslint-parser": "^7.15.4", "@babel/plugin-proposal-class-properties": "^7.14.5", "@babel/plugin-transform-react-constant-elements": "^7.14.5", "@babel/plugin-transform-react-inline-elements": "^7.14.5", "@babel/plugin-transform-runtime": "^7.15.0", - "@babel/preset-env": "^7.15.0", + "@babel/preset-env": "^7.15.4", "@babel/preset-react": "^7.14.5", "@eartharoid/deep-merge": "^0.0.1", "babel-loader": "^8.2.2", @@ -44,13 +44,13 @@ "eslint": "^7.32.0", "eslint-config-react-app": "^6.0.0", "html-webpack-plugin": "^5.3.2", - "mini-css-extract-plugin": "^2.2.0", - "sass": "^1.38.0", + "mini-css-extract-plugin": "^2.2.2", + "sass": "^1.39.0", "sass-loader": "^12.1.0", "source-map-loader": "^3.0.0", - "webpack": "^5.51.1", + "webpack": "^5.51.0", "webpack-cli": "^4.8.0", - "webpack-dev-server": "^4.0.0" + "webpack-dev-server": "^4.1.0" }, "scripts": { "start": "webpack serve", diff --git a/src/components/modals/main/settings/KeybindInput.jsx b/src/components/modals/main/settings/KeybindInput.jsx new file mode 100644 index 00000000..0ced3175 --- /dev/null +++ b/src/components/modals/main/settings/KeybindInput.jsx @@ -0,0 +1,22 @@ +export default function KeybindInput(props) { + const language = window.language.modals.main.settings; + + const getButton = () => { + const value = props.state[props.settingsName]; + if (!value) { + return null; + } else if (value === language.sections.keybinds.recording) { + return props.cancel(props.settingsName)}>{language.sections.advanced.reset_modal.cancel} + } else { + return props.reset(props.settingsName)}>{language.buttons.reset}; + } + } + + return ( + <> +
{props.name}
+ props.set(props.settingsName)} value={props.state[props.settingsName] || language.sections.keybinds.click_to_record} readOnly/> + {getButton()} + > + ); +} diff --git a/src/components/modals/main/settings/sections/Keybinds.jsx b/src/components/modals/main/settings/sections/Keybinds.jsx index 16334d24..e9f08d86 100644 --- a/src/components/modals/main/settings/sections/Keybinds.jsx +++ b/src/components/modals/main/settings/sections/Keybinds.jsx @@ -1,6 +1,7 @@ import { PureComponent } from 'react'; -import Checkbox from '../Checkbox'; +import Switch from '../Switch'; +import KeybindInput from '../KeybindInput'; export default class KeybindSettings extends PureComponent { constructor() { @@ -25,7 +26,7 @@ export default class KeybindSettings extends PureComponent { this.forceUpdate(); let keys = ''; - const keydown = document.addEventListener('keydown', (event) => { + this.keydown = document.addEventListener('keydown', (event) => { if (keys === '') { keys = event.key; } else { @@ -33,8 +34,8 @@ export default class KeybindSettings extends PureComponent { } }); - const keyup = document.addEventListener('keyup', () => { - document.removeEventListener('keydown', keydown); + this.keyup = document.addEventListener('keyup', () => { + document.removeEventListener('keydown', this.keydown); const keybinds = this.state.keybinds; keybinds[type] = keys; localStorage.setItem('keybinds', JSON.stringify(keybinds)); @@ -43,11 +44,22 @@ export default class KeybindSettings extends PureComponent { }); }); - document.removeEventListener('keyup', keyup); + document.removeEventListener('keyup', this.keyup); this.showReminder(); } + cancel(type) { + document.removeEventListener('keydown', this.keydown); + document.removeEventListener('keyup', this.keyup); + const currentKeybinds = this.state.keybinds; + delete currentKeybinds[type]; + this.setState({ + keybinds: currentKeybinds + }); + this.forceUpdate(); + } + reset(type) { const keybinds = this.state.keybinds; keybinds[type] = ''; @@ -65,67 +77,19 @@ export default class KeybindSettings extends PureComponent { return ( <>{keybinds.background.favourite}
- this.listen('favouriteBackground')} value={this.state.keybinds['favouriteBackground'] || ''} readOnly/> - this.reset('favouriteBackground')}>{this.language.buttons.reset} -{keybinds.background.maximise}
- this.listen('maximiseBackground')} value={this.state.keybinds['maximiseBackground'] || ''} readOnly/> - this.reset('maximiseBackground')}>{this.language.buttons.reset} -{keybinds.background.download}
- this.listen('downloadBackground')} value={this.state.keybinds['downloadBackground'] || ''} readOnly/> - this.reset('downloadBackground')}>{this.language.buttons.reset} -{keybinds.background.show_info}
- this.listen('showBackgroundInformation')} value={this.state.keybinds['showBackgroundInformation'] || ''} readOnly/> - this.reset('showBackgroundInformation')}>{this.language.buttons.reset} -{keybinds.quote.favourite}
- this.listen('favouriteQuote')} value={this.state.keybinds['favouriteQuote'] || ''} readOnly/> - this.reset('favouriteQuote')}>{this.language.buttons.reset} -{keybinds.quote.copy}
- this.listen('copyQuote')} value={this.state.keybinds['copyQuote'] || ''} readOnly/> - this.reset('copyQuote')}>{this.language.buttons.reset} -{keybinds.quote.tweet}
- this.listen('tweetQuote')} value={this.state.keybinds['tweetQuote'] || ''} readOnly/> - this.reset('tweetQuote')}>{this.language.buttons.reset} -{keybinds.notes.pin}
- this.listen('pinNotes')} value={this.state.keybinds['pinNotes'] || ''} readOnly/> - this.reset('pinNotes')}>{this.language.buttons.reset} -{keybinds.notes.copy}
- this.listen('copyNotes')} value={this.state.keybinds['copyNotes'] || ''} readOnly/> - this.reset('copyNotes')}>{this.language.buttons.reset} -{keybinds.search}
- this.listen('focusSearch')} value={this.state.keybinds['focusSearch'] || ''} readOnly/> - this.reset('focusSearch')}>{this.language.buttons.reset} -{keybinds.quicklinks}
- this.listen('toggleQuicklinks')} value={this.state.keybinds['toggleQuicklinks'] || ''} readOnly/> - this.reset('toggleQuicklinks')}>{this.language.buttons.reset} -{keybinds.modal}
- this.listen('toggleModal')} value={this.state.keybinds['toggleModal'] || ''} readOnly/> - this.reset('toggleModal')}>{this.language.buttons.reset} -