diff --git a/.storybook/preview.ts b/.storybook/preview.ts index 003515698..6802bc389 100644 --- a/.storybook/preview.ts +++ b/.storybook/preview.ts @@ -25,6 +25,14 @@ const preview: Preview = { csrftoken: "mockToken", }, cookiePreserve: true, + sveltekit_experimental: { + stores: { + page: { + url: "/", + data: {}, + }, + }, + }, }, }; diff --git a/src/lib/components/forms/DocumentUpload.svelte b/src/lib/components/forms/DocumentUpload.svelte index 8f3919b45..3dde39f8d 100644 --- a/src/lib/components/forms/DocumentUpload.svelte +++ b/src/lib/components/forms/DocumentUpload.svelte @@ -106,7 +106,13 @@ import { filesize } from "filesize"; import { afterUpdate } from "svelte"; import { _ } from "svelte-i18n"; - import { File16, File24, Upload16, XCircleFill24 } from "svelte-octicons"; + import { + Alert16, + File16, + File24, + Upload16, + XCircleFill24, + } from "svelte-octicons"; import { page } from "$app/stores"; @@ -126,14 +132,20 @@ import Text from "../inputs/Text.svelte"; import * as documents from "$lib/api/documents"; - import { DOCUMENT_TYPES } from "@/config/config.js"; + import { + DOCUMENT_SIZE_LIMIT, + DOCUMENT_TYPES, + PDF_SIZE_LIMIT, + } from "@/config/config.js"; import { filenameToTitle, getFileExtension, isSupported, + isWithinSizeLimit, } from "@/lib/utils/files"; + import Tooltip from "@/common/Tooltip.svelte"; - let files: File[] = []; + export let files: File[] = []; let projects: Project[] = []; let loading = false; @@ -157,12 +169,14 @@ let ocrEngine = ocrEngineOptions[0]; $: csrf_token = $page.data.csrf_token; - $: projects = $page.data.projects.results; + $: projects = $page.data.projects?.results; $: total = files.reduce((t, file) => { return t + file.size; }, 0); + $: exceedsSizeLimit = files.some((file) => !isWithinSizeLimit(file)); + function addFiles(filesToAdd: FileList) { files = files.concat(Array.from(filesToAdd).filter(isSupported)); } @@ -215,8 +229,21 @@
- {getFileExtension(file)} / {filesize(file.size)} +
+ {getFileExtension(file)} / {filesize(file.size)}
+ {#if !isWithinSizeLimit(file)}
+
Total upload size: {filesize(total)}
-+ Total: {files.length} file{files.length > 1 ? "s" : ""}, + {filesize(total)} +
+