From 02ecb3fad116a6f39bdfb2310d0774e64162a821 Mon Sep 17 00:00:00 2001 From: Thomas L Fagermyr Date: Fri, 7 Feb 2025 10:38:37 +0100 Subject: [PATCH] feat: Added loading icon while waiting for download response --- .../ModelFilesView/ModelFilesView.tsx | 75 ++++++++++++++----- src/hooks/useFetchFile.tsx | 2 +- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/features/ModelView/ModelFilesView/ModelFilesView.tsx b/src/features/ModelView/ModelFilesView/ModelFilesView.tsx index 36527c8..817680f 100644 --- a/src/features/ModelView/ModelFilesView/ModelFilesView.tsx +++ b/src/features/ModelView/ModelFilesView/ModelFilesView.tsx @@ -1,5 +1,5 @@ /* eslint-disable max-lines-per-function */ -import { Table, Typography } from '@equinor/eds-core-react'; +import { CircularProgress, Table, Typography } from '@equinor/eds-core-react'; import { UploadFileType, UploadList } from '../../../api/generated'; import * as Styled from './ModelFilesView.styled'; import { @@ -13,27 +13,75 @@ import { getFetchNcFileAxios, getFetchResqmlFileAxios, } from '../../../hooks/useFetchFile'; +import { useState } from 'react'; export const ModelFilesView = () => { const { analogueModel } = usePepmContextStore(); + const [isLoadingNc, setIsLoadingNc] = useState(false); + const [isLoadingIni, setIsLoadingIni] = useState(false); + const [isLoadingResqml, setIsLoadingResqml] = useState(false); if (analogueModel === analogueModelDefault) return

Loading ...

; - const downloadFile = (fileType: UploadFileType) => { + const downloadFile = async (fileType: UploadFileType) => { switch (fileType) { case UploadFileType.NET_CDF: - getFetchNcFileAxios(analogueModel); + setIsLoadingNc(true); + await getFetchNcFileAxios(analogueModel); + setIsLoadingNc(false); break; case UploadFileType.INI_DATA: - getFetchIniFileAxios(analogueModel); + setIsLoadingIni(true); + await getFetchIniFileAxios(analogueModel); + setIsLoadingIni(false); break; case UploadFileType.RES_QMLDATA: - getFetchResqmlFileAxios(analogueModel); + setIsLoadingResqml(true); + await getFetchResqmlFileAxios(analogueModel); + setIsLoadingResqml(false); break; } return; }; + const iconButtons = (fileType: UploadFileType) => { + if (isLoadingNc && fileType === UploadFileType.NET_CDF) + return ( + + ); + if (isLoadingIni && fileType === UploadFileType.INI_DATA) + return ( + + ); + if (isLoadingResqml && fileType === UploadFileType.RES_QMLDATA) + return ( + + ); + + return ( + downloadFile(fileType)} + /> + ); + }; + return ( @@ -55,13 +103,7 @@ export const ModelFilesView = () => { {file.originalFileName} - - - downloadFile(file.uploadFileType)} - /> - + {iconButtons(file.uploadFileType)} )) ) : ( @@ -75,14 +117,7 @@ export const ModelFilesView = () => { Resqml.zip - - - {' '} - downloadFile(UploadFileType.RES_QMLDATA)} - /> - + {iconButtons(UploadFileType.RES_QMLDATA)} ) : ( <> diff --git a/src/hooks/useFetchFile.tsx b/src/hooks/useFetchFile.tsx index 45908a4..40c5e0d 100644 --- a/src/hooks/useFetchFile.tsx +++ b/src/hooks/useFetchFile.tsx @@ -75,7 +75,7 @@ export const getFetchNcFileAxios = async ( export const getFetchResqmlFileAxios = async ( analogueModel: AnalogueModelDetail, -): Promise => { +) => { const token = OpenAPI.TOKEN; // replace with your bearer token const base = OpenAPI.BASE;