diff --git a/client/src/Pages/PreviewPage.tsx b/client/src/Pages/PreviewPage.tsx index 545c0b7..8c8bfe7 100644 --- a/client/src/Pages/PreviewPage.tsx +++ b/client/src/Pages/PreviewPage.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; import { Typography, Container, @@ -20,7 +21,8 @@ function PreviewPage() { const [isPlaying, setIsPlaying] = useState(false); const [error, setError] = useState(false); const videoRef = useRef(null); - + const location = useLocation(); + const { audioClass } = location.state || {} // Supported video formats const supportedFormats = ['video/mp4', 'video/webm', 'video/ogg']; const isVideo = mediaFile && supportedFormats.includes(mediaFile.type); @@ -46,6 +48,7 @@ function PreviewPage() { return ( +

Audio Classification: {audioClass || "No data received"}

@@ -129,7 +132,7 @@ function PreviewPage() { diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index 0e9392b..19f9137 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from "react"; -import { useNavigate } from "react-router-dom"; +import { useNavigate,useLocation } from "react-router-dom"; import { Typography, Container, Paper, Box, LinearProgress } from "@mui/material"; import StepperComponent from "../components/StepperComponent"; import { useMediaContext } from "../contexts/MediaContext"; @@ -35,6 +35,8 @@ function ProcessingPage() { console.error(`Error in step: ${url}`, error); } }; + const location = useLocation(); + const { audioClass } = location.state || {}; useEffect(() => { if (!mediaFile) { @@ -59,7 +61,9 @@ function ProcessingPage() { useEffect(() => { if (progress === 100) { - navigate("/results"); + + navigate('/results', { state: { audioClass}}) + } }, [progress]); diff --git a/client/src/Pages/ResultsPage.tsx b/client/src/Pages/ResultsPage.tsx index 46b4fb1..5d3b195 100644 --- a/client/src/Pages/ResultsPage.tsx +++ b/client/src/Pages/ResultsPage.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useRef } from 'react'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import axios from 'axios'; import { Typography, @@ -23,45 +23,12 @@ import { useMediaContext } from '../contexts/MediaContext'; function ResultsPage() { const navigate = useNavigate(); const theme = useTheme(); - const { mediaFile, clearMedia,response } = useMediaContext(); + const { mediaFile, clearMedia, response } = useMediaContext(); const [isPlaying, setIsPlaying] = useState(false); - const videoRef = useRef(null); - - const processDownload = async() => { - try { - console.log('download started..') - const res = await axios.get("http://127.0.0.1:8000/api/download", { - params: { file_uuid: response.file_uuid }, // Attach file_uuid as a query param - responseType: "blob", // Treat response as a file - }); - - if (res.status === 200) { - const blob = new Blob([res.data]); - const url = window.URL.createObjectURL(blob); - - // Extract filename from headers or use default - const contentDisposition = res.headers["content-disposition"]; - const filename = contentDisposition - ? contentDisposition.split("filename=")[1] - : "downloaded_file"; - - // Auto-download the file (no user interaction needed) - const link = document.createElement("a"); - link.href = url; - link.setAttribute("download", filename); - document.body.appendChild(link); - link.click(); - - // Cleanup - document.body.removeChild(link); - window.URL.revokeObjectURL(url); - } else { - console.error("Download failed, server responded with:", res); - } - } catch (error) { - console.error("Download error:", error); - } - }; + const audioRefs = [useRef(null), useRef(null), useRef(null),useRef(null)]; + const location = useLocation(); + const { audioClass } = location.state || {}; + const isVideo = mediaFile?.type.includes('video'); useEffect(() => { if (!mediaFile) { @@ -69,26 +36,19 @@ function ResultsPage() { } }, [mediaFile, navigate]); - const togglePlay = () => { - if (videoRef.current) { + const togglePlay = (index) => { + if (audioRefs[index].current) { if (isPlaying) { - videoRef.current.pause(); + audioRefs[index].current.pause(); } else { - videoRef.current.play(); + audioRefs[index].current.play(); } setIsPlaying(!isPlaying); } }; - const handleProcessAnother = () => { - clearMedia(); - navigate('/upload'); - }; - if (!mediaFile) return ; - const isVideo = mediaFile.type.includes('video'); - return ( @@ -107,50 +67,38 @@ function ResultsPage() { {isVideo ? ( - - +