Skip to content

Commit

Permalink
fixed unnecessary placement of mic permission info
Browse files Browse the repository at this point in the history
  • Loading branch information
Spiral-Memory committed Mar 13, 2024
1 parent 4c51d3a commit e5c8f34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/Components/Patient/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const FileUpload = (props: FileUploadProps) => {
{ name: "Unarchived Files", value: "UNARCHIVED" },
{ name: "Archived Files", value: "ARCHIVED" },
]);
const [isMicPermission, setIsMicPermission] = useState(true);

const { data: patient } = useQuery(routes.getPatient, {
pathParams: { id: patientId },
Expand Down Expand Up @@ -556,6 +557,10 @@ export const FileUpload = (props: FileUploadProps) => {
setbtnloader(false);
};

const handleSetMicPermission = (isPermitted: boolean) => {
setIsMicPermission(isPermitted);
};

const renderFileUpload = (item: FileUploadModel) => {
const isPreviewSupported = previewExtensions.includes(item.extension ?? "");
return (
Expand Down Expand Up @@ -1474,8 +1479,9 @@ export const FileUpload = (props: FileUploadProps) => {
confirmAudioBlobExists={confirmAudioBlobExists}
reset={resetRecording}
setResetRecording={setResetRecording}
handleSetMicPermission={handleSetMicPermission}
/>
{!audioBlobExists && (
{!audioBlobExists && !isMicPermission && (
<span className="text-sm font-medium text-warning-500">
<CareIcon className="care-l-exclamation-triangle mr-1 text-base" />
Please allow browser permission before you start
Expand Down
11 changes: 8 additions & 3 deletions src/Utils/VoiceRecorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import { NonReadOnlyUsers } from "./AuthorizeFor";
import { useTranslation } from "react-i18next";
export const VoiceRecorder = (props: any) => {
const { t } = useTranslation();
const { createAudioBlob, confirmAudioBlobExists, reset, setResetRecording } =
props;
const {
createAudioBlob,
confirmAudioBlobExists,
reset,
setResetRecording,
handleSetMicPermission,
} = props;
const [
audioURL,
isRecording,
startRecording,
stopRecording,
newBlob,
resetRecording,
] = useRecorder();
] = useRecorder(handleSetMicPermission);
const [time, setTime] = useState(0);
createAudioBlob(newBlob);
useEffect(() => {
Expand Down
19 changes: 14 additions & 5 deletions src/Utils/useRecorder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { Error } from "./Notifications";

const useRecorder = () => {
const useRecorder = (handleMicPermission) => {
const [audioURL, setAudioURL] = useState("");
const [isRecording, setIsRecording] = useState(false);
const [recorder, setRecorder] = useState(null);
Expand All @@ -11,10 +11,19 @@ const useRecorder = () => {
// Lazily obtain recorder first time we're recording.
if (recorder === null) {
if (isRecording) {
requestRecorder().then(setRecorder, () => {
Error({ msg: "Please grant microphone permission to record audio." });
setIsRecording(false);
});
requestRecorder().then(
(fetchedRecorder) => {
setRecorder(fetchedRecorder);
handleMicPermission(true);
},
() => {
Error({
msg: "Please grant microphone permission to record audio.",
});
setIsRecording(false);
handleMicPermission(false);
}
);
}
return;
}
Expand Down

0 comments on commit e5c8f34

Please sign in to comment.