monkeeShark/src/client/pages/my-lists/list.vue
syuilo f6154dc0af
v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com>
Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
2020-01-30 04:37:25 +09:00

163 lines
3.1 KiB
Vue

<template>
<div class="mk-list-page">
<transition name="zoom" mode="out-in">
<div v-if="list" :key="list.id" class="_section list">
<div class="_title">{{ list.name }}</div>
<div class="_content">
<div class="users">
<div class="user" v-for="(user, i) in users" :key="user.id" :data-index="i">
<mk-avatar :user="user" class="avatar"/>
<div class="body">
<mk-user-name :user="user" class="name"/>
<mk-acct :user="user" class="acct"/>
</div>
<div class="action">
<button class="_button" @click="removeUser(user)"><fa :icon="faTimes"/></button>
</div>
</div>
</div>
</div>
<div class="_footer">
<mk-button inline @click="renameList()">{{ $t('renameList') }}</mk-button>
<mk-button inline @click="deleteList()">{{ $t('deleteList') }}</mk-button>
</div>
</div>
</transition>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import { faTimes } from '@fortawesome/free-solid-svg-icons';
import i18n from '../../i18n';
import Progress from '../../scripts/loading';
import MkButton from '../../components/ui/button.vue';
export default Vue.extend({
i18n,
metaInfo() {
return {
title: this.list ? `${this.list.name} | ${this.$t('manageLists')}` : this.$t('manageLists')
};
},
components: {
MkButton
},
data() {
return {
list: null,
users: [],
faTimes
};
},
watch: {
$route: 'fetch'
},
created() {
this.fetch();
},
methods: {
fetch() {
Progress.start();
this.$root.api('users/lists/show', {
listId: this.$route.params.list
}).then(list => {
this.list = list;
this.$root.api('users/show', {
userIds: this.list.userIds
}).then(users => {
this.users = users;
Progress.done();
});
});
},
removeUser(user) {
this.$root.api('users/lists/pull', {
listId: this.list.id,
userId: user.id
}).then(() => {
this.users = this.users.filter(x => x.id !== user.id);
});
},
async renameList() {
const { canceled, result: name } = await this.$root.dialog({
title: this.$t('enterListName'),
input: {
default: this.list.name
}
});
if (canceled) return;
await this.$root.api('users/lists/update', {
listId: this.list.id,
name: name
});
this.list.name = name;
},
async deleteList() {
const { canceled } = await this.$root.dialog({
type: 'warning',
text: this.$t('deleteListConfirm', { list: this.list.name }),
showCancelButton: true
});
if (canceled) return;
await this.$root.api('users/lists/delete', {
listId: this.list.id
});
this.$root.dialog({
type: 'success',
iconOnly: true, autoClose: true
});
this.$router.push('/my/lists');
}
}
});
</script>
<style lang="scss" scoped>
.mk-list-page {
> .list {
> ._content {
max-height: 400px;
overflow: auto;
> .users {
> .user {
display: flex;
align-items: center;
> .avatar {
width: 50px;
height: 50px;
}
> .body {
flex: 1;
padding: 8px;
> .name {
display: block;
font-weight: bold;
}
> .acct {
opacity: 0.5;
}
}
}
}
}
}
}
</style>