Moves the attach-file shortcut into the component
This commit is contained in:
parent
ab1c31b64f
commit
fc425304fc
5 changed files with 50 additions and 48 deletions
|
@ -1565,18 +1565,7 @@ export async function startApp(): Promise<void> {
|
||||||
// Send in expanded composer - handled by component
|
// Send in expanded composer - handled by component
|
||||||
|
|
||||||
// Attach file
|
// Attach file
|
||||||
if (
|
// hooks/useKeyboardShorcuts useAttachFileShortcut
|
||||||
conversation &&
|
|
||||||
commandOrCtrl &&
|
|
||||||
!shiftKey &&
|
|
||||||
(key === 'u' || key === 'U')
|
|
||||||
) {
|
|
||||||
conversation.trigger('attach-file');
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove draft link preview
|
// Remove draft link preview
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -50,6 +50,10 @@ import { MediaQualitySelector } from './MediaQualitySelector';
|
||||||
import { Quote, Props as QuoteProps } from './conversation/Quote';
|
import { Quote, Props as QuoteProps } from './conversation/Quote';
|
||||||
import { StagedLinkPreview } from './conversation/StagedLinkPreview';
|
import { StagedLinkPreview } from './conversation/StagedLinkPreview';
|
||||||
import { countStickers } from './stickers/lib';
|
import { countStickers } from './stickers/lib';
|
||||||
|
import {
|
||||||
|
useAttachFileShortcut,
|
||||||
|
useKeyboardShortcuts,
|
||||||
|
} from '../hooks/useKeyboardShortcuts';
|
||||||
|
|
||||||
export type CompositionAPIType =
|
export type CompositionAPIType =
|
||||||
| {
|
| {
|
||||||
|
@ -269,7 +273,7 @@ export const CompositionArea = ({
|
||||||
[draftAttachments, onSendMessage, setLarge]
|
[draftAttachments, onSendMessage, setLarge]
|
||||||
);
|
);
|
||||||
|
|
||||||
const launchAttachmentPicker = () => {
|
const launchAttachmentPicker = useCallback(() => {
|
||||||
const fileInput = fileInputRef.current;
|
const fileInput = fileInputRef.current;
|
||||||
if (fileInput) {
|
if (fileInput) {
|
||||||
// Setting the value to empty so that onChange always fires in case
|
// Setting the value to empty so that onChange always fires in case
|
||||||
|
@ -277,7 +281,10 @@ export const CompositionArea = ({
|
||||||
fileInput.value = '';
|
fileInput.value = '';
|
||||||
fileInput.click();
|
fileInput.click();
|
||||||
}
|
}
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
|
const attachFileShortcut = useAttachFileShortcut(launchAttachmentPicker);
|
||||||
|
useKeyboardShortcuts(attachFileShortcut);
|
||||||
|
|
||||||
const focusInput = useCallback(() => {
|
const focusInput = useCallback(() => {
|
||||||
if (inputApiRef.current) {
|
if (inputApiRef.current) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2016-2020 Signal Messenger, LLC
|
// Copyright 2016-2020 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { noop } from 'lodash';
|
import { noop } from 'lodash';
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import { ToastVoiceNoteLimit } from '../ToastVoiceNoteLimit';
|
||||||
import { ToastVoiceNoteMustBeOnlyAttachment } from '../ToastVoiceNoteMustBeOnlyAttachment';
|
import { ToastVoiceNoteMustBeOnlyAttachment } from '../ToastVoiceNoteMustBeOnlyAttachment';
|
||||||
import { useEscapeHandling } from '../../hooks/useEscapeHandling';
|
import { useEscapeHandling } from '../../hooks/useEscapeHandling';
|
||||||
import {
|
import {
|
||||||
getStartRecordingShortcut,
|
useStartRecordingShortcut,
|
||||||
useKeyboardShortcuts,
|
useKeyboardShortcuts,
|
||||||
} from '../../hooks/useKeyboardShortcuts';
|
} from '../../hooks/useKeyboardShortcuts';
|
||||||
|
|
||||||
|
@ -94,10 +94,7 @@ export const AudioCapture = ({
|
||||||
|
|
||||||
useEscapeHandling(escapeRecording);
|
useEscapeHandling(escapeRecording);
|
||||||
|
|
||||||
const startRecordingShortcut = useMemo(() => {
|
const startRecordingShortcut = useStartRecordingShortcut(startRecording);
|
||||||
return getStartRecordingShortcut(startRecording);
|
|
||||||
}, [startRecording]);
|
|
||||||
|
|
||||||
useKeyboardShortcuts(startRecordingShortcut);
|
useKeyboardShortcuts(startRecordingShortcut);
|
||||||
|
|
||||||
// Update timestamp regularly, then timeout if recording goes over five minutes
|
// Update timestamp regularly, then timeout if recording goes over five minutes
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
|
|
||||||
import * as KeyboardLayout from '../services/keyboardLayout';
|
import * as KeyboardLayout from '../services/keyboardLayout';
|
||||||
|
@ -15,24 +15,48 @@ function isCmdOrCtrl(ev: KeyboardEvent): boolean {
|
||||||
return commandKey || controlKey;
|
return commandKey || controlKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStartRecordingShortcut(
|
export function useStartRecordingShortcut(
|
||||||
startAudioRecording: () => unknown
|
startAudioRecording: () => unknown
|
||||||
): KeyboardShortcutHandlerType {
|
): KeyboardShortcutHandlerType {
|
||||||
return ev => {
|
return useCallback(
|
||||||
const { shiftKey } = ev;
|
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();
|
||||||
startAudioRecording();
|
return true;
|
||||||
ev.preventDefault();
|
}
|
||||||
ev.stopPropagation();
|
|
||||||
|
|
||||||
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(
|
export function useKeyboardShortcuts(
|
||||||
|
|
|
@ -287,7 +287,6 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
// These are triggered by background.ts for keyboard handling
|
// These are triggered by background.ts for keyboard handling
|
||||||
this.listenTo(this.model, 'focus-composer', this.focusMessageField);
|
this.listenTo(this.model, 'focus-composer', this.focusMessageField);
|
||||||
this.listenTo(this.model, 'open-all-media', this.showAllMedia);
|
this.listenTo(this.model, 'open-all-media', this.showAllMedia);
|
||||||
this.listenTo(this.model, 'attach-file', this.onChooseAttachment);
|
|
||||||
this.listenTo(this.model, 'escape-pressed', this.resetPanel);
|
this.listenTo(this.model, 'escape-pressed', this.resetPanel);
|
||||||
this.listenTo(this.model, 'show-message-details', this.showMessageDetail);
|
this.listenTo(this.model, 'show-message-details', this.showMessageDetail);
|
||||||
this.listenTo(this.model, 'show-contact-modal', this.showContactModal);
|
this.listenTo(this.model, 'show-contact-modal', this.showContactModal);
|
||||||
|
@ -1288,20 +1287,6 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onChooseAttachment(): void {
|
|
||||||
// TODO: DESKTOP-2425
|
|
||||||
this.$('input.file-input').click();
|
|
||||||
}
|
|
||||||
|
|
||||||
async onChoseAttachment(): Promise<void> {
|
|
||||||
const fileField = this.$('input.file-input');
|
|
||||||
const files: Array<File> = Array.from(fileField.prop('files'));
|
|
||||||
|
|
||||||
fileField.val([]);
|
|
||||||
|
|
||||||
await this.processAttachments(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO DESKTOP-2426
|
// TODO DESKTOP-2426
|
||||||
async processAttachments(files: Array<File>): Promise<void> {
|
async processAttachments(files: Array<File>): Promise<void> {
|
||||||
const {
|
const {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue