Skip to content

Commit

Permalink
add loading state on share button (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianMrn committed Sep 6, 2020
1 parent 64cb88a commit e2b6a9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions resources/compiled/ignition.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion resources/js/components/Shared/ShareButton.vue
Expand Up @@ -46,7 +46,12 @@
:ownerUrl="sharedErrorUrls.owner_url"
/>
</div>
<ShareForm v-else @share="shareError" :error="shareHadError" />
<ShareForm
v-else
:error="shareHadError"
:is-loading="isShareLoading"
@share="shareError"
/>
</div>
</div>
</template>
Expand All @@ -64,6 +69,7 @@ export default {
shareHadError: false,
sharedErrorUrls: null,
menuVisible: false,
isShareLoading: false,
};
},
Expand All @@ -83,6 +89,8 @@ export default {
},
async shareError(selectedTabs) {
this.isShareLoading = true;
try {
const response = await fetch(this.shareEndpoint, {
method: 'POST',
Expand All @@ -106,6 +114,8 @@ export default {
} catch (error) {
this.shareHadError = true;
}
this.isShareLoading = false;
},
},
};
Expand Down
14 changes: 10 additions & 4 deletions resources/js/components/Shared/ShareForm.vue
Expand Up @@ -18,8 +18,12 @@
Please try again later.
</div>

<button @click="shareError" class="button-secondary button-sm bg-tint-600 text-white">
Share
<button
class="button-secondary button-sm text-white bg-tint-600"
:disabled="isLoading"
@click="shareError"
>
{{ isLoading ? 'Sharing…' : 'Share' }}
</button>
</div>
</div>
Expand All @@ -31,7 +35,7 @@ import CheckboxField from './CheckboxField';
export default {
components: { CheckboxField },
props: ['error'],
props: ['error', 'isLoading'],
computed: {
selectedTabs() {
Expand All @@ -54,7 +58,9 @@ export default {
methods: {
shareError() {
this.$emit('share', this.selectedTabs);
if (!this.isLoading) {
this.$emit('share', this.selectedTabs);
}
},
},
};
Expand Down

0 comments on commit e2b6a9e

Please sign in to comment.