don't remove already selected files

This commit is contained in:
cupcakearmy 2022-03-02 16:55:04 +01:00
parent 83f0902291
commit 43f67c795d
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F

View File

@ -3,6 +3,7 @@
import { Files } from '$lib/files'
import { createEventDispatcher } from 'svelte'
import { t } from 'svelte-intl-precompile'
import Button from './Button.svelte'
import MaxSize from './MaxSize.svelte'
export let label: string = ''
@ -13,7 +14,7 @@
async function onInput(e: Event) {
const input = e.target as HTMLInputElement
if (input?.files?.length) {
files = Array.from(input.files)
files = [...files, ...Array.from(input.files)]
const data: FileDTO[] = await Promise.all(
files.map(async (file) => ({
name: file.name,
@ -27,6 +28,12 @@
dispatch('file', '')
}
}
function clear(e: Event) {
e.preventDefault()
files = []
dispatch('file', '')
}
</script>
<label>
@ -43,6 +50,8 @@
{file.name}
</div>
{/each}
<div class="spacer" />
<Button on:click={clear}>Clear</Button>
</div>
{:else}
<div>
@ -66,4 +75,8 @@
align-items: center;
cursor: pointer;
}
.spacer {
margin-top: 1rem;
}
</style>