Fix loading in profile picture input

This commit is contained in:
Jon Staab 2026-07-02 16:52:36 -07:00
parent 5bd4014d6d
commit 6046647aa0

View file

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import {randomId, call} from "@welshman/lib" import {randomId} from "@welshman/lib"
import {preventDefault, stopPropagation, compressFile} from "@lib/html" import {preventDefault, stopPropagation, compressFile} from "@lib/html"
import CloseCircle from "@assets/icons/close-circle.svg?dataurl" import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
import AddCircle from "@assets/icons/add-circle.svg?dataurl" import AddCircle from "@assets/icons/add-circle.svg?dataurl"
@ -36,32 +36,22 @@
const onDrop = async (e: any) => { const onDrop = async (e: any) => {
active = false active = false
file = await compressFile(e.dataTransfer.files[0], compressOptions) submit(e.dataTransfer.files[0])
} }
const onChange = async (e: any) => { const onChange = async (e: any) => {
file = await compressFile(e.target.files[0], compressOptions) submit(e.target.files[0])
} }
const onClear = () => { const submit = async (file: File) => {
initialUrl = undefined loading = true
file = undefined
url = undefined
}
let active = $state(false) try {
let loading = $state(false) file = await compressFile(file, compressOptions)
let initialUrl = $state(url)
$effect(() => {
call(async () => {
if (file) { if (file) {
loading = true
const {result} = await uploadFile(file) const {result} = await uploadFile(file)
loading = false
if (result?.url) { if (result?.url) {
url = result.url url = result.url
} else { } else {
@ -80,8 +70,20 @@
} else { } else {
url = initialUrl url = initialUrl
} }
}) } finally {
}) loading = false
}
}
const onClear = () => {
initialUrl = undefined
file = undefined
url = undefined
}
let active = $state(false)
let loading = $state(false)
let initialUrl = $state(url)
</script> </script>
<form> <form>