Skip to content

Commit

Permalink
Revert "fix: remove progress bar in toast"
Browse files Browse the repository at this point in the history
This reverts commit 6755deb.
  • Loading branch information
trobonox committed Aug 14, 2023
1 parent 6755deb commit c4a7103
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/files.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { auth } from "@/stores/auth";
import type { UploadedFile } from "@/types/api";
import { createSignal } from "solid-js";
import toast from "solid-toast";

export const createFileImporter = (onFileUploaded: (files: FileList) => unknown) => {
Expand Down Expand Up @@ -79,6 +80,8 @@ export const getUploadedFileURL = (file: UploadedFile) => {
return url;
};

const [downloadProgress, setDownloadProgress] = createSignal(0);

export const downloadUploadedFile = (file: UploadedFile) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/api/file/" + file.id, true);
Expand All @@ -89,7 +92,8 @@ export const downloadUploadedFile = (file: UploadedFile) => {
toast.custom(() => (
<div
class="relative flex flex-col gap-2 rounded-md bg-base px-6 py-3 pr-12 font-medium text-text shadow-md">
Downloading your file, please wait...
Downloading... {downloadProgress()}%
<progress value={downloadProgress()} max={100} class="bg-lavender" />
</div>
), {
unmountDelay: 0
Expand Down Expand Up @@ -117,6 +121,7 @@ export const downloadUploadedFile = (file: UploadedFile) => {
xhr.onprogress = (event) => {
if (event.lengthComputable) {
console.info(file.name, `${event.loaded}/${event.total} (${event.loaded * 100 / event.total}%)`);
setDownloadProgress(Math.floor(event.loaded * 100 / event.total));

if (event.loaded === 1) {
toast.dismiss();
Expand Down

0 comments on commit c4a7103

Please sign in to comment.