+
{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}