Fix loading state for kanban board
This commit is contained in:
parent
15edfe0a49
commit
bd351550ee
3 changed files with 41 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="kanban loader-container" :class="{ 'is-loading': bucketService.loading}">
|
<div class="kanban loader-container" :class="{ 'is-loading': loading}">
|
||||||
<div v-for="bucket in buckets" :key="`bucket${bucket.id}`" class="bucket">
|
<div v-for="bucket in buckets" :key="`bucket${bucket.id}`" class="bucket">
|
||||||
<div class="bucket-header">
|
<div class="bucket-header">
|
||||||
<h2
|
<h2
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bucket new-bucket" v-if="!bucketService.loading">
|
<div class="bucket new-bucket" v-if="!loading">
|
||||||
<input
|
<input
|
||||||
v-if="showNewBucketInput"
|
v-if="showNewBucketInput"
|
||||||
class="input"
|
class="input"
|
||||||
|
@ -151,8 +151,8 @@
|
||||||
@keyup.esc="() => showNewBucketInput = false"
|
@keyup.esc="() => showNewBucketInput = false"
|
||||||
@keyup.enter="createNewBucket"
|
@keyup.enter="createNewBucket"
|
||||||
v-model="newBucketTitle"
|
v-model="newBucketTitle"
|
||||||
:disabled="bucketService.loading"
|
:disabled="loading"
|
||||||
:class="{'is-loading': bucketService.loading}"
|
:class="{'is-loading': loading}"
|
||||||
/>
|
/>
|
||||||
<a
|
<a
|
||||||
class="button noshadow is-transparent is-fullwidth has-text-centered"
|
class="button noshadow is-transparent is-fullwidth has-text-centered"
|
||||||
|
@ -186,7 +186,6 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import BucketService from '../../../services/bucket'
|
|
||||||
import TaskService from '../../../services/task'
|
import TaskService from '../../../services/task'
|
||||||
import TaskModel from '../../../models/task'
|
import TaskModel from '../../../models/task'
|
||||||
import BucketModel from '../../../models/bucket'
|
import BucketModel from '../../../models/bucket'
|
||||||
|
@ -199,6 +198,7 @@
|
||||||
import {filterObject} from '../../../helpers/filterObject'
|
import {filterObject} from '../../../helpers/filterObject'
|
||||||
import {applyDrag} from '../../../helpers/applyDrag'
|
import {applyDrag} from '../../../helpers/applyDrag'
|
||||||
import {mapState} from 'vuex'
|
import {mapState} from 'vuex'
|
||||||
|
import {LOADING} from '../../../store/mutation-types'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Kanban',
|
name: 'Kanban',
|
||||||
|
@ -211,7 +211,6 @@
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
bucketService: BucketService,
|
|
||||||
taskService: TaskService,
|
taskService: TaskService,
|
||||||
|
|
||||||
dropPlaceholderOptions: {
|
dropPlaceholderOptions: {
|
||||||
|
@ -235,13 +234,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.bucketService = new BucketService()
|
|
||||||
this.taskService = new TaskService()
|
this.taskService = new TaskService()
|
||||||
this.loadBuckets()
|
this.loadBuckets()
|
||||||
setTimeout(() => document.addEventListener('click', this.closeBucketDropdowns), 0)
|
setTimeout(() => document.addEventListener('click', this.closeBucketDropdowns), 0)
|
||||||
},
|
},
|
||||||
computed: mapState({
|
computed: mapState({
|
||||||
buckets: state => state.kanban.buckets,
|
buckets: state => state.kanban.buckets,
|
||||||
|
loading: LOADING,
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
loadBuckets() {
|
loadBuckets() {
|
||||||
|
|
11
src/store/helper.js
Normal file
11
src/store/helper.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import {LOADING} from './mutation-types'
|
||||||
|
|
||||||
|
export const setLoading = context => {
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
context.commit(LOADING, true, {root: true})
|
||||||
|
}, 100)
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
context.commit(LOADING, false, {root: true})
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import Vue from 'vue'
|
||||||
|
|
||||||
import BucketService from '../../services/bucket'
|
import BucketService from '../../services/bucket'
|
||||||
import {filterObject} from '../../helpers/filterObject'
|
import {filterObject} from '../../helpers/filterObject'
|
||||||
|
import {setLoading} from '../helper'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This store is intended to hold the currently active kanban view.
|
* This store is intended to hold the currently active kanban view.
|
||||||
|
@ -89,6 +90,11 @@ export default {
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
loadBucketsForList(ctx, listId) {
|
loadBucketsForList(ctx, listId) {
|
||||||
|
const cancel = setLoading(ctx)
|
||||||
|
|
||||||
|
// Clear everything to prevent having old buckets in the list if loading the buckets from this list takes a few moments
|
||||||
|
ctx.commit('setBuckets', [])
|
||||||
|
|
||||||
const bucketService = new BucketService()
|
const bucketService = new BucketService()
|
||||||
return bucketService.getAll({listId: listId})
|
return bucketService.getAll({listId: listId})
|
||||||
.then(r => {
|
.then(r => {
|
||||||
|
@ -98,8 +104,13 @@ export default {
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
})
|
})
|
||||||
|
.finally(() => {
|
||||||
|
cancel()
|
||||||
|
})
|
||||||
},
|
},
|
||||||
createBucket(ctx, bucket) {
|
createBucket(ctx, bucket) {
|
||||||
|
const cancel = setLoading(ctx)
|
||||||
|
|
||||||
const bucketService = new BucketService()
|
const bucketService = new BucketService()
|
||||||
return bucketService.create(bucket)
|
return bucketService.create(bucket)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
|
@ -109,8 +120,13 @@ export default {
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
})
|
})
|
||||||
|
.finally(() => {
|
||||||
|
cancel()
|
||||||
|
})
|
||||||
},
|
},
|
||||||
deleteBucket(ctx, bucket) {
|
deleteBucket(ctx, bucket) {
|
||||||
|
const cancel = setLoading(ctx)
|
||||||
|
|
||||||
const bucketService = new BucketService()
|
const bucketService = new BucketService()
|
||||||
return bucketService.delete(bucket)
|
return bucketService.delete(bucket)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
|
@ -122,8 +138,13 @@ export default {
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
})
|
})
|
||||||
|
.finally(() => {
|
||||||
|
cancel()
|
||||||
|
})
|
||||||
},
|
},
|
||||||
updateBucket(ctx, bucket) {
|
updateBucket(ctx, bucket) {
|
||||||
|
const cancel = setLoading(ctx)
|
||||||
|
|
||||||
const bucketService = new BucketService()
|
const bucketService = new BucketService()
|
||||||
return bucketService.update(bucket)
|
return bucketService.update(bucket)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
|
@ -136,6 +157,9 @@ export default {
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
})
|
})
|
||||||
|
.finally(() => {
|
||||||
|
cancel()
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
Loading…
Reference in a new issue