mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
fix: add proccessing page to file upload and reprocessing (#650)
This commit is contained in:
@@ -10,7 +10,15 @@ import FinalSummary from "./finalSummary";
|
|||||||
import TranscriptTitle from "../transcriptTitle";
|
import TranscriptTitle from "../transcriptTitle";
|
||||||
import Player from "../player";
|
import Player from "../player";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Box, Flex, Grid, GridItem, Skeleton, Text } from "@chakra-ui/react";
|
import {
|
||||||
|
Box,
|
||||||
|
Flex,
|
||||||
|
Grid,
|
||||||
|
GridItem,
|
||||||
|
Skeleton,
|
||||||
|
Text,
|
||||||
|
Spinner,
|
||||||
|
} from "@chakra-ui/react";
|
||||||
import { useTranscriptGet } from "../../../lib/apiHooks";
|
import { useTranscriptGet } from "../../../lib/apiHooks";
|
||||||
import { TranscriptStatus } from "../../../lib/transcript";
|
import { TranscriptStatus } from "../../../lib/transcript";
|
||||||
|
|
||||||
@@ -28,6 +36,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
"idle",
|
"idle",
|
||||||
"recording",
|
"recording",
|
||||||
"processing",
|
"processing",
|
||||||
|
"uploaded",
|
||||||
] satisfies TranscriptStatus[] as TranscriptStatus[];
|
] satisfies TranscriptStatus[] as TranscriptStatus[];
|
||||||
|
|
||||||
const transcript = useTranscriptGet(transcriptId);
|
const transcript = useTranscriptGet(transcriptId);
|
||||||
@@ -45,15 +54,55 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
useState<HTMLDivElement | null>(null);
|
useState<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (waiting) {
|
if (!waiting || !transcript.data) return;
|
||||||
const newUrl = "/transcripts/" + params.transcriptId + "/record";
|
|
||||||
|
const status = transcript.data.status;
|
||||||
|
let newUrl: string | null = null;
|
||||||
|
|
||||||
|
if (status === "processing" || status === "uploaded") {
|
||||||
|
newUrl = `/transcripts/${params.transcriptId}/processing`;
|
||||||
|
} else if (status === "recording") {
|
||||||
|
newUrl = `/transcripts/${params.transcriptId}/record`;
|
||||||
|
} else if (status === "idle") {
|
||||||
|
newUrl =
|
||||||
|
transcript.data.source_kind === "file"
|
||||||
|
? `/transcripts/${params.transcriptId}/upload`
|
||||||
|
: `/transcripts/${params.transcriptId}/record`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newUrl) {
|
||||||
// Shallow redirection does not work on NextJS 13
|
// Shallow redirection does not work on NextJS 13
|
||||||
// https://github.com/vercel/next.js/discussions/48110
|
// https://github.com/vercel/next.js/discussions/48110
|
||||||
// https://github.com/vercel/next.js/discussions/49540
|
// https://github.com/vercel/next.js/discussions/49540
|
||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
// history.replaceState({}, "", newUrl);
|
|
||||||
}
|
}
|
||||||
}, [waiting]);
|
}, [waiting, transcript.data?.status, transcript.data?.source_kind]);
|
||||||
|
|
||||||
|
if (waiting) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box
|
||||||
|
w="full"
|
||||||
|
background="gray.bg"
|
||||||
|
border={"2px solid"}
|
||||||
|
borderColor={"gray.bg"}
|
||||||
|
borderRadius={8}
|
||||||
|
p={6}
|
||||||
|
minH="100%"
|
||||||
|
display="flex"
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="center"
|
||||||
|
>
|
||||||
|
<Flex direction="column" align="center" gap={3}>
|
||||||
|
<Spinner size="xl" color="blue.500" />
|
||||||
|
<Text color="gray.600" textAlign="center">
|
||||||
|
Loading transcript...
|
||||||
|
</Text>
|
||||||
|
</Flex>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (transcript.error || topics?.error) {
|
if (transcript.error || topics?.error) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
97
www/app/(app)/transcripts/[transcriptId]/processing/page.tsx
Normal file
97
www/app/(app)/transcripts/[transcriptId]/processing/page.tsx
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
"use client";
|
||||||
|
import { useEffect, use } from "react";
|
||||||
|
import {
|
||||||
|
Heading,
|
||||||
|
Text,
|
||||||
|
VStack,
|
||||||
|
Spinner,
|
||||||
|
Button,
|
||||||
|
Center,
|
||||||
|
} from "@chakra-ui/react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useTranscriptGet } from "../../../../lib/apiHooks";
|
||||||
|
|
||||||
|
type TranscriptProcessing = {
|
||||||
|
params: Promise<{
|
||||||
|
transcriptId: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function TranscriptProcessing(details: TranscriptProcessing) {
|
||||||
|
const params = use(details.params);
|
||||||
|
const transcriptId = params.transcriptId;
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const transcript = useTranscriptGet(transcriptId);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const status = transcript.data?.status;
|
||||||
|
if (!status) return;
|
||||||
|
|
||||||
|
if (status === "ended" || status === "error") {
|
||||||
|
router.replace(`/transcripts/${transcriptId}`);
|
||||||
|
} else if (status === "recording") {
|
||||||
|
router.replace(`/transcripts/${transcriptId}/record`);
|
||||||
|
} else if (status === "idle") {
|
||||||
|
const dest =
|
||||||
|
transcript.data?.source_kind === "file"
|
||||||
|
? `/transcripts/${transcriptId}/upload`
|
||||||
|
: `/transcripts/${transcriptId}/record`;
|
||||||
|
router.replace(dest);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
transcript.data?.status,
|
||||||
|
transcript.data?.source_kind,
|
||||||
|
router,
|
||||||
|
transcriptId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (transcript.isLoading) {
|
||||||
|
return (
|
||||||
|
<VStack align="center" py={8}>
|
||||||
|
<Heading size="lg">Loading transcript...</Heading>
|
||||||
|
</VStack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transcript.error) {
|
||||||
|
return (
|
||||||
|
<VStack align="center" py={8}>
|
||||||
|
<Heading size="lg">Transcript not found</Heading>
|
||||||
|
<Text>We couldn't load this transcript.</Text>
|
||||||
|
</VStack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<VStack
|
||||||
|
align={"left"}
|
||||||
|
minH="100vh"
|
||||||
|
pt={4}
|
||||||
|
mx="auto"
|
||||||
|
w={{ base: "full", md: "container.xl" }}
|
||||||
|
>
|
||||||
|
<Center h={"full"} w="full">
|
||||||
|
<VStack gap={10} bg="gray.100" p={10} borderRadius="md" maxW="500px">
|
||||||
|
<Spinner size="xl" color="blue.500" />
|
||||||
|
<Heading size={"md"} textAlign="center">
|
||||||
|
Processing recording
|
||||||
|
</Heading>
|
||||||
|
<Text color="gray.600" textAlign="center">
|
||||||
|
You can safely return to the library while your recording is being
|
||||||
|
processed.
|
||||||
|
</Text>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
router.push("/browse");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Browse
|
||||||
|
</Button>
|
||||||
|
</VStack>
|
||||||
|
</Center>
|
||||||
|
</VStack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import { useWebSockets } from "../../useWebSockets";
|
|||||||
import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock";
|
import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import useMp3 from "../../useMp3";
|
import useMp3 from "../../useMp3";
|
||||||
import { Center, VStack, Text, Heading, Button } from "@chakra-ui/react";
|
import { Center, VStack, Text, Heading } from "@chakra-ui/react";
|
||||||
import FileUploadButton from "../../fileUploadButton";
|
import FileUploadButton from "../../fileUploadButton";
|
||||||
import { useTranscriptGet } from "../../../../lib/apiHooks";
|
import { useTranscriptGet } from "../../../../lib/apiHooks";
|
||||||
|
|
||||||
@@ -53,6 +53,12 @@ const TranscriptUpload = (details: TranscriptUpload) => {
|
|||||||
|
|
||||||
const newUrl = "/transcripts/" + params.transcriptId;
|
const newUrl = "/transcripts/" + params.transcriptId;
|
||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
|
} else if (
|
||||||
|
newStatus &&
|
||||||
|
(newStatus == "uploaded" || newStatus == "processing")
|
||||||
|
) {
|
||||||
|
// After upload finishes (or if already processing), redirect to the unified processing page
|
||||||
|
router.replace(`/transcripts/${params.transcriptId}/processing`);
|
||||||
}
|
}
|
||||||
}, [webSockets.status?.value, transcript.data?.status]);
|
}, [webSockets.status?.value, transcript.data?.status]);
|
||||||
|
|
||||||
@@ -71,7 +77,7 @@ const TranscriptUpload = (details: TranscriptUpload) => {
|
|||||||
<>
|
<>
|
||||||
<VStack
|
<VStack
|
||||||
align={"left"}
|
align={"left"}
|
||||||
h="full"
|
minH="100vh"
|
||||||
pt={4}
|
pt={4}
|
||||||
mx="auto"
|
mx="auto"
|
||||||
w={{ base: "full", md: "container.xl" }}
|
w={{ base: "full", md: "container.xl" }}
|
||||||
@@ -79,34 +85,16 @@ const TranscriptUpload = (details: TranscriptUpload) => {
|
|||||||
<Heading size={"lg"}>Upload meeting</Heading>
|
<Heading size={"lg"}>Upload meeting</Heading>
|
||||||
<Center h={"full"} w="full">
|
<Center h={"full"} w="full">
|
||||||
<VStack gap={10} bg="gray.100" p={10} borderRadius="md" maxW="500px">
|
<VStack gap={10} bg="gray.100" p={10} borderRadius="md" maxW="500px">
|
||||||
{status && status == "idle" && (
|
|
||||||
<>
|
|
||||||
<Text>
|
<Text>
|
||||||
Please select the file, supported formats: .mp3, m4a, .wav,
|
Please select the file, supported formats: .mp3, m4a, .wav, .mp4,
|
||||||
.mp4, .mov or .webm
|
.mov or .webm
|
||||||
</Text>
|
</Text>
|
||||||
<FileUploadButton transcriptId={params.transcriptId} />
|
<FileUploadButton
|
||||||
</>
|
transcriptId={params.transcriptId}
|
||||||
)}
|
onUploadComplete={() =>
|
||||||
{status && status == "uploaded" && (
|
router.replace(`/transcripts/${params.transcriptId}/processing`)
|
||||||
<Text>File is uploaded, processing...</Text>
|
}
|
||||||
)}
|
/>
|
||||||
{(status == "recording" || status == "processing") && (
|
|
||||||
<>
|
|
||||||
<Heading size={"lg"}>Processing your recording...</Heading>
|
|
||||||
<Text>
|
|
||||||
You can safely return to the library while your file is being
|
|
||||||
processed.
|
|
||||||
</Text>
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
router.push("/browse");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Browse
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</VStack>
|
</VStack>
|
||||||
</Center>
|
</Center>
|
||||||
</VStack>
|
</VStack>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useError } from "../../(errors)/errorContext";
|
|||||||
|
|
||||||
type FileUploadButton = {
|
type FileUploadButton = {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
|
onUploadComplete?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function FileUploadButton(props: FileUploadButton) {
|
export default function FileUploadButton(props: FileUploadButton) {
|
||||||
@@ -31,6 +32,7 @@ export default function FileUploadButton(props: FileUploadButton) {
|
|||||||
const uploadNextChunk = async () => {
|
const uploadNextChunk = async () => {
|
||||||
if (chunkNumber == totalChunks) {
|
if (chunkNumber == totalChunks) {
|
||||||
setProgress(0);
|
setProgress(0);
|
||||||
|
props.onUploadComplete?.();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user