Moves the attach-file shortcut into the component

This commit is contained in:
Josh Perez 2021-10-15 14:51:58 -04:00 committed by GitHub
parent ab1c31b64f
commit fc425304fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 48 deletions

View file

@ -1,7 +1,7 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { useEffect } from 'react';
import { useCallback, useEffect } from 'react';
import { get } from 'lodash';
import * as KeyboardLayout from '../services/keyboardLayout';
@ -15,24 +15,48 @@ function isCmdOrCtrl(ev: KeyboardEvent): boolean {
return commandKey || controlKey;
}
export function getStartRecordingShortcut(
export function useStartRecordingShortcut(
startAudioRecording: () => unknown
): KeyboardShortcutHandlerType {
return ev => {
const { shiftKey } = ev;
return useCallback(
ev => {
const { shiftKey } = ev;
const key = KeyboardLayout.lookup(ev);
const key = KeyboardLayout.lookup(ev);
if (isCmdOrCtrl(ev) && shiftKey && (key === 'v' || key === 'V')) {
ev.preventDefault();
ev.stopPropagation();
if (isCmdOrCtrl(ev) && shiftKey && (key === 'v' || key === 'V')) {
startAudioRecording();
ev.preventDefault();
ev.stopPropagation();
startAudioRecording();
return true;
}
return true;
}
return false;
},
[startAudioRecording]
);
}
return false;
};
export function useAttachFileShortcut(
attachFile: () => unknown
): KeyboardShortcutHandlerType {
return useCallback(
ev => {
const { shiftKey } = ev;
const key = KeyboardLayout.lookup(ev);
if (isCmdOrCtrl(ev) && !shiftKey && (key === 'u' || key === 'U')) {
ev.preventDefault();
ev.stopPropagation();
attachFile();
return true;
}
return false;
},
[attachFile]
);
}
export function useKeyboardShortcuts(