1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2025-01-11 04:13:31 +09:00
cherrypick/packages/frontend/src/pages/my-groups/index.vue

189 lines
4.7 KiB
Vue
Raw Normal View History

2022-07-14 17:38:11 +09:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
2023-06-04 15:37:50 +09:00
<MkSpacer :contentMax="700">
2023-06-17 03:12:13 +09:00
<div v-if="tab === 'owned'">
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="ownedPagination">
<MkA v-for="group in items" :key="group.id" :class="$style.group" class="_panel" :to="`/my/groups/${ group.id }`">
<div :class="$style.name">{{ group.name }}</div>
<MkAvatars :class="$style.avatars" :userIds="group.userIds"/>
</MkA>
</MkPagination>
</div>
2023-06-17 03:12:13 +09:00
<div v-else-if="tab === 'joined'">
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="joinedPagination">
<div v-for="group in items" :class="$style.group" class="_panel">
<MkA :key="group.id" :class="$style.groupTop" :to="`/my/groups/${ group.id }`">
<div :class="$style.name">{{ group.name }}</div>
<MkAvatars :class="$style.avatars" :userIds="group.userIds"/>
</MkA>
2023-06-17 03:12:13 +09:00
<div :class="$style.actions">
<MkButton rounded danger @click="leave(group)">{{ i18n.ts.leaveGroup }}</MkButton>
</div>
</div>
</MkPagination>
</div>
2023-06-17 03:12:13 +09:00
<div v-else-if="tab === 'invites'">
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="invitationPagination">
2023-06-17 03:12:13 +09:00
<MkA v-for="invitation in items" :key="invitation.id" :class="$style.group" class="_panel">
<div :class="$style.name">{{ invitation.group.name }}</div>
<MkAvatars :class="$style.avatars" :userIds="invitation.group.userIds"/>
2023-06-17 03:12:13 +09:00
<div :class="$style.actions">
<MkButton primary rounded inline :class="$style.invitesButton" @click="acceptInvite(invitation)"><i class="ti ti-check"></i> {{ i18n.ts.accept }}</MkButton>
<MkButton rounded inline :class="$style.invitesButton" @click="rejectInvite(invitation)"><i class="ti ti-x"></i> {{ i18n.ts.reject }}</MkButton>
</div>
</MkA>
</MkPagination>
</div>
</MkSpacer>
</MkStickyContainer>
2022-07-14 17:38:11 +09:00
</template>
<script lang="ts" setup>
2023-02-10 22:29:15 +09:00
import { } from 'vue';
import MkPagination from '@/components/MkPagination.vue';
import MkButton from '@/components/MkButton.vue';
import MkAvatars from '@/components/MkAvatars.vue';
2022-07-14 17:38:11 +09:00
import * as os from '@/os';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
const pagingComponent = $ref<InstanceType<typeof MkPagination>>();
const ownedPagination = {
endpoint: 'users/groups/owned' as const,
limit: 10,
// sort: '+createdAt/updatedAt',
};
const joinedPagination = {
endpoint: 'users/groups/joined' as const,
limit: 10,
};
const invitationPagination = {
endpoint: 'i/user-group-invites' as const,
limit: 10,
};
let tab = $ref('owned');
async function create() {
const { canceled, result: name } = await os.inputText({
title: i18n.ts.groupName,
});
if (canceled) return;
await os.apiWithDialog('users/groups/create', { name: name });
pagingComponent.reload();
}
async function acceptInvite(invitation) {
os.apiWithDialog('users/groups/invitations/accept', {
invitationId: invitation.id,
}).then(() => {
os.success();
pagingComponent.reload();
});
}
function rejectInvite(invitation) {
os.apiWithDialog('users/groups/invitations/reject', {
invitationId: invitation.id,
}).then(() => {
pagingComponent.reload();
// this.$refs.invitations.reload();
});
}
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(() => {
pagingComponent.reload();
});
}
const headerActions = $computed(() => [{
icon: 'ti ti-plus',
text: i18n.ts.createGroup,
handler: create,
}]);
const headerTabs = $computed(() => [{
key: 'owned',
title: i18n.ts.ownedGroups,
2023-02-10 22:29:15 +09:00
icon: 'ti ti-flag',
}, {
key: 'joined',
title: i18n.ts.joinedGroups,
icon: 'ti ti-id-badge',
}, {
key: 'invites',
title: i18n.ts.invites,
2023-02-10 22:29:15 +09:00
icon: 'ti ti-mail-opened',
}]);
2023-02-10 20:19:16 +09:00
definePageMetadata({
title: i18n.ts.groups,
2023-02-10 22:29:15 +09:00
icon: 'ti ti-users',
actions: [{
icon: 'ti ti-plus',
text: i18n.ts.createGroup,
handler: create,
}],
2022-07-14 17:38:11 +09:00
});
2022-07-14 17:38:11 +09:00
</script>
2023-06-17 03:12:13 +09:00
<style lang="scss" module>
.actions {
display: flex;
justify-content: flex-end;
2023-06-17 03:12:13 +09:00
margin-top: 10px;
padding: 0 24px 16px;
2023-06-17 03:12:13 +09:00
}
.add {
margin: 0 auto var(--margin) auto;
}
.group {
display: block;
border: solid 1px var(--divider);
border-radius: 6px;
&:hover {
border: solid 1px var(--accent);
text-decoration: none;
2023-02-10 22:29:15 +09:00
}
2023-06-17 03:12:13 +09:00
}
.groupTop {
&:hover {
text-decoration: none;
}
}
2023-06-17 03:12:13 +09:00
.name {
margin-bottom: 12px;
border-bottom: solid 1px var(--divider);
padding: 16px 24px;
font-weight: bold;
}
.avatars {
padding: 8px 24px 16px;
2023-06-17 03:12:13 +09:00
}
2023-02-10 22:29:15 +09:00
2023-06-17 03:12:13 +09:00
.invitesButton {
&:not(:last-child) {
margin-right: 5px;
2023-02-10 22:29:15 +09:00
}
}
2022-07-14 17:38:11 +09:00
</style>