mirror of
https://github.com/janishutz/fundamentals-of-webengineering.git
synced 2025-11-25 13:54:25 +00:00
[Task 3] Loading Spinner
This commit is contained in:
@@ -36,6 +36,9 @@ function App () {
|
|||||||
setFileList
|
setFileList
|
||||||
] = useState( null as responseObject | null );
|
] = 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
|
// Add evenbt listener for server-sent events on first render
|
||||||
const [active, setActive] = useState(false);
|
const [active, setActive] = useState(false);
|
||||||
|
|
||||||
@@ -72,6 +75,7 @@ function App () {
|
|||||||
|
|
||||||
// This is triggered in CSVCard
|
// This is triggered in CSVCard
|
||||||
const handleFileUpload = async ( e: React.ChangeEvent<HTMLInputElement> ): Promise<void> => {
|
const handleFileUpload = async ( e: React.ChangeEvent<HTMLInputElement> ): Promise<void> => {
|
||||||
|
setLoading(true)
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
|
|
||||||
if ( !file ) throw new Error( 'No file received' );
|
if ( !file ) throw new Error( 'No file received' );
|
||||||
@@ -86,6 +90,7 @@ function App () {
|
|||||||
|
|
||||||
setInfo( newFileInfo );
|
setInfo( newFileInfo );
|
||||||
setData( data );
|
setData( data );
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
if ( formRef.current ) {
|
if ( formRef.current ) {
|
||||||
// Upload to server
|
// Upload to server
|
||||||
@@ -99,6 +104,8 @@ function App () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleFileChange = async ( fileName: string ) => {
|
const handleFileChange = async ( fileName: string ) => {
|
||||||
|
setLoading(true)
|
||||||
|
|
||||||
const response = await fetch( `/download/${ fileName }` );
|
const response = await fetch( `/download/${ fileName }` );
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
const text = await blob.text();
|
const text = await blob.text();
|
||||||
@@ -108,7 +115,7 @@ function App () {
|
|||||||
const data = await convertCSVtoJSON( text );
|
const data = await convertCSVtoJSON( text );
|
||||||
|
|
||||||
// Updating fileInfo requires more effort since blob doesn't have the metadata
|
// Updating fileInfo requires more effort since blob doesn't have the metadata
|
||||||
|
setLoading(false);
|
||||||
setData( data );
|
setData( data );
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,7 +124,7 @@ function App () {
|
|||||||
<CSVCard handleChange={handleFileUpload} formRef={formRef}></CSVCard>
|
<CSVCard handleChange={handleFileUpload} formRef={formRef}></CSVCard>
|
||||||
<FileCard fileList={fileList as responseObject} fileChangeHandle={handleFileChange}></FileCard>
|
<FileCard fileList={fileList as responseObject} fileChangeHandle={handleFileChange}></FileCard>
|
||||||
<InfoCard info={info}></InfoCard>
|
<InfoCard info={info}></InfoCard>
|
||||||
<DataTable data={data}></DataTable>
|
<DataTable data={data} loading={loading}></DataTable>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
const DataTable = ( props: {
|
const DataTable = ( props: {
|
||||||
'data': CSV_Data
|
'data': CSV_Data,
|
||||||
|
'loading': boolean
|
||||||
} ) => {
|
} ) => {
|
||||||
if ( props.data.length == 0 ) return <></>;
|
if ( props.data.length == 0 ) return <></>;
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ const DataTable = ( props: {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<article className="table-container">
|
<article className="table-container">
|
||||||
<header>
|
<header aria-busy={props.loading}>
|
||||||
<h2>Data table</h2>
|
<h2>Data table</h2>
|
||||||
</header>
|
</header>
|
||||||
<div className="table-scroll-wrapper">
|
<div className="table-scroll-wrapper">
|
||||||
|
|||||||
Reference in New Issue
Block a user