From e98f1bf4bc7bed06fddecd22537ea819761b83b7 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 13 Nov 2023 18:33:24 +0100 Subject: [PATCH] loading and redirecting front-end --- .../transcripts/[transcriptId]/page.tsx | 18 +++++-- .../[transcriptId]/record/page.tsx | 50 +++++++++++++------ www/app/[domain]/transcripts/finalSummary.tsx | 2 +- www/app/[domain]/transcripts/recorder.tsx | 13 +++-- www/app/[domain]/transcripts/useWebSockets.ts | 14 +++++- .../[domain]/transcripts/waveformLoading.tsx | 11 ++++ 6 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 www/app/[domain]/transcripts/waveformLoading.tsx diff --git a/www/app/[domain]/transcripts/[transcriptId]/page.tsx b/www/app/[domain]/transcripts/[transcriptId]/page.tsx index add5a824..079b41e8 100644 --- a/www/app/[domain]/transcripts/[transcriptId]/page.tsx +++ b/www/app/[domain]/transcripts/[transcriptId]/page.tsx @@ -13,6 +13,7 @@ import ShareLink from "../shareLink"; import QRCode from "react-qr-code"; import TranscriptTitle from "../transcriptTitle"; import Player from "../player"; +import WaveformLoading from "../waveformLoading"; type TranscriptDetails = { params: { @@ -83,9 +84,9 @@ export default function TranscriptDetails(details: TranscriptDetails) { mediaDuration={transcript.response.duration} /> ) : mp3.error || waveform.error ? ( - "error loading this recording" +
"error loading this recording"
) : ( - "Loading Recording" + )}
@@ -104,10 +105,17 @@ export default function TranscriptDetails(details: TranscriptDetails) { summary={transcript.response.longSummary} transcriptId={transcript.response.id} /> - ) : transcript.response.status == "processing" ? ( - "Loading Transcript" ) : ( - "error final summary" +
+ {transcript.response.status == "processing" ? ( +

Loading Transcript

+ ) : ( +

+ There was an error generating the final summary, please + come back later +

+ )} +
)} diff --git a/www/app/[domain]/transcripts/[transcriptId]/record/page.tsx b/www/app/[domain]/transcripts/[transcriptId]/record/page.tsx index 10297f5c..36f4bbe9 100644 --- a/www/app/[domain]/transcripts/[transcriptId]/record/page.tsx +++ b/www/app/[domain]/transcripts/[transcriptId]/record/page.tsx @@ -11,9 +11,12 @@ import { Topic } from "../../webSocketTypes"; import LiveTrancription from "../../liveTranscription"; import DisconnectedIndicator from "../../disconnectedIndicator"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faGear } from "@fortawesome/free-solid-svg-icons"; +import { faGear, faSpinner } from "@fortawesome/free-solid-svg-icons"; import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock"; import { useRouter } from "next/navigation"; +import Player from "../../player"; +import useMp3 from "../../useMp3"; +import WaveformLoading from "../../waveformLoading"; type TranscriptDetails = { params: { @@ -42,8 +45,10 @@ const TranscriptRecord = (details: TranscriptDetails) => { const { audioDevices, getAudioStream } = useAudioDevice(); - const [hasRecorded, setHasRecorded] = useState(false); + const [recordedTime, setRecordedTime] = useState(0); + const [startTime, setStartTime] = useState(0); const [transcriptStarted, setTranscriptStarted] = useState(false); + const mp3 = useMp3(true, ""); const router = useRouter(); @@ -54,8 +59,6 @@ const TranscriptRecord = (details: TranscriptDetails) => { useEffect(() => { const statusToRedirect = ["ended", "error"]; - console.log(webSockets.status, "hey"); - console.log(transcript.response, "ho"); //TODO if has no topic and is error, get back to new if ( @@ -80,16 +83,31 @@ const TranscriptRecord = (details: TranscriptDetails) => { return ( <> - { - setStream(null); - setHasRecorded(true); - webRTC?.send(JSON.stringify({ cmd: "STOP" })); - }} - getAudioStream={getAudioStream} - audioDevices={audioDevices} - /> + {webSockets.waveform && mp3.media ? ( + + ) : recordedTime ? ( + + ) : ( + { + setStream(null); + setRecordedTime(Date.now() - startTime); + webRTC?.send(JSON.stringify({ cmd: "STOP" })); + }} + onRecord={() => { + setStartTime(Date.now()); + }} + getAudioStream={getAudioStream} + audioDevices={audioDevices} + /> + )}
{
- {!hasRecorded ? ( + {!recordedTime ? ( <> {transcriptStarted && (

Transcription

@@ -135,7 +153,7 @@ const TranscriptRecord = (details: TranscriptDetails) => { couple of minutes. Please do not navigate away from the page during this time.

- {/* TODO If login required remove last sentence */} + {/* NTH If login required remove last sentence */}
)} diff --git a/www/app/[domain]/transcripts/finalSummary.tsx b/www/app/[domain]/transcripts/finalSummary.tsx index 463f6100..e0d0f1c9 100644 --- a/www/app/[domain]/transcripts/finalSummary.tsx +++ b/www/app/[domain]/transcripts/finalSummary.tsx @@ -87,7 +87,7 @@ export default function FinalSummary(props: FinalSummaryProps) {
diff --git a/www/app/[domain]/transcripts/recorder.tsx b/www/app/[domain]/transcripts/recorder.tsx index 5b4420c4..e7c016a7 100644 --- a/www/app/[domain]/transcripts/recorder.tsx +++ b/www/app/[domain]/transcripts/recorder.tsx @@ -14,11 +14,11 @@ import { waveSurferStyles } from "../../styles/recorder"; import { useError } from "../../(errors)/errorContext"; type RecorderProps = { - setStream?: React.Dispatch>; - onStop?: () => void; - getAudioStream?: (deviceId) => Promise; - audioDevices?: Option[]; - mediaDuration?: number | null; + setStream: React.Dispatch>; + onStop: () => void; + onRecord?: () => void; + getAudioStream: (deviceId) => Promise; + audioDevices: Option[]; }; export default function Recorder(props: RecorderProps) { @@ -94,7 +94,6 @@ export default function Recorder(props: RecorderProps) { autoCenter: true, barWidth: 2, height: "auto", - duration: props.mediaDuration || 1, ...waveSurferStyles.player, }); @@ -161,10 +160,10 @@ export default function Recorder(props: RecorderProps) { setScreenMediaStream(null); setDestinationStream(null); } else { + if (props.onRecord) props.onRecord(); const stream = await getCurrentStream(); if (props.setStream) props.setStream(stream); - waveRegions?.clearRegions(); if (stream) { await record.startRecording(stream); setIsRecording(true); diff --git a/www/app/[domain]/transcripts/useWebSockets.ts b/www/app/[domain]/transcripts/useWebSockets.ts index cb74f86d..3f3d20fc 100644 --- a/www/app/[domain]/transcripts/useWebSockets.ts +++ b/www/app/[domain]/transcripts/useWebSockets.ts @@ -1,8 +1,8 @@ import { useContext, useEffect, useState } from "react"; import { Topic, FinalSummary, Status } from "./webSocketTypes"; import { useError } from "../../(errors)/errorContext"; -import { useRouter } from "next/navigation"; import { DomainContext } from "../domainContext"; +import { AudioWaveform } from "../../api"; export type UseWebSockets = { transcriptText: string; @@ -11,6 +11,7 @@ export type UseWebSockets = { topics: Topic[]; finalSummary: FinalSummary; status: Status; + waveform: AudioWaveform | null; }; export const useWebSockets = (transcriptId: string | null): UseWebSockets => { @@ -21,6 +22,7 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => { const [translationQueue, setTranslationQueue] = useState([]); const [isProcessing, setIsProcessing] = useState(false); const [topics, setTopics] = useState([]); + const [waveform, setWaveForm] = useState(null); const [finalSummary, setFinalSummary] = useState({ summary: "", }); @@ -405,5 +407,13 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => { }; }, [transcriptId]); - return { transcriptText, translateText, topics, finalSummary, title, status }; + return { + transcriptText, + translateText, + topics, + finalSummary, + title, + status, + waveform, + }; }; diff --git a/www/app/[domain]/transcripts/waveformLoading.tsx b/www/app/[domain]/transcripts/waveformLoading.tsx new file mode 100644 index 00000000..68e0c80f --- /dev/null +++ b/www/app/[domain]/transcripts/waveformLoading.tsx @@ -0,0 +1,11 @@ +import { faSpinner } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +export default () => ( +
+ +
+);