feat: loader
This commit is contained in:
parent
d7cc0d20a1
commit
bbedccd5a9
|
|
@ -13,6 +13,7 @@ import clsx from 'clsx';
|
||||||
import interClass from '@gitroom/react/helpers/inter.font';
|
import interClass from '@gitroom/react/helpers/inter.font';
|
||||||
import { VideoFrame } from '@gitroom/react/helpers/video.frame';
|
import { VideoFrame } from '@gitroom/react/helpers/video.frame';
|
||||||
import { useToaster } from '@gitroom/react/toaster/toaster';
|
import { useToaster } from '@gitroom/react/toaster/toaster';
|
||||||
|
import { LoadingComponent } from '@gitroom/frontend/components/layout/loading';
|
||||||
const showModalEmitter = new EventEmitter();
|
const showModalEmitter = new EventEmitter();
|
||||||
|
|
||||||
export const ShowMediaBoxModal: FC = () => {
|
export const ShowMediaBoxModal: FC = () => {
|
||||||
|
|
@ -60,6 +61,7 @@ export const MediaBox: FC<{
|
||||||
const fetch = useFetch();
|
const fetch = useFetch();
|
||||||
const mediaDirectory = useMediaDirectory();
|
const mediaDirectory = useMediaDirectory();
|
||||||
const toaster = useToaster();
|
const toaster = useToaster();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const loadMedia = useCallback(async () => {
|
const loadMedia = useCallback(async () => {
|
||||||
return (await fetch('/media')).json();
|
return (await fetch('/media')).json();
|
||||||
|
|
@ -76,18 +78,22 @@ export const MediaBox: FC<{
|
||||||
!file?.target?.files?.length ||
|
!file?.target?.files?.length ||
|
||||||
file?.target?.files?.[0]?.size > maxFileSize
|
file?.target?.files?.[0]?.size > maxFileSize
|
||||||
) {
|
) {
|
||||||
toaster.show(`Maximum file size ${maxFileSize / 1024 / 1024}mb`, 'warning');
|
toaster.show(
|
||||||
|
`Maximum file size ${maxFileSize / 1024 / 1024}mb`,
|
||||||
|
'warning'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file?.target?.files?.[0]);
|
formData.append('file', file?.target?.files?.[0]);
|
||||||
|
setLoading(true);
|
||||||
const data = await (
|
const data = await (
|
||||||
await fetch('/media', {
|
await fetch('/media', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
).json();
|
).json();
|
||||||
|
setLoading(false);
|
||||||
setListMedia([...mediaList, data]);
|
setListMedia([...mediaList, data]);
|
||||||
},
|
},
|
||||||
[mediaList]
|
[mediaList]
|
||||||
|
|
@ -247,6 +253,13 @@ export const MediaBox: FC<{
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
{loading && (
|
||||||
|
<div className="w-[200px] h-[200px] flex border-tableBorder border-2 cursor-pointer relative">
|
||||||
|
<div className="absolute left-0 top-0 w-full h-full -mt-[50px] flex justify-center items-center">
|
||||||
|
<LoadingComponent />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue