Whalebird-desktop-client-ma.../src/renderer/components/TimelineSpace/Modals/ListMembership.vue

111 lines
2.6 KiB
Vue
Raw Normal View History

<template>
2022-04-27 12:53:52 +02:00
<el-dialog :title="$t('modals.list_membership.title')" v-model="listMembershipModal" width="400px" class="list-membership-modal">
<el-checkbox-group v-model="belongToLists" v-loading="loading">
<table class="lists">
<tbody>
<tr v-for="list in lists" :key="list.id">
<td>
<el-checkbox :label="list.id">{{ list.title }}</el-checkbox>
</td>
</tr>
</tbody>
</table>
</el-checkbox-group>
</el-dialog>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'list-membership',
data() {
return {
2022-04-19 12:18:29 +02:00
loading: false
}
},
computed: {
...mapState({
2022-04-19 12:18:29 +02:00
account: state => state.TimelineSpace.Modals.ListMembership.account,
lists: state => state.TimelineSpace.Modals.ListMembership.lists
}),
listMembershipModal: {
get() {
return this.$store.state.TimelineSpace.Modals.ListMembership.modalOpen
},
set(value) {
2022-04-19 12:18:29 +02:00
this.$store.dispatch('TimelineSpace/Modals/ListMembership/changeModal', value)
}
},
belongToLists: {
get() {
2022-04-19 12:18:29 +02:00
return this.$store.state.TimelineSpace.Modals.ListMembership.belongToLists.map(l => l.id)
},
set(value) {
this.loading = true
return this.$store
2022-04-19 12:18:29 +02:00
.dispatch('TimelineSpace/Modals/ListMembership/changeBelongToLists', value)
.catch(() => {
this.$message({
2018-08-13 08:27:53 +02:00
message: this.$t('message.update_list_memberships_error'),
2022-04-19 12:18:29 +02:00
type: 'error'
})
})
.finally(() => (this.loading = false))
2022-04-19 12:18:29 +02:00
}
}
},
watch: {
listMembershipModal: function (newState, oldState) {
if (!oldState && newState) {
this.init()
}
2022-04-19 12:18:29 +02:00
}
},
methods: {
async init() {
this.loading = true
try {
2022-04-19 12:18:29 +02:00
await this.$store.dispatch('TimelineSpace/Modals/ListMembership/fetchListMembership', this.account)
await this.$store.dispatch('TimelineSpace/Modals/ListMembership/fetchLists')
} catch (err) {
this.$message({
2018-08-13 08:27:53 +02:00
message: this.$t('message.lists_fetch_error'),
2022-04-19 12:18:29 +02:00
type: 'error'
})
} finally {
this.loading = false
}
2022-04-19 12:18:29 +02:00
}
}
}
</script>
<style lang="scss" scoped>
.lists {
text-align: left;
border-collapse: collapse;
width: 100%;
tr {
border-bottom: solid 1px #ebeef5;
&:first-child {
border-top: solid 1px #ebeef5;
}
&:nth-child(even) {
background-color: #fafafa;
}
&:hover {
background-color: #f2f6fc;
}
td {
padding: 4px 8px;
}
}
}
</style>