Skip to content

Commit

Permalink
Restores ESC to close preferences
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and josh-signal committed Aug 24, 2021
1 parent b2ccd9e commit 36aba97
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ts/components/Preferences.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand Down
18 changes: 18 additions & 0 deletions ts/components/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type PropsType = {

// Other props
addCustomColor: (color: CustomColorType) => unknown;
closeSettings: () => unknown;
doDeleteAllData: () => unknown;
editCustomColor: (colorId: string, color: CustomColorType) => unknown;
getConversationsWithCustomColor: (
Expand Down Expand Up @@ -158,6 +159,7 @@ export const Preferences = ({
availableMicrophones,
availableSpeakers,
blockedCount,
closeSettings,
customColors,
defaultConversationColor,
deviceName = '',
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions ts/windows/settings/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 36aba97

Please sign in to comment.