2022-09-14 01:43:59 +02:00
|
|
|
<template>
|
2022-09-14 02:08:09 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader/></template>
|
|
|
|
<div class="mk-group-page">
|
2022-09-14 02:19:34 +02:00
|
|
|
<div class="_section">
|
|
|
|
<div class="_content" style="display: flex; gap: var(--margin); flex-wrap: wrap;">
|
2022-09-14 02:32:43 +02:00
|
|
|
<MkButton inline @click="invite()">{{ i18n.ts.invite }}</MkButton>
|
|
|
|
<MkButton inline @click="renameGroup()">{{ i18n.ts.rename }}</MkButton>
|
|
|
|
<MkButton inline @click="transfer()">{{ i18n.ts.transfer }}</MkButton>
|
|
|
|
<MkButton inline @click="deleteGroup()">{{ i18n.ts.delete }}</MkButton>
|
2022-09-14 01:43:59 +02:00
|
|
|
</div>
|
2022-09-14 02:19:34 +02:00
|
|
|
</div>
|
|
|
|
<div class="_section members _gap">
|
|
|
|
<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>
|
2022-09-14 01:43:59 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-14 02:19:34 +02:00
|
|
|
</div>
|
2022-09-14 02:08:09 +02:00
|
|
|
</div>
|
|
|
|
</MkStickyContainer>
|
2022-09-14 01:43:59 +02:00
|
|
|
</template>
|
|
|
|
|
2022-09-14 02:08:09 +02:00
|
|
|
<script lang="ts" setup>
|
2022-09-14 02:14:56 +02:00
|
|
|
import { computed, watch } from 'vue';
|
2022-09-14 01:47:35 +02:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2022-09-14 02:14:56 +02:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2022-09-14 02:08:09 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2022-09-14 02:32:43 +02:00
|
|
|
import { useRouter } from '@/router';
|
2022-09-14 01:43:59 +02:00
|
|
|
import * as os from '@/os';
|
|
|
|
|
2022-09-14 02:14:56 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
groupId: {
|
2022-09-14 02:16:43 +02:00
|
|
|
type: string,
|
2022-09-14 01:43:59 +02:00
|
|
|
required: true,
|
2022-09-14 02:32:43 +02:00
|
|
|
}
|
2022-09-14 02:14:56 +02:00
|
|
|
}>();
|
2022-09-14 01:43:59 +02:00
|
|
|
|
2022-09-14 02:32:43 +02:00
|
|
|
let users = [];
|
|
|
|
let group = null;
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
2022-09-14 02:14:56 +02:00
|
|
|
watch(() => props.groupId, () => {
|
|
|
|
fetch();
|
2022-09-14 01:43:59 +02:00
|
|
|
});
|
2022-09-14 02:08:09 +02:00
|
|
|
|
2022-09-14 02:35:08 +02:00
|
|
|
|
|
|
|
async function fetch() {
|
2022-09-14 02:14:56 +02:00
|
|
|
os.api('users/groups/show', {
|
2022-09-14 02:32:43 +02:00
|
|
|
groupId: props.groupId,
|
|
|
|
}).then(gp => {
|
|
|
|
group = gp;
|
2022-09-14 02:14:56 +02:00
|
|
|
os.api('users/show', {
|
2022-09-14 02:32:43 +02:00
|
|
|
userIds: group.userIds
|
|
|
|
}).then(us => {
|
|
|
|
users = us;
|
2022-09-14 02:14:56 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-14 02:35:08 +02:00
|
|
|
fetch();
|
|
|
|
|
2022-09-14 02:14:56 +02:00
|
|
|
function invite() {
|
|
|
|
os.selectUser().then(user => {
|
|
|
|
os.apiWithDialog('users/groups/invite', {
|
2022-09-14 02:32:43 +02:00
|
|
|
groupId: group.id,
|
2022-09-14 02:14:56 +02:00
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
});
|
2022-09-14 02:16:27 +02:00
|
|
|
}
|
2022-09-14 02:14:56 +02:00
|
|
|
|
|
|
|
function removeUser(user) {
|
|
|
|
os.api('users/groups/pull', {
|
2022-09-14 02:32:43 +02:00
|
|
|
groupId: group.id,
|
2022-09-14 02:14:56 +02:00
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
2022-09-14 02:32:43 +02:00
|
|
|
users = users.filter(x => x.id !== user.id);
|
2022-09-14 02:14:56 +02:00
|
|
|
});
|
2022-09-14 02:16:27 +02:00
|
|
|
}
|
2022-09-14 02:14:56 +02:00
|
|
|
|
|
|
|
async function renameGroup() {
|
|
|
|
const { canceled, result: name } = await os.inputText({
|
2022-09-14 02:32:43 +02:00
|
|
|
title: i18n.ts.groupName,
|
|
|
|
default: group.name
|
2022-09-14 02:14:56 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await os.api('users/groups/update', {
|
2022-09-14 02:32:43 +02:00
|
|
|
groupId: group.id,
|
2022-09-14 02:14:56 +02:00
|
|
|
name: name
|
|
|
|
});
|
|
|
|
|
2022-09-14 02:32:43 +02:00
|
|
|
group.name = name;
|
2022-09-14 02:16:27 +02:00
|
|
|
}
|
2022-09-14 02:14:56 +02:00
|
|
|
|
|
|
|
function transfer() {
|
|
|
|
os.selectUser().then(user => {
|
|
|
|
os.apiWithDialog('users/groups/transfer', {
|
2022-09-14 02:32:43 +02:00
|
|
|
groupId: group.id,
|
2022-09-14 02:14:56 +02:00
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
});
|
2022-09-14 02:16:27 +02:00
|
|
|
}
|
2022-09-14 02:14:56 +02:00
|
|
|
|
|
|
|
async function deleteGroup() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2022-09-14 02:32:43 +02:00
|
|
|
text: i18n.ts('removeAreYouSure', { x: group.name }),
|
2022-09-14 02:14:56 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await os.apiWithDialog('users/groups/delete', {
|
2022-09-14 02:32:43 +02:00
|
|
|
groupId: group.id,
|
2022-09-14 02:14:56 +02:00
|
|
|
});
|
2022-09-14 02:32:43 +02:00
|
|
|
router.push('/my/groups');
|
2022-09-14 02:14:56 +02:00
|
|
|
}
|
|
|
|
|
2022-09-14 02:08:09 +02:00
|
|
|
definePageMetadata(computed(() => ({
|
|
|
|
title: i18n.ts.members,
|
|
|
|
icon: 'fas fa-users',
|
|
|
|
})));
|
|
|
|
|
2022-09-14 01:43:59 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2022-09-14 02:08:09 +02:00
|
|
|
.mk-group-page {
|
|
|
|
> ._section {
|
|
|
|
> ._content {
|
|
|
|
padding-top: 1rem;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
> .members {
|
|
|
|
> ._content {
|
|
|
|
> .users {
|
|
|
|
> .user {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 16px;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
2022-09-14 01:43:59 +02:00
|
|
|
|
2022-09-14 02:08:09 +02:00
|
|
|
> .body {
|
|
|
|
flex: 1;
|
|
|
|
padding: 8px;
|
2022-09-14 01:43:59 +02:00
|
|
|
|
2022-09-14 02:08:09 +02:00
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
2022-09-14 01:43:59 +02:00
|
|
|
|
2022-09-14 02:08:09 +02:00
|
|
|
> .acct {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
2022-09-14 01:43:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 02:08:09 +02:00
|
|
|
</style>
|