feat(notes): show loader on image upload button while uploading

This commit is contained in:
Julien Calixte
2026-05-25 21:23:22 +02:00
parent 6a0f0d08d2
commit 4ab0be75e7

View File

@@ -118,17 +118,23 @@ const { uploadImage } = useImageUpload({
const fileInput = ref<HTMLInputElement | null>(null) const fileInput = ref<HTMLInputElement | null>(null)
const editKey = ref(0) const editKey = ref(0)
const isUploading = ref(false)
const onImagePicked = async (e: Event) => { const onImagePicked = async (e: Event) => {
const input = e.target as HTMLInputElement const input = e.target as HTMLInputElement
const file = input.files?.[0] const file = input.files?.[0]
input.value = "" input.value = ""
if (!file || !path.value) return if (!file || !path.value) return
const result = await uploadImage(file) isUploading.value = true
if (!result) return try {
const suffix = rawContent.value.endsWith("\n") ? "" : "\n\n" const result = await uploadImage(file)
rawContent.value = `${rawContent.value}${suffix}![](${result.filename})\n` if (!result) return
editKey.value++ const suffix = rawContent.value.endsWith("\n") ? "" : "\n\n"
rawContent.value = `${rawContent.value}${suffix}![](${result.filename})\n`
editKey.value++
} finally {
isUploading.value = false
}
} }
const { const {
@@ -298,10 +304,16 @@ const onBadgeClick = async () => {
<button <button
v-if="isMarkdown && mode === 'edit'" v-if="isMarkdown && mode === 'edit'"
class="action button is-text is-light" class="action button is-text is-light"
title="Upload image" :title="isUploading ? 'Uploading…' : 'Upload image'"
:disabled="isUploading"
@click="fileInput?.click()" @click="fileInput?.click()"
> >
<span
v-if="isUploading"
class="loading loading-spinner loading-sm"
></span>
<svg <svg
v-else
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-photo-plus" class="icon icon-tabler icon-tabler-photo-plus"
width="24" width="24"