Load list background in list card

This commit is contained in:
kolaente 2021-07-06 22:50:54 +02:00
parent d09eff1655
commit 8097ef93c1
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 35 additions and 28 deletions

View file

@ -2,16 +2,16 @@
<router-link <router-link
:class="{ :class="{
'has-light-text': !colorIsDark(list.hexColor), 'has-light-text': !colorIsDark(list.hexColor),
'has-background': backgroundResolver(list.id) !== null 'has-background': background !== null
}" }"
:style="{ :style="{
'background-color': list.hexColor, 'background-color': list.hexColor,
'background-image': backgroundResolver(list.id) !== null ? `url(${backgroundResolver(list.id)})` : false, 'background-image': background !== null ? `url(${background})` : false,
}" }"
:to="{ name: 'list.index', params: { listId: list.id} }" :to="{ name: 'list.index', params: { listId: list.id} }"
class="list-card" class="list-card"
tag="span" tag="span"
v-if="showArchived ? true : !list.isArchived" v-if="list !== null && (showArchived ? true : !list.isArchived)"
> >
<div class="is-archived-container"> <div class="is-archived-container">
<span class="is-archived" v-if="list.isArchived"> <span class="is-archived" v-if="list.isArchived">
@ -30,8 +30,16 @@
</template> </template>
<script> <script>
import ListService from '@/services/list'
export default { export default {
name: 'list-card', name: 'list-card',
data() {
return {
background: null,
backgroundLoading: false,
}
},
props: { props: {
list: { list: {
required: true, required: true,
@ -40,13 +48,33 @@ export default {
default: false, default: false,
type: Boolean, type: Boolean,
}, },
// A function, returning a background blob or null if none exists for that list. },
// Receives the list id as parameter. watch: {
backgroundResolver: { list() {
required: true, this.loadBackground()
}, },
}, },
created() {
this.loadBackground()
},
methods: { methods: {
loadBackground() {
if (this.list === null || !this.list.backgroundInformation || this.backgroundLoading) {
return
}
this.backgroundLoading = true
const listService = new ListService()
listService.background(this.list)
.then(b => {
this.$set(this, 'background', b)
})
.catch(e => {
this.error(e)
})
.finally(() => this.backgroundLoading = false)
},
toggleFavoriteList(list) { toggleFavoriteList(list) {
// The favorites pseudo list is always favorite // The favorites pseudo list is always favorite
// Archived lists cannot be marked favorite // Archived lists cannot be marked favorite

View file

@ -58,7 +58,6 @@
:key="`l${l.id}`" :key="`l${l.id}`"
:list="l" :list="l"
:show-archived="showArchived" :show-archived="showArchived"
:background-resolver="lId => typeof backgrounds[lId] !== 'undefined' ? backgrounds[lId] : null"
/> />
</div> </div>
</div> </div>
@ -67,7 +66,6 @@
<script> <script>
import {mapState} from 'vuex' import {mapState} from 'vuex'
import ListService from '../../services/list'
import Fancycheckbox from '../../components/input/fancycheckbox' import Fancycheckbox from '../../components/input/fancycheckbox'
import {LOADING} from '@/store/mutation-types' import {LOADING} from '@/store/mutation-types'
import ListCard from '@/components/list/partials/list-card' import ListCard from '@/components/list/partials/list-card'
@ -81,13 +79,10 @@ export default {
data() { data() {
return { return {
showArchived: false, showArchived: false,
// listId is the key, the object is the background blob
backgrounds: {},
} }
}, },
created() { created() {
this.showArchived = JSON.parse(localStorage.getItem('showArchived')) ?? false this.showArchived = JSON.parse(localStorage.getItem('showArchived')) ?? false
this.loadBackgroundsForLists()
}, },
mounted() { mounted() {
this.setTitle(this.$t('namespace.title')) this.setTitle(this.$t('namespace.title'))
@ -99,22 +94,6 @@ export default {
loading: LOADING, loading: LOADING,
}), }),
methods: { methods: {
loadBackgroundsForLists() {
const listService = new ListService()
this.namespaces.forEach(n => {
n.lists.forEach(l => {
if (l.backgroundInformation) {
listService.background(l)
.then(b => {
this.$set(this.backgrounds, l.id, b)
})
.catch(e => {
this.error(e)
})
}
})
})
},
saveShowArchivedState() { saveShowArchivedState() {
localStorage.setItem('showArchived', JSON.stringify(this.showArchived)) localStorage.setItem('showArchived', JSON.stringify(this.showArchived))
}, },