Disable "Publish" button while post is being published

This commit is contained in:
silverpill 2022-09-25 21:55:32 +00:00
parent 74173b4884
commit 408677921b
3 changed files with 19 additions and 3 deletions

View file

@ -136,9 +136,9 @@ button {
} }
&[disabled] { &[disabled] {
background-color: #ddd !important; background-color: $btn-disabled-background-color !important;
box-shadow: none; box-shadow: none;
color: #999 !important; color: $btn-disabled-text-color !important;
cursor: initial; cursor: initial;
} }
} }

View file

@ -67,6 +67,7 @@
type="submit" type="submit"
v-if="inReplyTo" v-if="inReplyTo"
class="submit-btn-small" class="submit-btn-small"
:disabled="!canPublish()"
@click.prevent="publish()" @click.prevent="publish()"
> >
Publish Publish
@ -78,7 +79,7 @@
<button <button
class="btn" class="btn"
type="submit" type="submit"
:disabled="getCharacterCount() < 0" :disabled="!canPublish()"
@click.prevent="publish()" @click.prevent="publish()"
>Publish</button> >Publish</button>
</div> </div>
@ -130,6 +131,7 @@ let attachment = $ref<Attachment | null>(null)
let visibility = $ref(Visibility.Public) let visibility = $ref(Visibility.Public)
let visibilityMenuVisible = $ref(false) let visibilityMenuVisible = $ref(false)
let isLoading = $ref(false)
let errorMessage = $ref<string | null>(null) let errorMessage = $ref<string | null>(null)
const author = $computed<User | null>(() => { const author = $computed<User | null>(() => {
@ -192,6 +194,10 @@ function getCharacterCount(): number {
return (instance.post_character_limit - content.length) return (instance.post_character_limit - content.length)
} }
function canPublish(): boolean {
return getCharacterCount() >= 0 && !isLoading
}
async function publish() { async function publish() {
const contentRendered = renderMarkdownLite(content) const contentRendered = renderMarkdownLite(content)
const postData = { const postData = {
@ -200,6 +206,7 @@ async function publish() {
visibility: visibility, visibility: visibility,
mentions: [], mentions: [],
} }
isLoading = true
let post let post
try { try {
post = await createPost( post = await createPost(
@ -209,10 +216,12 @@ async function publish() {
) )
} catch (error: any) { } catch (error: any) {
errorMessage = error.message errorMessage = error.message
isLoading = false
return return
} }
// Refresh editor // Refresh editor
errorMessage = null errorMessage = null
isLoading = false
attachment = null attachment = null
content = "" content = ""
if (postFormContentRef) { if (postFormContentRef) {
@ -288,6 +297,11 @@ textarea {
.submit-btn-small { .submit-btn-small {
font-weight: bold; font-weight: bold;
margin-left: $block-inner-padding; margin-left: $block-inner-padding;
&[disabled] {
color: $btn-disabled-text-color;
cursor: initial;
}
} }
} }

View file

@ -26,6 +26,8 @@ $btn-border-radius: 8px;
$btn-shadow: 2px 5px 10px -5px #B7B5B5; $btn-shadow: 2px 5px 10px -5px #B7B5B5;
$btn-secondary-background-color: #CCCBC6; $btn-secondary-background-color: #CCCBC6;
$btn-secondary-text-color: $text-color; $btn-secondary-text-color: $text-color;
$btn-disabled-background-color: #ddd;
$btn-disabled-text-color: #999;
$block-border-radius: 15px; $block-border-radius: 15px;
$block-background-color: #fff; $block-background-color: #fff;