add loading to authorize page

-disable fields if successful on the authorize page
This commit is contained in:
Danil Kovtonyuk 2020-02-10 00:11:37 +10:00
parent 431b06ca52
commit a979220830
5 changed files with 53 additions and 22 deletions

View File

@ -189,8 +189,6 @@
fieldset[disabled] { fieldset[disabled] {
.box { .box {
opacity: .5;
cursor: not-allowed;
background-color: $primary-invert; background-color: $primary-invert;
border-color: #393939; border-color: #393939;
@ -602,6 +600,15 @@ fieldset {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
&[disabled] {
opacity: .5;
cursor: not-allowed;
label {
cursor: inherit;
}
}
} }
.form { .form {

27
components/Loading.vue Normal file
View File

@ -0,0 +1,27 @@
<template>
<b-loading :active.sync="loading">
<div class="loading-container">
<div class="loading-tornado"></div>
<div class="loading-message">{{ message }}...</div>
</div>
</b-loading>
</template>
<script>
export default {
data() {
return {
loading: false,
message: 'Loading'
}
},
created() {
this.$root.$on('enableLoading', (msg = 'Loading') => {
this.loading = true
this.message = msg
})
this.$root.$on('disableLoading', () => {
this.loading = false
})
}
}
</script>

View File

@ -6,15 +6,18 @@
<nuxt /> <nuxt />
</div> </div>
</section> </section>
<Loading />
</div> </div>
</template> </template>
<script> <script>
import Navbar from '@/components/Navbar' import Navbar from '@/components/Navbar'
import Loading from '@/components/Loading'
export default { export default {
components: { components: {
Navbar Navbar,
Loading
} }
} }
</script> </script>

View File

@ -6,7 +6,7 @@
<h2 class="subtitle"> <h2 class="subtitle">
Do you want to authorize your contribution #{{ contributionIndex }}? Please sign in. Do you want to authorize your contribution #{{ contributionIndex }}? Please sign in.
</h2> </h2>
<fieldset class="authorize"> <fieldset :disabled="hideSaveBtn" class="authorize">
<Form /> <Form />
</fieldset> </fieldset>
<div class="buttons is-centered"> <div class="buttons is-centered">
@ -60,6 +60,7 @@ export default {
...mapGetters('user', ['isLoggedIn', 'hasErrorName']) ...mapGetters('user', ['isLoggedIn', 'hasErrorName'])
}, },
async mounted() { async mounted() {
this.$root.$emit('enableLoading')
await this.getUserData() await this.getUserData()
this.token = this.$route.query.token this.token = this.$route.query.token
if (!this.token) { if (!this.token) {
@ -68,6 +69,9 @@ export default {
// TODO try to load contribution data. May be it's already authorized // TODO try to load contribution data. May be it's already authorized
// also set `contributionIndex` // also set `contributionIndex`
} }
setTimeout(() => {
this.$root.$emit('disableLoading')
}, 800)
}, },
methods: { methods: {
...mapActions('user', ['getUserData', 'makeTweet']), ...mapActions('user', ['getUserData', 'makeTweet']),

View File

@ -56,13 +56,6 @@
If you dont trust binaries, we encorage you to follow this <a href="">instruction</a> to If you dont trust binaries, we encorage you to follow this <a href="">instruction</a> to
contribute by compiling from source code. It is very easy! contribute by compiling from source code. It is very easy!
</p> </p>
<b-loading :active.sync="loading">
<div class="loading-container">
<div class="loading-tornado"></div>
<div :class="status.type" class="loading-message">{{ status.msg }}...</div>
</div>
</b-loading>
</div> </div>
</template> </template>
@ -84,8 +77,7 @@ export default {
status: { status: {
type: '', type: '',
msg: '' msg: ''
}, }
loading: false
} }
}, },
computed: { computed: {
@ -131,12 +123,10 @@ export default {
} }
}, },
async mounted() { async mounted() {
this.loading = true this.$root.$emit('enableLoading')
this.status.msg = 'Loading'
this.status.type = ''
await this.getUserData() await this.getUserData()
setTimeout(() => { setTimeout(() => {
this.loading = false this.$root.$emit('disableLoading')
}, 800) }, 800)
}, },
methods: { methods: {
@ -144,20 +134,20 @@ export default {
async makeContribution({ retry = 0 } = {}) { async makeContribution({ retry = 0 } = {}) {
try { try {
this.isContributeBtnSnown = true this.isContributeBtnSnown = true
this.loading = true this.status.msg = ''
this.status.msg = 'Downloading last contribution'
this.status.type = '' this.status.type = ''
this.$root.$emit('enableLoading', 'Downloading last contribution')
let data = await fetch('api/challenge') let data = await fetch('api/challenge')
data = new Uint8Array(await data.arrayBuffer()) data = new Uint8Array(await data.arrayBuffer())
this.status.msg = 'Generating random contribution' this.$root.$emit('enableLoading', 'Generating random contribution')
await timeout(100) // allow UI to update before freezing in wasm await timeout(100) // allow UI to update before freezing in wasm
console.log('Source params', data) console.log('Source params', data)
const contribute = await this.$contribute() const contribute = await this.$contribute()
const result = contribute(data) const result = contribute(data)
console.log('Updated params', result) console.log('Updated params', result)
this.status.msg = 'Uploading and verifying your contribution' this.$root.$emit('enableLoading', 'Uploading and verifying your contribution')
console.log('this.user.name', this.userName, this.userHandle, this.userCompany) console.log('this.user.name', this.userName, this.userHandle, this.userCompany)
const formData = new FormData() const formData = new FormData()
formData.append('response', new Blob([result], { type: 'application/octet-stream' })) formData.append('response', new Blob([result], { type: 'application/octet-stream' }))
@ -197,7 +187,7 @@ export default {
this.status.type = 'is-danger' this.status.type = 'is-danger'
this.isContributeBtnSnown = false this.isContributeBtnSnown = false
} finally { } finally {
this.loading = false this.$root.$emit('disableLoading')
} }
}, },
onAnonymousHandler() { onAnonymousHandler() {