more design updates on attachment picker
This commit is contained in:
parent
b1dbc7cc62
commit
bd3a604c7a
|
@ -6,13 +6,16 @@
|
||||||
export let files = []
|
export let files = []
|
||||||
|
|
||||||
let selectedImageIdx = 0
|
let selectedImageIdx = 0
|
||||||
|
let fileDragged = false
|
||||||
|
|
||||||
$: selectedImage = files[selectedImageIdx]
|
$: selectedImage = files[selectedImageIdx]
|
||||||
|
|
||||||
async function processFiles(evt) {
|
async function processFiles(fileList) {
|
||||||
const filesToProcess = Array.from(evt.target.files).map(
|
const filesToProcess = Array.from(fileList).map(({ name, path, size }) => ({
|
||||||
({ name, path, size }) => ({ name, path, size })
|
name,
|
||||||
)
|
path,
|
||||||
|
size,
|
||||||
|
}))
|
||||||
|
|
||||||
const response = await api.post(`/api/files/process`, {
|
const response = await api.post(`/api/files/process`, {
|
||||||
files: filesToProcess,
|
files: filesToProcess,
|
||||||
|
@ -29,12 +32,37 @@
|
||||||
function navigateRight() {
|
function navigateRight() {
|
||||||
selectedImageIdx += 1
|
selectedImageIdx += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleFile(evt) {
|
||||||
|
processFiles(evt.target.files)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDragOver(evt) {
|
||||||
|
evt.preventDefault()
|
||||||
|
fileDragged = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDragLeave(evt) {
|
||||||
|
evt.preventDefault()
|
||||||
|
fileDragged = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDrop(evt) {
|
||||||
|
evt.preventDefault()
|
||||||
|
processFiles(evt.dataTransfer.files)
|
||||||
|
fileDragged = false
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="dropzone">
|
<div
|
||||||
|
class="dropzone"
|
||||||
|
on:dragover={handleDragOver}
|
||||||
|
on:dragleave={handleDragLeave}
|
||||||
|
on:dragenter={handleDragOver}
|
||||||
|
on:drop={handleDrop}
|
||||||
|
class:fileDragged>
|
||||||
<ul>
|
<ul>
|
||||||
{#if selectedImage}
|
{#if selectedImage}
|
||||||
<!-- if block necessary for svelte transitions to work -->
|
|
||||||
<li transition:fade>
|
<li transition:fade>
|
||||||
<header>
|
<header>
|
||||||
<span>
|
<span>
|
||||||
|
@ -58,7 +86,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
</ul>
|
</ul>
|
||||||
<i class="ri-folder-upload-line" />
|
<i class="ri-folder-upload-line" />
|
||||||
<input id="file-upload" type="file" multiple on:change={processFiles} />
|
<input id="file-upload" type="file" multiple on:change={handleFile} />
|
||||||
<label for="file-upload">Upload</label>
|
<label for="file-upload">Upload</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -71,6 +99,13 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileDragged {
|
||||||
|
border: 2px dashed var(--grey-7);
|
||||||
|
transform: scale(1.02);
|
||||||
|
background: var(--blue-light);
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="file"] {
|
input[type="file"] {
|
||||||
|
|
Loading…
Reference in New Issue