From 5525c4b4ad55bc9e9cde726c1b3eebaaf9163df1 Mon Sep 17 00:00:00 2001 From: RobinB27 Date: Mon, 17 Nov 2025 08:04:46 +0100 Subject: [PATCH] [Task 3] Loading Spinner --- task_3_react/src/client/App.tsx | 11 +++++++++-- task_3_react/src/client/components/DataTable.tsx | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/task_3_react/src/client/App.tsx b/task_3_react/src/client/App.tsx index 5508782..9fa0715 100644 --- a/task_3_react/src/client/App.tsx +++ b/task_3_react/src/client/App.tsx @@ -36,6 +36,9 @@ function App () { setFileList ] = useState( null as responseObject | null ); + // For the loading spinner in DataTable + const [loading, setLoading] = useState(false); + // Add evenbt listener for server-sent events on first render const [active, setActive] = useState(false); @@ -72,6 +75,7 @@ function App () { // This is triggered in CSVCard const handleFileUpload = async ( e: React.ChangeEvent ): Promise => { + setLoading(true) const file = e.target.files?.[0]; if ( !file ) throw new Error( 'No file received' ); @@ -86,6 +90,7 @@ function App () { setInfo( newFileInfo ); setData( data ); + setLoading(false); if ( formRef.current ) { // Upload to server @@ -99,6 +104,8 @@ function App () { }; const handleFileChange = async ( fileName: string ) => { + setLoading(true) + const response = await fetch( `/download/${ fileName }` ); const blob = await response.blob(); const text = await blob.text(); @@ -108,7 +115,7 @@ function App () { const data = await convertCSVtoJSON( text ); // Updating fileInfo requires more effort since blob doesn't have the metadata - + setLoading(false); setData( data ); }; @@ -117,7 +124,7 @@ function App () { - + ); } diff --git a/task_3_react/src/client/components/DataTable.tsx b/task_3_react/src/client/components/DataTable.tsx index 813033c..665a3a2 100644 --- a/task_3_react/src/client/components/DataTable.tsx +++ b/task_3_react/src/client/components/DataTable.tsx @@ -6,7 +6,8 @@ import { } from '../types'; const DataTable = ( props: { - 'data': CSV_Data + 'data': CSV_Data, + 'loading': boolean } ) => { if ( props.data.length == 0 ) return <>; @@ -52,7 +53,7 @@ const DataTable = ( props: { return (
-
+

Data table