createproject: add loading indicator and enabled to button

This commit is contained in:
Simone Gotti 2019-05-13 23:48:44 +02:00
parent 923219ca65
commit b3c22f8429
1 changed files with 25 additions and 2 deletions

View File

@ -17,7 +17,12 @@
</div> </div>
<div class="field is-grouped"> <div class="field is-grouped">
<div class="control"> <div class="control">
<button class="button is-primary" @click="createProject()">Create Project</button> <button
class="button is-primary"
v-bind:class="{ 'is-loading': createProjectLoading }"
:disabled="!createProjectButtonEnabled"
@click="createProject()"
>Create Project</button>
</div> </div>
</div> </div>
<div v-if="createProjectError" class="message is-danger"> <div v-if="createProjectError" class="message is-danger">
@ -48,18 +53,34 @@ export default {
data() { data() {
return { return {
createProjectError: null, createProjectError: null,
createProjectLoading: false,
createProjectLoadingTimeout: null,
user: null, user: null,
remoteSources: null, remoteSources: null,
remoteRepos: [], remoteRepos: [],
projectName: null, projectName: "",
remoteRepoPath: null, remoteRepoPath: null,
selectedRemoteSource: null selectedRemoteSource: null
}; };
}, },
computed: {
createProjectButtonEnabled: function() {
return this.projectName.length && this.selectedRemoteSource;
}
},
methods: { methods: {
resetErrors() { resetErrors() {
this.createProjectError = null; this.createProjectError = null;
}, },
startProjectLoading() {
this.createProjectLoadingTimeout = setTimeout(() => {
this.createProjectLoading = true;
}, 300);
},
stopProjectLoading() {
clearTimeout(this.createProjectLoadingTimeout);
this.createProjectLoading = false;
},
repoSelected(remoteSource, repoPath) { repoSelected(remoteSource, repoPath) {
this.selectedRemoteSource = remoteSource; this.selectedRemoteSource = remoteSource;
this.remoteRepoPath = repoPath; this.remoteRepoPath = repoPath;
@ -73,12 +94,14 @@ export default {
} }
let parentref = refArray.join("/"); let parentref = refArray.join("/");
this.startProjectLoading();
let { error } = await createProject( let { error } = await createProject(
parentref, parentref,
this.projectName, this.projectName,
this.selectedRemoteSource.name, this.selectedRemoteSource.name,
this.remoteRepoPath this.remoteRepoPath
); );
this.stopProjectLoading();
if (error) { if (error) {
this.createProjectError = error; this.createProjectError = error;
return; return;