2021-07-06 22:22:57 +02:00
|
|
|
<template>
|
|
|
|
<router-link
|
|
|
|
:class="{
|
|
|
|
'has-light-text': !colorIsDark(list.hexColor),
|
2021-07-06 22:50:54 +02:00
|
|
|
'has-background': background !== null
|
2021-07-06 22:22:57 +02:00
|
|
|
}"
|
|
|
|
:style="{
|
|
|
|
'background-color': list.hexColor,
|
2021-07-06 22:50:54 +02:00
|
|
|
'background-image': background !== null ? `url(${background})` : false,
|
2021-07-06 22:22:57 +02:00
|
|
|
}"
|
|
|
|
:to="{ name: 'list.index', params: { listId: list.id} }"
|
|
|
|
class="list-card"
|
|
|
|
tag="span"
|
2021-07-06 22:50:54 +02:00
|
|
|
v-if="list !== null && (showArchived ? true : !list.isArchived)"
|
2021-07-06 22:22:57 +02:00
|
|
|
>
|
|
|
|
<div class="is-archived-container">
|
|
|
|
<span class="is-archived" v-if="list.isArchived">
|
|
|
|
{{ $t('namespace.archived') }}
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
:class="{'is-favorite': list.isFavorite, 'is-archived': list.isArchived}"
|
|
|
|
@click.stop="toggleFavoriteList(list)"
|
|
|
|
class="favorite">
|
|
|
|
<icon icon="star" v-if="list.isFavorite"/>
|
|
|
|
<icon :icon="['far', 'star']" v-else/>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="title">{{ list.title }}</div>
|
|
|
|
</router-link>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-07-06 22:50:54 +02:00
|
|
|
import ListService from '@/services/list'
|
|
|
|
|
2021-07-06 22:22:57 +02:00
|
|
|
export default {
|
|
|
|
name: 'list-card',
|
2021-07-06 22:50:54 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
background: null,
|
|
|
|
backgroundLoading: false,
|
|
|
|
}
|
|
|
|
},
|
2021-07-06 22:22:57 +02:00
|
|
|
props: {
|
|
|
|
list: {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
showArchived: {
|
|
|
|
default: false,
|
|
|
|
type: Boolean,
|
|
|
|
},
|
2021-07-06 22:50:54 +02:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
list() {
|
|
|
|
this.loadBackground()
|
2021-07-06 22:22:57 +02:00
|
|
|
},
|
|
|
|
},
|
2021-07-06 22:50:54 +02:00
|
|
|
created() {
|
|
|
|
this.loadBackground()
|
|
|
|
},
|
2021-07-06 22:22:57 +02:00
|
|
|
methods: {
|
2021-07-06 22:50:54 +02:00
|
|
|
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)
|
|
|
|
},
|
2021-07-06 22:22:57 +02:00
|
|
|
toggleFavoriteList(list) {
|
|
|
|
// The favorites pseudo list is always favorite
|
|
|
|
// Archived lists cannot be marked favorite
|
|
|
|
if (list.id === -1 || list.isArchived) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.$store.dispatch('lists/toggleListFavorite', list)
|
|
|
|
.catch(e => this.error(e))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|