2022-09-14 08:43:59 +09:00
|
|
|
<template>
|
2022-09-14 10:57:26 +09:00
|
|
|
<MkStickyContainer>
|
2022-09-14 13:01:31 +09:00
|
|
|
<template #header><MkPageHeader :actions="headerActions"/></template>
|
2022-09-14 12:57:39 +09:00
|
|
|
<MkSpacer :content-max="800" :margin-min="20">
|
2022-11-07 11:49:47 +09:00
|
|
|
<MkButton primary style="margin: 0 auto var(--margin) auto;" @click="create"><i class="ph-plus-bold ph-lg"></i> {{ i18n.ts.createGroup }}</MkButton>
|
2022-09-14 12:57:39 +09:00
|
|
|
<MkPagination v-slot="{items}" ref="owned" :pagination="ownedPagination">
|
|
|
|
<div v-for="group in items" :key="group.id" class="_card">
|
|
|
|
<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>
|
|
|
|
<MkPagination v-slot="{items}" ref="joined" :pagination="joinedPagination">
|
|
|
|
<div v-for="group in items" :key="group.id" class="_card">
|
|
|
|
<div class="_title">{{ group.name }}</div>
|
|
|
|
<div class="_content">
|
|
|
|
<MkAvatars :user-ids="group.userIds"/>
|
|
|
|
</div>
|
|
|
|
<div class="_footer">
|
|
|
|
<MkButton danger @click="leave(group)">{{ i18n.ts.leaveGroup }}</MkButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MkPagination>
|
2022-09-14 10:57:26 +09:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2022-09-14 08:43:59 +09:00
|
|
|
</template>
|
|
|
|
|
2022-09-14 10:57:26 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, ref } from 'vue';
|
2022-09-14 08:47:35 +09:00
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkAvatars from '@/components/MkAvatars.vue';
|
2022-09-14 08:43:59 +09:00
|
|
|
import * as os from '@/os';
|
2022-09-14 10:57:26 +09:00
|
|
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import MkStickyContainer from '@/components/global/MkStickyContainer.vue';
|
2022-09-14 08:43:59 +09:00
|
|
|
|
2022-09-14 10:57:26 +09:00
|
|
|
const owned = ref('owned');
|
|
|
|
const joined = ref('joined');
|
|
|
|
|
|
|
|
const ownedPagination = {
|
|
|
|
endpoint: 'users/groups/owned' as const,
|
2022-09-14 12:57:39 +09:00
|
|
|
limit: 10,
|
2022-09-14 10:57:26 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
const joinedPagination = {
|
|
|
|
endpoint: 'users/groups/joined' as const,
|
2022-09-14 12:57:39 +09:00
|
|
|
limit: 10,
|
2022-09-14 10:57:26 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
const headerActions = $computed(() => [
|
|
|
|
{
|
2022-11-07 11:49:47 +09:00
|
|
|
icon: 'ph-plus-bold ph-lg',
|
2022-09-14 10:57:26 +09:00
|
|
|
text: i18n.ts.createGroup,
|
|
|
|
handler: create,
|
2022-09-14 11:14:28 +09:00
|
|
|
},
|
2022-09-14 10:57:26 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
definePageMetadata(
|
|
|
|
computed(() => ({
|
|
|
|
title: i18n.ts.groups,
|
2022-11-08 05:29:56 +09:00
|
|
|
icon: "ph-users-three-bold ph-lg",
|
2022-09-14 10:57:26 +09:00
|
|
|
})),
|
|
|
|
);
|
|
|
|
|
|
|
|
async function create() {
|
|
|
|
const { canceled, result: name } = await os.inputText({
|
|
|
|
title: i18n.ts.groupName,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.api('users/groups/create', { name: name });
|
|
|
|
owned.value.reload();
|
|
|
|
os.success();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function leave(group) {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('leaveGroupConfirm', { name: group.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
os.apiWithDialog('users/groups/leave', {
|
|
|
|
groupId: group.id,
|
|
|
|
}).then(() => {
|
|
|
|
joined.value.reload();
|
|
|
|
});
|
|
|
|
}
|
2022-09-14 08:43:59 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2022-09-14 08:57:09 +09:00
|
|
|
._card {
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
._title {
|
|
|
|
font-size: 1.2rem;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
._content {
|
|
|
|
margin: 1rem 0;
|
|
|
|
}
|
|
|
|
._footer {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 08:43:59 +09:00
|
|
|
</style>
|