Restores ESC to close preferences

This commit is contained in:
Josh Perez 2021-08-24 17:00:56 -04:00 committed by GitHub
parent 424d8785b6
commit c304cb84fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -101,8 +101,9 @@ const createProps = (): PropsType => ({
zoomFactor: 1,
addCustomColor: action('addCustomColor'),
editCustomColor: action('editCustomColor'),
closeSettings: action('closeSettings'),
doDeleteAllData: action('doDeleteAllData'),
editCustomColor: action('editCustomColor'),
getConversationsWithCustomColor: () => Promise.resolve([]),
initialSpellCheckSetting: true,
makeSyncRequest: () => {

View File

@ -76,6 +76,7 @@ export type PropsType = {
// Other props
addCustomColor: (color: CustomColorType) => unknown;
closeSettings: () => unknown;
doDeleteAllData: () => unknown;
editCustomColor: (colorId: string, color: CustomColorType) => unknown;
getConversationsWithCustomColor: (
@ -158,6 +159,7 @@ export const Preferences = ({
availableMicrophones,
availableSpeakers,
blockedCount,
closeSettings,
customColors,
defaultConversationColor,
deviceName = '',
@ -249,6 +251,22 @@ export const Preferences = ({
document.body.classList.toggle('dark-theme', theme === ThemeType.dark);
}, [theme]);
useEffect(() => {
const handler = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
closeSettings();
event.preventDefault();
event.stopPropagation();
}
};
document.addEventListener('keydown', handler);
return () => {
document.removeEventListener('keydown', handler);
};
}, [closeSettings]);
const onZoomSelectChange = useCallback(
(value: string) => {
const number = parseFloat(value);

View File

@ -291,6 +291,7 @@ async function renderPreferences() {
// Actions and other props
addCustomColor: ipcAddCustomColor,
closeSettings: () => ipcRenderer.send('close-settings'),
doDeleteAllData: () => ipcRenderer.send('delete-all-data'),
editCustomColor: ipcEditCustomColor,
getConversationsWithCustomColor: ipcGetConversationsWithCustomColor,