2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2021-10-23 21:03:07 +02:00
|
|
|
<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>
|
2020-02-08 07:11:12 +01:00
|
|
|
</div>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
|
|
|
</transition>
|
2020-02-08 07:11:12 +01:00
|
|
|
|
2021-10-23 21:03:07 +02: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 class="user _panel" v-for="user in users" :key="user.id">
|
|
|
|
<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>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
|
|
|
</transition>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import Progress from '@/scripts/loading';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-01-29 20:37:25 +01:00
|
|
|
components: {
|
|
|
|
MkButton
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: computed(() => this.list ? {
|
2020-11-03 12:36:12 +01:00
|
|
|
title: this.list.name,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-list-ul',
|
2020-10-17 13:12:00 +02:00
|
|
|
} : null),
|
2020-01-29 20:37:25 +01:00
|
|
|
list: null,
|
|
|
|
users: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
$route: 'fetch'
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetch() {
|
|
|
|
Progress.start();
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('users/lists/show', {
|
2020-01-29 20:37:25 +01:00
|
|
|
listId: this.$route.params.list
|
|
|
|
}).then(list => {
|
|
|
|
this.list = list;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('users/show', {
|
2020-01-29 20:37:25 +01:00
|
|
|
userIds: this.list.userIds
|
|
|
|
}).then(users => {
|
|
|
|
this.users = users;
|
|
|
|
Progress.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-02-08 07:11:12 +01:00
|
|
|
addUser() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.selectUser().then(user => {
|
|
|
|
os.apiWithDialog('users/lists/push', {
|
2020-02-08 07:11:12 +01:00
|
|
|
listId: this.list.id,
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
this.users.push(user);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
removeUser(user) {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('users/lists/pull', {
|
2020-01-29 20:37:25 +01:00
|
|
|
listId: this.list.id,
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
this.users = this.users.filter(x => x.id !== user.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
async renameList() {
|
2021-11-18 10:45:58 +01:00
|
|
|
const { canceled, result: name } = await os.inputText({
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.enterListName,
|
2021-11-18 10:45:58 +01:00
|
|
|
default: this.list.name
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
await os.api('users/lists/update', {
|
2020-01-29 20:37:25 +01:00
|
|
|
listId: this.list.id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
|
|
|
|
this.list.name = name;
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteList() {
|
2021-11-18 10:45:58 +01:00
|
|
|
const { canceled } = await os.confirm({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'warning',
|
2020-02-08 07:11:12 +01:00
|
|
|
text: this.$t('removeAreYouSure', { x: this.list.name }),
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
await os.api('users/lists/delete', {
|
2020-01-29 20:37:25 +01:00
|
|
|
listId: this.list.id
|
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
os.success();
|
2020-01-29 20:37:25 +01:00
|
|
|
this.$router.push('/my/lists');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-list-page {
|
2020-02-08 07:11:12 +01:00
|
|
|
> .members {
|
2020-01-29 20:37:25 +01:00
|
|
|
> ._content {
|
|
|
|
> .users {
|
|
|
|
> .user {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-10-17 13:12:00 +02:00
|
|
|
padding: 16px;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
flex: 1;
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .acct {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|