From 603c315c82dd90e4f791a622a0c84cb64430c855 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Wed, 29 Sep 2021 16:23:06 -0400 Subject: [PATCH] Moves AudioCapture into react --- _locales/en/messages.json | 12 + preload.js | 1 - stylesheets/components/AudioCapture.scss | 128 ++++++++++ stylesheets/components/Toast.scss | 1 + stylesheets/manifest.scss | 1 + test/index.html | 5 - ts/background.ts | 17 +- ts/components/CompositionArea.stories.tsx | 24 +- ts/components/CompositionArea.tsx | 112 +++++---- .../conversation/AudioCapture.stories.tsx | 66 +++++ ts/components/conversation/AudioCapture.tsx | 227 +++++++++++++++++ ts/hooks/useKeyboardShortcuts.tsx | 47 ++++ ts/services/audioRecorder.ts | 132 ++++++++++ ts/state/actions.ts | 3 + ts/state/ducks/audioRecorder.ts | 199 +++++++++++++++ ts/state/reducer.ts | 2 + ts/state/smart/CompositionArea.tsx | 4 + ts/state/types.ts | 2 + ts/util/lint/exceptions.json | 93 ------- ts/util/resolveAttachmentDraftData.ts | 30 +++ ts/views/conversation_view.ts | 229 +++++------------- ts/views/recorder_view.ts | 143 ----------- ts/window.d.ts | 26 +- 23 files changed, 1012 insertions(+), 492 deletions(-) create mode 100644 stylesheets/components/AudioCapture.scss create mode 100644 ts/components/conversation/AudioCapture.stories.tsx create mode 100644 ts/components/conversation/AudioCapture.tsx create mode 100644 ts/hooks/useKeyboardShortcuts.tsx create mode 100644 ts/services/audioRecorder.ts create mode 100644 ts/state/ducks/audioRecorder.ts create mode 100644 ts/util/resolveAttachmentDraftData.ts delete mode 100644 ts/views/recorder_view.ts diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 38d6e5f05..71ae1267b 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -909,6 +909,18 @@ "message": "Original message found, but not loaded. Scroll up to load it.", "description": "Shown in toast if user clicks on quote references messages not loaded in view, but in database" }, + "voiceRecording--start": { + "message": "Start recording voice message", + "description": "Tooltip for microphone button to start voice message" + }, + "voiceRecording--complete": { + "message": "Complete voice message and send", + "description": "Tooltip for green complete voice message and send" + }, + "voiceRecording--cancel": { + "message": "Cancel voice message", + "description": "Tooltip for red button to cancel voice message" + }, "voiceRecordingInterruptedMax": { "message": "Voice message recording stopped because the maximum time limit was reached.", "description": "Confirmation dialog message for when the voice recording is interrupted due to max time limit" diff --git a/preload.js b/preload.js index 0c0ba70b2..b601acdce 100644 --- a/preload.js +++ b/preload.js @@ -466,7 +466,6 @@ try { require('./ts/views/conversation_view'); require('./ts/views/inbox_view'); require('./ts/views/install_view'); - require('./ts/views/recorder_view'); require('./ts/views/standalone_registration_view'); require('./ts/SignalProtocolStore'); require('./ts/background'); diff --git a/stylesheets/components/AudioCapture.scss b/stylesheets/components/AudioCapture.scss new file mode 100644 index 000000000..21cb219fb --- /dev/null +++ b/stylesheets/components/AudioCapture.scss @@ -0,0 +1,128 @@ +// Copyright 2016-2020 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +.AudioCapture { + display: flex; + text-align: center; + flex-direction: row; + justify-content: center; + align-items: center; + background: none; + + &__microphone { + height: 32px; + width: 32px; + text-align: center; + opacity: 0.5; + background: none; + + padding: 0; + border: none; + + &:focus, + &:hover { + opacity: 1; + } + + outline: none; + + &:before { + content: ''; + display: inline-block; + height: 24px; + width: 24px; + + @include light-theme { + @include color-svg( + '../images/icons/v2/mic-outline-24.svg', + $color-gray-75 + ); + } + @include dark-theme { + @include color-svg( + '../images/icons/v2/mic-solid-24.svg', + $color-gray-15 + ); + } + } + } + + &__recorder-button { + flex-grow: 0; + flex-shrink: 0; + + width: 32px; + height: 32px; + border-radius: 32px; + margin-left: 5px; + opacity: 0.3; + text-align: center; + padding: 0; + + &:focus, + &:hover { + opacity: 1; + } + + outline: none; + + .icon { + display: inline-block; + width: 24px; + height: 24px; + margin-bottom: -3px; + } + + &--complete { + background: lighten($color-accent-green, 20%); + border: 1px solid $color-accent-green; + + .icon { + @include color-svg( + '../images/icons/v2/check-24.svg', + $color-accent-green + ); + } + } + + &--cancel { + background: lighten($color-accent-red, 20%); + border: 1px solid $color-accent-red; + + .icon { + @include color-svg('../images/icons/v2/x-24.svg', $color-accent-red); + } + } + } + + &__time { + color: $color-gray-60; + font-variant: tabular-nums; + line-height: 36px; + padding: 0 10px; + + @keyframes pulse { + 0% { + opacity: 0; + } + 50% { + opacity: 1; + } + 100% { + opacity: 0; + } + } + + &::before { + content: ''; + display: inline-block; + border-radius: 10px; + width: 10px; + height: 10px; + background: $color-accent-red; + margin-right: 10px; + opacity: 0; + animation: pulse 2s infinite; + } + } +} diff --git a/stylesheets/components/Toast.scss b/stylesheets/components/Toast.scss index c72871033..6f591f633 100644 --- a/stylesheets/components/Toast.scss +++ b/stylesheets/components/Toast.scss @@ -11,6 +11,7 @@ position: absolute; text-align: center; transform: translate(-50%, 0); + user-select: none; z-index: 100; @include light-theme { diff --git a/stylesheets/manifest.scss b/stylesheets/manifest.scss index 838786afc..8d9d7b1e5 100644 --- a/stylesheets/manifest.scss +++ b/stylesheets/manifest.scss @@ -30,6 +30,7 @@ @import './components/AddGroupMembersModal.scss'; @import './components/AnnouncementsOnlyGroupBanner.scss'; @import './components/App.scss'; +@import './components/AudioCapture.scss'; @import './components/Avatar.scss'; @import './components/AvatarEditor.scss'; @import './components/AvatarModalButtons.scss'; diff --git a/test/index.html b/test/index.html index 708a8815d..2ead908b5 100644 --- a/test/index.html +++ b/test/index.html @@ -284,11 +284,6 @@ src="../js/views/group_member_list_view.js" data-cover > -