VoiceMessages: fix crash when uploading invalid audio files
This commit is contained in:
@@ -21,6 +21,7 @@ import "./styles.css";
|
|||||||
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||||
import { Microphone } from "@components/Icons";
|
import { Microphone } from "@components/Icons";
|
||||||
import { Link } from "@components/Link";
|
import { Link } from "@components/Link";
|
||||||
|
import { Paragraph } from "@components/Paragraph";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
|
import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
|
||||||
@@ -144,7 +145,7 @@ function Modal({ modalProps }: { modalProps: ModalProps; }) {
|
|||||||
URL.revokeObjectURL(blobUrl);
|
URL.revokeObjectURL(blobUrl);
|
||||||
}, [blobUrl]);
|
}, [blobUrl]);
|
||||||
|
|
||||||
const [meta] = useAwaiter(async () => {
|
const [meta, metaError] = useAwaiter(async () => {
|
||||||
if (!blob) return EMPTY_META;
|
if (!blob) return EMPTY_META;
|
||||||
|
|
||||||
const audioContext = new AudioContext();
|
const audioContext = new AudioContext();
|
||||||
@@ -214,11 +215,15 @@ function Modal({ modalProps }: { modalProps: ModalProps; }) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Forms.FormTitle>Preview</Forms.FormTitle>
|
<Forms.FormTitle>Preview</Forms.FormTitle>
|
||||||
|
{metaError
|
||||||
|
? <Paragraph className={cl("error")}>Failed to parse selected audio file: {metaError.message}</Paragraph>
|
||||||
|
: (
|
||||||
<VoicePreview
|
<VoicePreview
|
||||||
src={blobUrl}
|
src={blobUrl}
|
||||||
waveform={meta.waveform}
|
waveform={meta.waveform}
|
||||||
recording={isRecording}
|
recording={isRecording}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{isUnsupportedFormat && (
|
{isUnsupportedFormat && (
|
||||||
<Card className={`vc-warning-card ${Margins.top16}`}>
|
<Card className={`vc-warning-card ${Margins.top16}`}>
|
||||||
@@ -236,7 +241,7 @@ function Modal({ modalProps }: { modalProps: ModalProps; }) {
|
|||||||
<Button
|
<Button
|
||||||
disabled={!blob}
|
disabled={!blob}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
sendAudio(blob!, meta);
|
sendAudio(blob!, meta ?? EMPTY_META);
|
||||||
modalProps.onClose();
|
modalProps.onClose();
|
||||||
showToast("Now sending voice message... Please be patient", Toasts.Type.MESSAGE);
|
showToast("Now sending voice message... Please be patient", Toasts.Type.MESSAGE);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -48,3 +48,7 @@
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vc-vmsg-error {
|
||||||
|
color: var(--text-danger);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user