Fix loading in profile picture input
This commit is contained in:
parent
5bd4014d6d
commit
6046647aa0
1 changed files with 21 additions and 19 deletions
|
|
@ -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,31 +36,21 @@
|
||||||
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
|
|
||||||
file = undefined
|
|
||||||
url = undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
let active = $state(false)
|
|
||||||
let loading = $state(false)
|
|
||||||
let initialUrl = $state(url)
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
call(async () => {
|
|
||||||
if (file) {
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
const {result} = await uploadFile(file)
|
try {
|
||||||
|
file = await compressFile(file, compressOptions)
|
||||||
|
|
||||||
loading = false
|
if (file) {
|
||||||
|
const {result} = await uploadFile(file)
|
||||||
|
|
||||||
if (result?.url) {
|
if (result?.url) {
|
||||||
url = result.url
|
url = result.url
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue