mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 02:08:57 +00:00
Use utility & fixup dependency array
This commit is contained in:
@@ -26,6 +26,7 @@ import { isGIF } from '../types/Attachment';
|
|||||||
import { useRestoreFocus } from '../hooks/useRestoreFocus';
|
import { useRestoreFocus } from '../hooks/useRestoreFocus';
|
||||||
import { usePrevious } from '../hooks/usePrevious';
|
import { usePrevious } from '../hooks/usePrevious';
|
||||||
import { arrow } from '../util/keyboard';
|
import { arrow } from '../util/keyboard';
|
||||||
|
import { isCmdOrCtrl } from '../hooks/useKeyboardShortcuts';
|
||||||
|
|
||||||
export type PropsType = {
|
export type PropsType = {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
@@ -160,7 +161,8 @@ export function Lightbox({
|
|||||||
setVideoTime(videoElement.currentTime);
|
setVideoTime(videoElement.currentTime);
|
||||||
}, [setVideoTime, videoElement]);
|
}, [setVideoTime, videoElement]);
|
||||||
|
|
||||||
const handleSave = (
|
const handleSave = useCallback(
|
||||||
|
(
|
||||||
event: KeyboardEvent | React.MouseEvent<HTMLButtonElement, MouseEvent>
|
event: KeyboardEvent | React.MouseEvent<HTMLButtonElement, MouseEvent>
|
||||||
) => {
|
) => {
|
||||||
if (isViewOnce) {
|
if (isViewOnce) {
|
||||||
@@ -174,7 +176,9 @@ export function Lightbox({
|
|||||||
const { attachment, message, index } = mediaItem;
|
const { attachment, message, index } = mediaItem;
|
||||||
|
|
||||||
saveAttachment(attachment, message.sent_at, index + 1);
|
saveAttachment(attachment, message.sent_at, index + 1);
|
||||||
};
|
},
|
||||||
|
[isViewOnce, media, saveAttachment, selectedIndex]
|
||||||
|
);
|
||||||
|
|
||||||
const handleForward = (
|
const handleForward = (
|
||||||
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
||||||
@@ -193,8 +197,6 @@ export function Lightbox({
|
|||||||
|
|
||||||
const onKeyDown = useCallback(
|
const onKeyDown = useCallback(
|
||||||
(event: KeyboardEvent) => {
|
(event: KeyboardEvent) => {
|
||||||
const isMacOS = (window.platform === 'darwin');
|
|
||||||
|
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case 'Escape': {
|
case 'Escape': {
|
||||||
closeLightbox();
|
closeLightbox();
|
||||||
@@ -214,7 +216,7 @@ export function Lightbox({
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if (isMacOS ? event.metaKey : event.ctrlKey) {
|
if (isCmdOrCtrl(event)) {
|
||||||
handleSave(event);
|
handleSave(event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import type { ContextMenuTriggerType } from '../components/conversation/MessageC
|
|||||||
|
|
||||||
type KeyboardShortcutHandlerType = (ev: KeyboardEvent) => boolean;
|
type KeyboardShortcutHandlerType = (ev: KeyboardEvent) => boolean;
|
||||||
|
|
||||||
function isCmdOrCtrl(ev: KeyboardEvent): boolean {
|
export function isCmdOrCtrl(ev: KeyboardEvent): boolean {
|
||||||
const { ctrlKey, metaKey } = ev;
|
const { ctrlKey, metaKey } = ev;
|
||||||
const commandKey = get(window, 'platform') === 'darwin' && metaKey;
|
const commandKey = get(window, 'platform') === 'darwin' && metaKey;
|
||||||
const controlKey = get(window, 'platform') !== 'darwin' && ctrlKey;
|
const controlKey = get(window, 'platform') !== 'darwin' && ctrlKey;
|
||||||
|
|||||||
Reference in New Issue
Block a user