mirror of
https://github.com/arc53/DocsGPT.git
synced 2026-04-28 13:00:30 +00:00
chore: slight delay between uploading and learning progress transition
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useDropzone } from 'react-dropzone';
|
import { useDropzone } from 'react-dropzone';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
@@ -35,6 +35,7 @@ function Upload({
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const setTimeoutRef = useRef<number | null>();
|
||||||
|
|
||||||
const urlOptions: { label: string; value: string }[] = [
|
const urlOptions: { label: string; value: string }[] = [
|
||||||
{ label: 'Crawler', value: 'crawler' },
|
{ label: 'Crawler', value: 'crawler' },
|
||||||
@@ -48,6 +49,12 @@ function Upload({
|
|||||||
value: 'url',
|
value: 'url',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (setTimeoutRef.current) {
|
||||||
|
clearTimeout(setTimeoutRef.current);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
function ProgressBar({ progress }: { progress: number }) {
|
function ProgressBar({ progress }: { progress: number }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-5 w-[50%]">
|
<div className="my-5 w-[50%]">
|
||||||
@@ -63,7 +70,6 @@ function Upload({
|
|||||||
{progress >= 5 && `${progress}%`}
|
{progress >= 5 && `${progress}%`}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="h-1 w-[100%] bg-purple-30"></div> */}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -209,7 +215,9 @@ function Upload({
|
|||||||
});
|
});
|
||||||
xhr.onload = () => {
|
xhr.onload = () => {
|
||||||
const { task_id } = JSON.parse(xhr.responseText);
|
const { task_id } = JSON.parse(xhr.responseText);
|
||||||
setProgress({ type: 'TRAINIING', percentage: 0, taskId: task_id });
|
setTimeoutRef.current = setTimeout(() => {
|
||||||
|
setProgress({ type: 'TRAINIING', percentage: 0, taskId: task_id });
|
||||||
|
}, 2000);
|
||||||
};
|
};
|
||||||
xhr.open('POST', `${apiHost + '/api/upload'}`);
|
xhr.open('POST', `${apiHost + '/api/upload'}`);
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
@@ -238,7 +246,9 @@ function Upload({
|
|||||||
});
|
});
|
||||||
xhr.onload = () => {
|
xhr.onload = () => {
|
||||||
const { task_id } = JSON.parse(xhr.responseText);
|
const { task_id } = JSON.parse(xhr.responseText);
|
||||||
setProgress({ type: 'TRAINIING', percentage: 0, taskId: task_id });
|
setTimeoutRef.current = setTimeout(() => {
|
||||||
|
setProgress({ type: 'TRAINIING', percentage: 0, taskId: task_id });
|
||||||
|
}, 2000);
|
||||||
};
|
};
|
||||||
xhr.open('POST', `${apiHost + '/api/remote'}`);
|
xhr.open('POST', `${apiHost + '/api/remote'}`);
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
|
|||||||
Reference in New Issue
Block a user