2022-06-20 11:38:49 +03:00
|
|
|
<template><MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="700">
|
2021-12-02 13:09:12 +02:00
|
|
|
<div class="mk-list-page">
|
2022-01-25 16:18:21 +02:00
|
|
|
<transition :name="$store.state.animation ? 'zoom' : ''" mode="out-in">
|
2021-12-02 13:09:12 +02:00
|
|
|
<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 08:11:12 +02:00
|
|
|
</div>
|
2021-12-02 13:09:12 +02:00
|
|
|
</transition>
|
2020-02-08 08:11:12 +02:00
|
|
|
|
2022-01-25 16:18:21 +02:00
|
|
|
<transition :name="$store.state.animation ? 'zoom' : ''" mode="out-in">
|
2021-12-02 13:09:12 +02:00
|
|
|
<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-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-02 13:09:12 +02:00
|
|
|
</transition>
|
|
|
|
</div>
|
2022-06-20 11:38:49 +03:00
|
|
|
</MkSpacer></MkStickyContainer>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 11:38:49 +03:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, defineComponent, watch } from 'vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import * as os from '@/os';
|
2022-06-20 11:38:49 +03:00
|
|
|
import { mainRouter } from '@/router';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
listId: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let list = $ref(null);
|
|
|
|
let users = $ref([]);
|
|
|
|
|
|
|
|
function fetchList() {
|
|
|
|
os.api('users/lists/show', {
|
|
|
|
listId: props.listId,
|
|
|
|
}).then(_list => {
|
|
|
|
list = _list;
|
|
|
|
os.api('users/show', {
|
|
|
|
userIds: list.userIds,
|
|
|
|
}).then(_users => {
|
|
|
|
users = _users;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addUser() {
|
|
|
|
os.selectUser().then(user => {
|
|
|
|
os.apiWithDialog('users/lists/push', {
|
|
|
|
listId: list.id,
|
|
|
|
userId: user.id,
|
|
|
|
}).then(() => {
|
|
|
|
users.push(user);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeUser(user) {
|
|
|
|
os.api('users/lists/pull', {
|
|
|
|
listId: list.id,
|
|
|
|
userId: user.id,
|
|
|
|
}).then(() => {
|
|
|
|
users = users.filter(x => x.id !== user.id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function renameList() {
|
|
|
|
const { canceled, result: name } = await os.inputText({
|
|
|
|
title: i18n.ts.enterListName,
|
|
|
|
default: list.name,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await os.api('users/lists/update', {
|
|
|
|
listId: list.id,
|
|
|
|
name: name,
|
|
|
|
});
|
|
|
|
|
|
|
|
list.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteList() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('removeAreYouSure', { x: list.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await os.api('users/lists/delete', {
|
|
|
|
listId: list.id,
|
|
|
|
});
|
|
|
|
os.success();
|
|
|
|
mainRouter.push('/my/lists');
|
|
|
|
}
|
|
|
|
|
|
|
|
watch(() => props.listId, fetchList, { immediate: true });
|
|
|
|
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => list ? {
|
|
|
|
title: list.name,
|
|
|
|
icon: 'fas fa-list-ul',
|
|
|
|
} : null));
|
2020-01-29 21:37:25 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-list-page {
|
2020-02-08 08:11:12 +02:00
|
|
|
> .members {
|
2020-01-29 21:37:25 +02:00
|
|
|
> ._content {
|
|
|
|
> .users {
|
|
|
|
> .user {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-10-17 14:12:00 +03:00
|
|
|
padding: 16px;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
flex: 1;
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .acct {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|