iceshrimp/packages/client/src/pages/my-groups/index.vue

107 lines
2.7 KiB
Vue
Raw Normal View History

<template>
<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>
</MkSpacer>
</MkStickyContainer>
</template>
<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';
import * as os from '@/os';
import { definePageMetadata } from "@/scripts/page-metadata";
import { i18n } from '@/i18n';
import MkStickyContainer from '@/components/global/MkStickyContainer.vue';
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,
};
const joinedPagination = {
endpoint: 'users/groups/joined' as const,
2022-09-14 12:57:39 +09:00
limit: 10,
};
const headerActions = $computed(() => [
{
2022-11-07 11:49:47 +09:00
icon: 'ph-plus-bold ph-lg',
text: i18n.ts.createGroup,
handler: create,
},
]);
definePageMetadata(
computed(() => ({
title: i18n.ts.groups,
2022-11-07 11:49:47 +09:00
icon: "ph-users-bold ph-lg",
})),
);
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();
});
}
</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;
}
}
</style>