frontend: implement dynamic file list
This commit is contained in:
parent
09c0f12692
commit
5535ffd048
6 changed files with 63 additions and 22 deletions
|
@ -1,14 +1,24 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
let { handler = () => {}, type = "button", files = $bindable() } = $props();
|
let { handler = () => {}, type = "button", files = $bindable() } = $props();
|
||||||
|
|
||||||
|
let file_list: FileList = $state([]);
|
||||||
|
$effect(() => {
|
||||||
|
// FileList -> Array[File]
|
||||||
|
let f_list: Array<File> = [];
|
||||||
|
for (let file of file_list)
|
||||||
|
f_list.push(file);
|
||||||
|
files = f_list;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if type == "button"}
|
{#if type == "button"}
|
||||||
<button class="plus round" style="height: 32px;" onclick={handler}>+</button>
|
<button class="plus round" style="height: 32px;" onclick={handler}>+</button>
|
||||||
{:else if type == "image"}
|
{:else if type == "image"}
|
||||||
<label for="img-upload" class="plus round" style="height: 48px; display: inline-block;">+</label>
|
<label for="img-upload" class="plus round" style="height: 48px; display: inline-block;">+</label>
|
||||||
<input id="img-upload" accept="image/png, image/jpeg" style="display: none" bind:files type="file"/>
|
<input id="img-upload" accept="image/png, image/jpeg" style="display: none" bind:files={file_list} type="file"/>
|
||||||
{:else}
|
{:else}
|
||||||
<button class="file-plus rounded" onclick={handler}>Загрузить файл</button>
|
<label for="file-upload" class="file-plus rounded">Загрузить файл</label>
|
||||||
|
<input id="file-upload" style="display: none" bind:files={file_list} multiple type="file"/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -23,15 +33,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-plus {
|
.file-plus {
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-size: larger;
|
||||||
font-size: x-large;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 0;
|
|
||||||
height: 3rem;
|
height: 3rem;
|
||||||
border: 0.15rem dashed;
|
border: 0.15rem dashed;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
@media (prefers-color-scheme: light) {
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import File from '$lib/components/file.svelte';
|
import File from '$lib/components/file.svelte';
|
||||||
import AddButton from '$lib/components/add_button.svelte';
|
import AddButton from '$lib/components/add_button.svelte';
|
||||||
|
let selected = $state([]);
|
||||||
|
let files: Array<File> = $state([]);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (selected.length > 0) {
|
||||||
|
let added: Array<File> = [];
|
||||||
|
for (let file of selected)
|
||||||
|
added.push(file);
|
||||||
|
files = files.concat(added);
|
||||||
|
selected = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="input rounded">
|
<div class="input rounded">
|
||||||
<File />
|
{#each files as file}
|
||||||
<AddButton type="file"/>
|
<File data={file}/>
|
||||||
|
{/each}
|
||||||
|
<AddButton type="file" bind:files={selected}/>
|
||||||
</div>
|
</div>
|
|
@ -15,7 +15,6 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
overflow-x: scroll;
|
overflow-x: scroll;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
padding: 0.5rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.img-conatiner :global(*) {
|
.img-conatiner :global(*) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import QueueItem from '$lib/components/queue_item.svelte';
|
import QueueItem from '$lib/components/queue_item.svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,27 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
let filename = "Some_very_long_archive_name.zip";
|
let { data } = $props();
|
||||||
let progress = "15GB/23GB";
|
|
||||||
|
const names = {
|
||||||
|
0: ["B", 0],
|
||||||
|
1: ["KB", 0],
|
||||||
|
2: ["MB", 1],
|
||||||
|
3: ["GB", 2],
|
||||||
|
4: ["TB", 3]
|
||||||
|
};
|
||||||
|
|
||||||
|
function size_str(size: number) {
|
||||||
|
let iter = 0;
|
||||||
|
while (size >= 1000) {
|
||||||
|
iter++;
|
||||||
|
size = size / 1000;
|
||||||
|
}
|
||||||
|
return size.toFixed(names[iter][1]).toString() + names[iter][0];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="file rounded">
|
<div class="file rounded">
|
||||||
<p class="filename">{filename}</p>
|
<p class="filename">{data.name}</p>
|
||||||
<p class="progress">{progress}</p>
|
<p class="progress">{size_str(data.size)}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -63,19 +63,22 @@ button {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fields p {
|
||||||
|
margin: 0;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-left: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
.horisontal-bar {
|
.horisontal-bar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
padding-left: 0.5rem;
|
padding-left: 0.25rem;
|
||||||
padding-right: 0.5rem;
|
padding-right: 0.25rem;
|
||||||
}
|
|
||||||
|
|
||||||
.horisontal-bar * {
|
|
||||||
margin: 0;
|
|
||||||
margin-right: 0.5rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.horisontal-bar p {
|
.horisontal-bar p {
|
||||||
|
margin: 0;
|
||||||
|
margin-right: 0.5rem;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue