Disable post submission button while attachment is being uploaded

This commit is contained in:
silverpill 2023-02-21 19:41:43 +00:00
parent 46369a261e
commit 16c6b35f4c
2 changed files with 9 additions and 2 deletions

View file

@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Changed custom emoji vertical alignment and size. - Changed custom emoji vertical alignment and size.
- Expect `/api/v1/statuses` to return status code 200. - Expect `/api/v1/statuses` to return status code 200.
- Insert application-name meta tag at build time. - Insert application-name meta tag at build time.
- Disable post submission button while attachment is being uploaded.
## [1.13.0] - 2023-02-06 ## [1.13.0] - 2023-02-06

View file

@ -172,6 +172,7 @@ let visibility = $ref(Visibility.Public)
let visibilityMenuVisible = $ref(false) let visibilityMenuVisible = $ref(false)
let preview = $ref<Post | null>(null) let preview = $ref<Post | null>(null)
let isLoading = $ref(false) let isLoading = $ref(false)
let isAttachmentLoading = $ref(false)
let errorMessage = $ref<string | null>(null) let errorMessage = $ref<string | null>(null)
const author = $computed<User | null>(() => { const author = $computed<User | null>(() => {
@ -231,7 +232,10 @@ function canAttachFile(): boolean {
if (!instance) { if (!instance) {
return false return false
} }
return attachments.length < instance.configuration.statuses.max_media_attachments return (
attachments.length < instance.configuration.statuses.max_media_attachments &&
!isAttachmentLoading
)
} }
function getAcceptedMediaTypes(): string { function getAcceptedMediaTypes(): string {
@ -258,6 +262,7 @@ async function onAttachmentUpload(event: Event) {
} }
async function addAttachment(file: File) { async function addAttachment(file: File) {
isAttachmentLoading = true
const imageDataUrl = await fileToDataUrl(file) const imageDataUrl = await fileToDataUrl(file)
const imageData = dataUrlToBase64(imageDataUrl) const imageData = dataUrlToBase64(imageDataUrl)
const attachment = await uploadAttachment( const attachment = await uploadAttachment(
@ -266,6 +271,7 @@ async function addAttachment(file: File) {
imageData.mediaType, imageData.mediaType,
) )
attachments.push(attachment) attachments.push(attachment)
isAttachmentLoading = false
} }
function removeAttachment(index: number) { function removeAttachment(index: number) {
@ -307,7 +313,7 @@ async function togglePreview() {
} }
function canPublish(): boolean { function canPublish(): boolean {
return getCharacterCount() >= 0 && !isLoading return getCharacterCount() >= 0 && !isLoading && !isAttachmentLoading
} }
async function publish() { async function publish() {