refactoring

Resolve #7779
This commit is contained in:
syuilo
2021-11-12 02:02:25 +09:00
parent 037837b551
commit 0e4a111f81
1714 changed files with 20803 additions and 11751 deletions

View File

@ -0,0 +1,184 @@
<template>
<div class="mk-group-page">
<transition name="zoom" mode="out-in">
<div v-if="group" class="_section">
<div class="_content">
<MkButton inline @click="invite()">{{ $ts.invite }}</MkButton>
<MkButton inline @click="renameGroup()">{{ $ts.rename }}</MkButton>
<MkButton inline @click="transfer()">{{ $ts.transfer }}</MkButton>
<MkButton inline @click="deleteGroup()">{{ $ts.delete }}</MkButton>
</div>
</div>
</transition>
<transition name="zoom" mode="out-in">
<div v-if="group" 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>
</div>
</div>
</div>
</div>
</div>
</transition>
</div>
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue';
import Progress from '@/scripts/loading';
import MkButton from '@/components/ui/button.vue';
import * as os from '@/os';
import * as symbols from '@/symbols';
export default defineComponent({
components: {
MkButton
},
props: {
groupId: {
type: String,
required: true,
},
},
data() {
return {
[symbols.PAGE_INFO]: computed(() => this.group ? {
title: this.group.name,
icon: 'fas fa-users',
} : null),
group: null,
users: [],
};
},
watch: {
groupId: 'fetch',
},
created() {
this.fetch();
},
methods: {
fetch() {
Progress.start();
os.api('users/groups/show', {
groupId: this.groupId
}).then(group => {
this.group = group;
os.api('users/show', {
userIds: this.group.userIds
}).then(users => {
this.users = users;
Progress.done();
});
});
},
invite() {
os.selectUser().then(user => {
os.apiWithDialog('users/groups/invite', {
groupId: this.group.id,
userId: user.id
});
});
},
removeUser(user) {
os.api('users/groups/pull', {
groupId: this.group.id,
userId: user.id
}).then(() => {
this.users = this.users.filter(x => x.id !== user.id);
});
},
async renameGroup() {
const { canceled, result: name } = await os.dialog({
title: this.$ts.groupName,
input: {
default: this.group.name
}
});
if (canceled) return;
await os.api('users/groups/update', {
groupId: this.group.id,
name: name
});
this.group.name = name;
},
transfer() {
os.selectUser().then(user => {
os.apiWithDialog('users/groups/transfer', {
groupId: this.group.id,
userId: user.id
});
});
},
async deleteGroup() {
const { canceled } = await os.dialog({
type: 'warning',
text: this.$t('removeAreYouSure', { x: this.group.name }),
showCancelButton: true
});
if (canceled) return;
await os.apiWithDialog('users/groups/delete', {
groupId: this.group.id
});
this.$router.push('/my/groups');
}
}
});
</script>
<style lang="scss" scoped>
.mk-group-page {
> .members {
> ._content {
> .users {
> .user {
display: flex;
align-items: center;
padding: 16px;
> .avatar {
width: 50px;
height: 50px;
}
> .body {
flex: 1;
padding: 8px;
> .name {
display: block;
font-weight: bold;
}
> .acct {
opacity: 0.5;
}
}
}
}
}
}
}
</style>

View File

@ -0,0 +1,121 @@
<template>
<div class="">
<div class="_section" style="padding: 0;">
<MkTab v-model="tab">
<option value="owned">{{ $ts.ownedGroups }}</option>
<option value="joined">{{ $ts.joinedGroups }}</option>
<option value="invites"><i class="fas fa-envelope-open-text"></i> {{ $ts.invites }}</option>
</MkTab>
</div>
<div class="_section">
<div class="_content" v-if="tab === 'owned'">
<MkButton @click="create" primary style="margin: 0 auto var(--margin) auto;"><i class="fas fa-plus"></i> {{ $ts.createGroup }}</MkButton>
<MkPagination :pagination="ownedPagination" #default="{items}" ref="owned">
<div class="_card" v-for="group in items" :key="group.id">
<div class="_title"><MkA :to="`/my/groups/${ group.id }`" class="_link">{{ group.name }}</MkA></div>
<div class="_content"><MkAvatars :user-ids="group.userIds"/></div>
</div>
</MkPagination>
</div>
<div class="_content" v-else-if="tab === 'joined'">
<MkPagination :pagination="joinedPagination" #default="{items}" ref="joined">
<div class="_card" v-for="group in items" :key="group.id">
<div class="_title">{{ group.name }}</div>
<div class="_content"><MkAvatars :user-ids="group.userIds"/></div>
</div>
</MkPagination>
</div>
<div class="_content" v-else-if="tab === 'invites'">
<MkPagination :pagination="invitationPagination" #default="{items}" ref="invitations">
<div class="_card" v-for="invitation in items" :key="invitation.id">
<div class="_title">{{ invitation.group.name }}</div>
<div class="_content"><MkAvatars :user-ids="invitation.group.userIds"/></div>
<div class="_footer">
<MkButton @click="acceptInvite(invitation)" primary inline><i class="fas fa-check"></i> {{ $ts.accept }}</MkButton>
<MkButton @click="rejectInvite(invitation)" primary inline><i class="fas fa-ban"></i> {{ $ts.reject }}</MkButton>
</div>
</div>
</MkPagination>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import MkPagination from '@/components/ui/pagination.vue';
import MkButton from '@/components/ui/button.vue';
import MkContainer from '@/components/ui/container.vue';
import MkAvatars from '@/components/avatars.vue';
import MkTab from '@/components/tab.vue';
import * as os from '@/os';
import * as symbols from '@/symbols';
export default defineComponent({
components: {
MkPagination,
MkButton,
MkContainer,
MkTab,
MkAvatars,
},
data() {
return {
[symbols.PAGE_INFO]: {
title: this.$ts.groups,
icon: 'fas fa-users'
},
tab: 'owned',
ownedPagination: {
endpoint: 'users/groups/owned',
limit: 10,
},
joinedPagination: {
endpoint: 'users/groups/joined',
limit: 10,
},
invitationPagination: {
endpoint: 'i/user-group-invites',
limit: 10,
},
};
},
methods: {
async create() {
const { canceled, result: name } = await os.dialog({
title: this.$ts.groupName,
input: true
});
if (canceled) return;
await os.api('users/groups/create', { name: name });
this.$refs.owned.reload();
os.success();
},
acceptInvite(invitation) {
os.api('users/groups/invitations/accept', {
invitationId: invitation.id
}).then(() => {
os.success();
this.$refs.invitations.reload();
this.$refs.joined.reload();
});
},
rejectInvite(invitation) {
os.api('users/groups/invitations/reject', {
invitationId: invitation.id
}).then(() => {
this.$refs.invitations.reload();
});
}
}
});
</script>
<style lang="scss" scoped>
</style>