From 43016e42aa0fe2d37d230c497173074760366f5b Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Thu, 12 Oct 2023 11:31:11 +0200 Subject: [PATCH] www: add shallow redirection on the final transcript url This prevent the user waiting for the final generation of the summary to have the final url It still redirect nextjs internally when final transcript is received. --- www/app/transcripts/new/page.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/www/app/transcripts/new/page.tsx b/www/app/transcripts/new/page.tsx index 89794005..b4e294d6 100644 --- a/www/app/transcripts/new/page.tsx +++ b/www/app/transcripts/new/page.tsx @@ -16,6 +16,7 @@ import { faGear } from "@fortawesome/free-solid-svg-icons"; import About from "../../(aboutAndPrivacy)/about"; import Privacy from "../../(aboutAndPrivacy)/privacy"; import { lockWakeState, releaseWakeState } from "../../lib/wakeLock"; +import { useRouter } from "next/navigation"; const TranscriptCreate = () => { const [stream, setStream] = useState(null); @@ -36,6 +37,7 @@ const TranscriptCreate = () => { const transcript = useTranscript(stream, api); const webRTC = useWebRTC(stream, transcript?.response?.id, api); const webSockets = useWebSockets(transcript?.response?.id); + const router = useRouter(); const { loading, permissionOk, @@ -53,6 +55,17 @@ const TranscriptCreate = () => { setTranscriptStarted(true); }, [webSockets.transcriptText]); + useEffect(() => { + if (transcript?.response?.id) { + const newUrl = `/transcripts/${transcript.response.id}`; + // Shallow redirection does not work on NextJS 13 + // https://github.com/vercel/next.js/discussions/48110 + // https://github.com/vercel/next.js/discussions/49540 + // router.push(newUrl, undefined, { shallow: true }); + history.replaceState({}, "", newUrl); + } + }); + useEffect(() => { lockWakeState(); return () => {