From 3537db24881122aa99f9b7b7c992f9c66edcd96e Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Thu, 24 Sep 2020 17:37:26 +0200 Subject: [PATCH] Adjust examples to 0.3.0 --- resources/js/Pages/Auth/Login.vue | 10 +++++++--- resources/js/Pages/Contacts/Create.vue | 7 ++++--- resources/js/Pages/Contacts/Edit.vue | 7 ++++--- resources/js/Pages/Organizations/Create.vue | 7 ++++--- resources/js/Pages/Organizations/Edit.vue | 7 ++++--- resources/js/Pages/Users/Create.vue | 10 +++++----- resources/js/Pages/Users/Edit.vue | 14 ++++++++------ resources/js/app.js | 3 +++ 8 files changed, 39 insertions(+), 26 deletions(-) diff --git a/resources/js/Pages/Auth/Login.vue b/resources/js/Pages/Auth/Login.vue index 6628cc3..614e28a 100644 --- a/resources/js/Pages/Auth/Login.vue +++ b/resources/js/Pages/Auth/Login.vue @@ -49,12 +49,16 @@ export default { }, methods: { submit() { - this.sending = true - this.$inertia.post(this.route('login.attempt'), { + const data = { email: this.form.email, password: this.form.password, remember: this.form.remember, - }).then(() => this.sending = false) + } + + this.$inertia.post(this.route('login.attempt'), data, { + onStart: () => this.sending = true, + onFinish: () => this.sending = false, + }) }, }, } diff --git a/resources/js/Pages/Contacts/Create.vue b/resources/js/Pages/Contacts/Create.vue index 1b9968e..130d263 100644 --- a/resources/js/Pages/Contacts/Create.vue +++ b/resources/js/Pages/Contacts/Create.vue @@ -71,9 +71,10 @@ export default { }, methods: { submit() { - this.sending = true - this.$inertia.post(this.route('contacts.store'), this.form) - .then(() => this.sending = false) + this.$inertia.post(this.route('contacts.store'), this.form, { + onStart: () => this.sending = true, + onFinish: () => this.sending = false, + }) }, }, } diff --git a/resources/js/Pages/Contacts/Edit.vue b/resources/js/Pages/Contacts/Edit.vue index 3b0a9d9..0c803fd 100644 --- a/resources/js/Pages/Contacts/Edit.vue +++ b/resources/js/Pages/Contacts/Edit.vue @@ -83,9 +83,10 @@ export default { }, methods: { submit() { - this.sending = true - this.$inertia.put(this.route('contacts.update', this.contact.id), this.form) - .then(() => this.sending = false) + this.$inertia.put(this.route('contacts.update', this.contact.id), this.form, { + onStart: () => this.sending = true, + onFinish: () => this.sending = false, + }) }, destroy() { if (confirm('Are you sure you want to delete this contact?')) { diff --git a/resources/js/Pages/Organizations/Create.vue b/resources/js/Pages/Organizations/Create.vue index 89a0c9d..589bcd6 100644 --- a/resources/js/Pages/Organizations/Create.vue +++ b/resources/js/Pages/Organizations/Create.vue @@ -63,9 +63,10 @@ export default { }, methods: { submit() { - this.sending = true - this.$inertia.post(this.route('organizations.store'), this.form) - .then(() => this.sending = false) + this.$inertia.post(this.route('organizations.store'), this.form, { + onStart: () => this.sending = true, + onFinish: () => this.sending = false, + }) }, }, } diff --git a/resources/js/Pages/Organizations/Edit.vue b/resources/js/Pages/Organizations/Edit.vue index 3972642..a340d93 100644 --- a/resources/js/Pages/Organizations/Edit.vue +++ b/resources/js/Pages/Organizations/Edit.vue @@ -111,9 +111,10 @@ export default { }, methods: { submit() { - this.sending = true - this.$inertia.put(this.route('organizations.update', this.organization.id), this.form) - .then(() => this.sending = false) + this.$inertia.put(this.route('organizations.update', this.organization.id), this.form, { + onStart: () => this.sending = true, + onFinish: () => this.sending = false, + }) }, destroy() { if (confirm('Are you sure you want to delete this organization?')) { diff --git a/resources/js/Pages/Users/Create.vue b/resources/js/Pages/Users/Create.vue index 3177de7..73cb882 100644 --- a/resources/js/Pages/Users/Create.vue +++ b/resources/js/Pages/Users/Create.vue @@ -60,9 +60,7 @@ export default { }, methods: { submit() { - this.sending = true - - var data = new FormData() + const data = new FormData() data.append('first_name', this.form.first_name || '') data.append('last_name', this.form.last_name || '') data.append('email', this.form.email || '') @@ -70,8 +68,10 @@ export default { data.append('owner', this.form.owner ? '1' : '0') data.append('photo', this.form.photo || '') - this.$inertia.post(this.route('users.store'), data) - .then(() => this.sending = false) + this.$inertia.post(this.route('users.store'), data, { + onStart: () => this.sending = true, + onFinish: () => this.sending = false, + }) }, }, } diff --git a/resources/js/Pages/Users/Edit.vue b/resources/js/Pages/Users/Edit.vue index 4e73020..0e52da4 100644 --- a/resources/js/Pages/Users/Edit.vue +++ b/resources/js/Pages/Users/Edit.vue @@ -75,8 +75,6 @@ export default { }, methods: { submit() { - this.sending = true - var data = new FormData() data.append('first_name', this.form.first_name || '') data.append('last_name', this.form.last_name || '') @@ -86,14 +84,18 @@ export default { data.append('photo', this.form.photo || '') data.append('_method', 'put') - this.$inertia.post(this.route('users.update', this.user.id), data) - .then(() => { - this.sending = false + this.$inertia.post(this.route('users.update', this.user.id), data, { + onStart: () => this.sending = true, + onSuccess: () => { if (Object.keys(this.$page.errors).length === 0) { this.form.photo = null this.form.password = null } - }) + }, + onFinish: () => { + this.sending = false + }, + }) }, destroy() { if (confirm('Are you sure you want to delete this user?')) { diff --git a/resources/js/app.js b/resources/js/app.js index e5500a6..936a857 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -2,6 +2,7 @@ import Vue from 'vue' import VueMeta from 'vue-meta' import PortalVue from 'portal-vue' import { InertiaApp } from '@inertiajs/inertia-vue' +import { InertiaProgress } from '@inertiajs/progress/src' Vue.config.productionTip = false Vue.mixin({ methods: { route: window.route } }) @@ -9,6 +10,8 @@ Vue.use(InertiaApp) Vue.use(PortalVue) Vue.use(VueMeta) +InertiaProgress.init() + let app = document.getElementById('app') new Vue({