Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add loading state on share button #309

Merged
merged 1 commit into from Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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