From 6dc87e3354efe09cfc4f0124441603cb81270b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Fri, 18 Nov 2022 13:53:32 -0300 Subject: [PATCH] Add rejected files list --- src/lib/Dropzone.svelte | 4 +-- src/lib/FileList.svelte | 14 ++++++++-- src/lib/FileViewer.svelte | 42 ++++++++++++++++------------- src/utils/filterFileRequirements.js | 20 ++++++++++++++ 4 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 src/utils/filterFileRequirements.js diff --git a/src/lib/Dropzone.svelte b/src/lib/Dropzone.svelte index c9afc82..2dfc6e3 100644 --- a/src/lib/Dropzone.svelte +++ b/src/lib/Dropzone.svelte @@ -1,6 +1,6 @@ {#if files.length !== 0}
-

Selected files:

+

{title}:

{#each Array.from(files) as file} -
+

{file.name} ({file.size / 1000} kb)

{/each} @@ -21,6 +23,14 @@ margin-top: 10px; } + #selected-file-card-error { + border: 1px solid red; + width: 500px; + padding-left: 15px; + margin-top: 10px; + color: red; + } + @media only screen and (max-device-width: 812px) { #selected-files-container { width: 100%; diff --git a/src/lib/FileViewer.svelte b/src/lib/FileViewer.svelte index 39de554..71ac1ea 100644 --- a/src/lib/FileViewer.svelte +++ b/src/lib/FileViewer.svelte @@ -3,10 +3,15 @@ import Dropzone from "./Dropzone.svelte"; import FileList from "./FileList.svelte"; + import { filterFileRequirements } from "../utils/filterFileRequirements"; + let files; let filesRendered = false; - const acceptedFiles = [".pes"]; - const maxFileSize = 700000; + let filesRejected; + const fileRequirements = { + supportedFormats: [".pes"], + maxSize: 700000, + }; const onSubmit = () => { filesRendered = true; @@ -23,18 +28,10 @@ const changedFiles = evt.dataTransfer ? evt.dataTransfer.files : evt.target.files; - let filesToUpload = []; - for (var i = 0, file; (file = changedFiles[i]); i++) { - if (file) { - if (file.size <= maxFileSize) { - filesToUpload.push(file); - } else { - console.log("File too large!"); - console.log(file); - } - } - } - files = filesToUpload; + + const results = filterFileRequirements(changedFiles, fileRequirements); + files = results.accepted; + filesRejected = results.rejected; }; const onClick = () => { @@ -55,11 +52,19 @@ >

Upload files

- Max file size is {maxFileSize / 1000}kb. Accepted formats: - {acceptedFiles.join(",")}. + Max file size is {fileRequirements.maxSize / 1000}kb. + Accepted formats: + {fileRequirements.supportedFormats.join(",")}.

- + @@ -67,7 +72,8 @@ {#if filesRendered} {:else} - + + {/if}