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