mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-23 19:37:52 +00:00
change attach download
This commit is contained in:
parent
98785e0571
commit
9af3def127
@ -1567,7 +1567,7 @@ function App() {
|
|||||||
showTutorial('qapps', true)
|
showTutorial('qapps', true)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
showTutorial('create-account', true)
|
showTutorial('getting-started', true)
|
||||||
|
|
||||||
}
|
}
|
||||||
}} >
|
}} >
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import React, { useCallback } from 'react';
|
import React, { useCallback, useRef } from 'react';
|
||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
import { resourceDownloadControllerAtom } from '../atoms/global';
|
import { resourceDownloadControllerAtom } from '../atoms/global';
|
||||||
import { getBaseApiReact } from '../App';
|
import { getBaseApiReact } from '../App';
|
||||||
|
|
||||||
export const useFetchResources = () => {
|
export const useFetchResources = () => {
|
||||||
const [resources, setResources] = useRecoilState(resourceDownloadControllerAtom);
|
const [resources, setResources] = useRecoilState(resourceDownloadControllerAtom);
|
||||||
|
const intervalId = useRef(null)
|
||||||
|
|
||||||
const downloadResource = useCallback(({ service, name, identifier }, build) => {
|
const downloadResource = useCallback(({ service, name, identifier }, build) => {
|
||||||
setResources((prev) => ({
|
setResources((prev) => ({
|
||||||
@ -21,9 +22,11 @@ export const useFetchResources = () => {
|
|||||||
let isCalling = false;
|
let isCalling = false;
|
||||||
let percentLoaded = 0;
|
let percentLoaded = 0;
|
||||||
let timer = 24;
|
let timer = 24;
|
||||||
|
let tries = 26;
|
||||||
let calledFirstTime = false
|
let calledFirstTime = false
|
||||||
|
|
||||||
const intervalId = setInterval(async () => {
|
const callFunction = async ()=> {
|
||||||
|
console.log('calledFirstTime', calledFirstTime)
|
||||||
if (isCalling) return;
|
if (isCalling) return;
|
||||||
isCalling = true;
|
isCalling = true;
|
||||||
|
|
||||||
@ -40,6 +43,22 @@ export const useFetchResources = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
res = await resCall.json()
|
res = await resCall.json()
|
||||||
|
if(tries === 5 && intervalId?.current){
|
||||||
|
clearInterval(intervalId?.current)
|
||||||
|
setResources((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[`${service}-${name}-${identifier}`]: {
|
||||||
|
...(prev[`${service}-${name}-${identifier}`] || {}),
|
||||||
|
status: {
|
||||||
|
...res,
|
||||||
|
status: 'FAILED_TO_DOWNLOAD',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tries = tries + 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,7 +122,7 @@ export const useFetchResources = () => {
|
|||||||
|
|
||||||
// Check if progress is 100% and clear interval if true
|
// Check if progress is 100% and clear interval if true
|
||||||
if (res?.status === 'READY') {
|
if (res?.status === 'READY') {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId.current);
|
||||||
|
|
||||||
// Update Recoil state for completion
|
// Update Recoil state for completion
|
||||||
setResources((prev) => ({
|
setResources((prev) => ({
|
||||||
@ -114,7 +133,12 @@ export const useFetchResources = () => {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}, !calledFirstTime ? 100 :5000);
|
}
|
||||||
|
callFunction()
|
||||||
|
intervalId.current = setInterval(async () => {
|
||||||
|
callFunction()
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error during resource fetch:', error);
|
console.error('Error during resource fetch:', error);
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ export const AttachmentCard = ({
|
|||||||
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{resourceDetails && resourceDetails?.status?.status !== 'READY' && (
|
{resourceDetails && resourceDetails?.status?.status !== 'READY' && resourceDetails?.status?.status !== 'FAILED_TO_DOWNLOAD' && (
|
||||||
<>
|
<>
|
||||||
<CircularProgress sx={{
|
<CircularProgress sx={{
|
||||||
color: 'white'
|
color: 'white'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user