2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2021-12-02 20:09:12 +09:00
|
|
|
<MkSpacer :content-max="700">
|
|
|
|
<div class="mk-list-page">
|
|
|
|
<transition name="zoom" mode="out-in">
|
|
|
|
<div v-if="list" class="_section">
|
|
|
|
<div class="_content">
|
|
|
|
<MkButton inline @click="addUser()">{{ $ts.addUser }}</MkButton>
|
|
|
|
<MkButton inline @click="renameList()">{{ $ts.rename }}</MkButton>
|
|
|
|
<MkButton inline @click="deleteList()">{{ $ts.delete }}</MkButton>
|
|
|
|
</div>
|
2020-02-08 15:11:12 +09:00
|
|
|
</div>
|
2021-12-02 20:09:12 +09:00
|
|
|
</transition>
|
2020-02-08 15:11:12 +09:00
|
|
|
|
2021-12-02 20:09:12 +09:00
|
|
|
<transition name="zoom" mode="out-in">
|
|
|
|
<div v-if="list" class="_section members _gap">
|
|
|
|
<div class="_title">{{ $ts.members }}</div>
|
|
|
|
<div class="_content">
|
|
|
|
<div class="users">
|
|
|
|
<div v-for="user in users" :key="user.id" class="user _panel">
|
|
|
|
<MkAvatar :user="user" class="avatar" :show-indicator="true"/>
|
|
|
|
<div class="body">
|
|
|
|
<MkUserName :user="user" class="name"/>
|
|
|
|
<MkAcct :user="user" class="acct"/>
|
|
|
|
</div>
|
|
|
|
<div class="action">
|
|
|
|
<button class="_button" @click="removeUser(user)"><i class="fas fa-times"></i></button>
|
|
|
|
</div>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-02 20:09:12 +09:00
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-01-30 04:37:25 +09:00
|
|
|
components: {
|
|
|
|
MkButton
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 12:54:12 +09:00
|
|
|
[symbols.PAGE_INFO]: computed(() => this.list ? {
|
2020-11-03 20:36:12 +09:00
|
|
|
title: this.list.name,
|
2021-04-20 23:22:59 +09:00
|
|
|
icon: 'fas fa-list-ul',
|
2021-12-02 20:09:12 +09:00
|
|
|
bg: 'var(--bg)',
|
2020-10-17 20:12:00 +09:00
|
|
|
} : null),
|
2020-01-30 04:37:25 +09:00
|
|
|
list: null,
|
|
|
|
users: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
$route: 'fetch'
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetch() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('users/lists/show', {
|
2020-01-30 04:37:25 +09:00
|
|
|
listId: this.$route.params.list
|
|
|
|
}).then(list => {
|
|
|
|
this.list = list;
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('users/show', {
|
2020-01-30 04:37:25 +09:00
|
|
|
userIds: this.list.userIds
|
|
|
|
}).then(users => {
|
|
|
|
this.users = users;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-02-08 15:11:12 +09:00
|
|
|
addUser() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.selectUser().then(user => {
|
|
|
|
os.apiWithDialog('users/lists/push', {
|
2020-02-08 15:11:12 +09:00
|
|
|
listId: this.list.id,
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
this.users.push(user);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
removeUser(user) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('users/lists/pull', {
|
2020-01-30 04:37:25 +09:00
|
|
|
listId: this.list.id,
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
this.users = this.users.filter(x => x.id !== user.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
async renameList() {
|
2021-11-18 18:45:58 +09:00
|
|
|
const { canceled, result: name } = await os.inputText({
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts.enterListName,
|
2021-11-18 18:45:58 +09:00
|
|
|
default: this.list.name
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
await os.api('users/lists/update', {
|
2020-01-30 04:37:25 +09:00
|
|
|
listId: this.list.id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
|
|
|
|
this.list.name = name;
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteList() {
|
2021-11-18 18:45:58 +09:00
|
|
|
const { canceled } = await os.confirm({
|
2020-01-30 04:37:25 +09:00
|
|
|
type: 'warning',
|
2020-02-08 15:11:12 +09:00
|
|
|
text: this.$t('removeAreYouSure', { x: this.list.name }),
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
await os.api('users/lists/delete', {
|
2020-01-30 04:37:25 +09:00
|
|
|
listId: this.list.id
|
|
|
|
});
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-01-30 04:37:25 +09:00
|
|
|
this.$router.push('/my/lists');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-list-page {
|
2020-02-08 15:11:12 +09:00
|
|
|
> .members {
|
2020-01-30 04:37:25 +09:00
|
|
|
> ._content {
|
|
|
|
> .users {
|
|
|
|
> .user {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-10-17 20:12:00 +09:00
|
|
|
padding: 16px;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
flex: 1;
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .acct {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|