egirlskey/packages/frontend/src/pages/my-lists/list.vue

234 lines
5.9 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
2022-07-20 13:24:26 +00:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :contentMax="700" :class="$style.main">
<div v-if="list" class="_gaps">
<MkFolder>
<template #label>{{ i18n.ts.settings }}</template>
<div class="_gaps">
<MkInput v-model="name">
<template #label>{{ i18n.ts.name }}</template>
</MkInput>
<MkSwitch v-model="isPublic">{{ i18n.ts.public }}</MkSwitch>
<div class="_buttons">
<MkButton rounded primary @click="updateSettings">{{ i18n.ts.save }}</MkButton>
<MkButton rounded danger @click="deleteList()">{{ i18n.ts.delete }}</MkButton>
</div>
2021-12-02 11:09:12 +00:00
</div>
</MkFolder>
<MkFolder defaultOpen>
<template #label>{{ i18n.ts.members }}</template>
<template #caption>{{ i18n.t('nUsers', { n: `${list.userIds.length}/${$i?.policies['userEachUserListsLimit']}` }) }}</template>
<div class="_gaps_s">
<MkButton rounded primary style="margin: 0 auto;" @click="addUser()">{{ i18n.ts.addUser }}</MkButton>
2023-10-03 11:26:11 +00:00
<MkPagination ref="paginationEl" :pagination="membershipsPagination">
<template #default="{ items }">
<div class="_gaps_s">
<div v-for="item in items" :key="item.id">
<div :class="$style.userItem">
<MkA :class="$style.userItemBody" :to="`${userPage(item.user)}`">
<MkUserCardMini :user="item.user"/>
</MkA>
<button class="_button" :class="$style.menu" @click="showMembershipMenu(item, $event)"><i class="ph-dots-three ph-bold ph-lg"></i></button>
<button class="_button" :class="$style.remove" @click="removeUser(item, $event)"><i class="ph-x ph-bold ph-lg"></i></button>
</div>
</div>
</div>
</template>
</MkPagination>
2023-03-02 11:47:24 +00:00
</div>
</MkFolder>
2023-03-02 11:47:24 +00:00
</div>
</MkSpacer>
2022-07-20 13:24:26 +00:00
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import * as Misskey from 'misskey-js';
import MkButton from '@/components/MkButton.vue';
2023-09-19 07:37:43 +00:00
import * as os from '@/os.js';
import { mainRouter } from '@/router.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import { userPage } from '@/filters/user.js';
2023-03-01 05:22:53 +00:00
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import MkFolder from '@/components/MkFolder.vue';
import MkInput from '@/components/MkInput.vue';
2023-10-03 11:26:11 +00:00
import { userListsCache } from '@/cache.js';
2023-09-19 07:37:43 +00:00
import { $i } from '@/account.js';
import { defaultStore } from '@/store.js';
2023-10-03 11:26:11 +00:00
import MkPagination, { Paging } from '@/components/MkPagination.vue';
const {
enableInfiniteScroll,
} = defaultStore.reactiveState;
const props = defineProps<{
listId: string;
}>();
2023-10-03 11:26:11 +00:00
const paginationEl = ref<InstanceType<typeof MkPagination>>();
let list = $ref<Misskey.entities.UserList | null>(null);
const isPublic = ref(false);
const name = ref('');
2023-10-03 11:26:11 +00:00
const membershipsPagination = {
endpoint: 'users/lists/get-memberships' as const,
limit: 30,
params: computed(() => ({
listId: props.listId,
})),
};
function fetchList() {
os.api('users/lists/show', {
listId: props.listId,
}).then(_list => {
list = _list;
name.value = list.name;
isPublic.value = list.isPublic;
});
}
function addUser() {
os.selectUser().then(user => {
if (!list) return;
os.apiWithDialog('users/lists/push', {
listId: list.id,
userId: user.id,
}).then(() => {
2023-10-03 11:26:11 +00:00
paginationEl.value.reload();
});
});
}
2023-10-03 11:26:11 +00:00
async function removeUser(item, ev) {
2023-03-01 05:22:53 +00:00
os.popupMenu([{
text: i18n.ts.remove,
2023-09-30 19:53:52 +00:00
icon: 'ph-x ph-bold ph-lg',
2023-03-01 05:22:53 +00:00
danger: true,
action: async () => {
if (!list) return;
2023-03-01 05:22:53 +00:00
os.api('users/lists/pull', {
listId: list.id,
2023-10-03 11:26:11 +00:00
userId: item.userId,
}).then(() => {
paginationEl.value.removeItem(item.id);
});
},
}], ev.currentTarget ?? ev.target);
}
async function showMembershipMenu(item, ev) {
os.popupMenu([{
text: item.withReplies ? i18n.ts.hideRepliesToOthersInTimeline : i18n.ts.showRepliesToOthersInTimeline,
2023-10-13 17:07:41 +00:00
icon: item.withReplies ? 'ph-envelope-open ph-bold ph-lg' : 'ph-envelope ph-bold ph-lg',
2023-10-03 11:26:11 +00:00
action: async () => {
os.api('users/lists/update-membership', {
listId: list.id,
userId: item.userId,
withReplies: !item.withReplies,
2023-03-01 05:22:53 +00:00
}).then(() => {
2023-10-03 11:26:11 +00:00
paginationEl.value.updateItem(item.id, (old) => ({
...old,
withReplies: !item.withReplies,
}));
2023-03-01 05:22:53 +00:00
});
},
}], ev.currentTarget ?? ev.target);
}
async function deleteList() {
if (!list) return;
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.t('removeAreYouSure', { x: list.name }),
});
if (canceled) return;
2023-03-24 07:58:57 +00:00
await os.apiWithDialog('users/lists/delete', {
listId: list.id,
});
2023-03-24 07:58:57 +00:00
userListsCache.delete();
mainRouter.push('/my/lists');
}
async function updateSettings() {
if (!list) return;
await os.apiWithDialog('users/lists/update', {
listId: list.id,
name: name.value,
isPublic: isPublic.value,
});
userListsCache.delete();
list.name = name.value;
list.isPublic = isPublic.value;
}
watch(() => props.listId, fetchList, { immediate: true });
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
definePageMetadata(computed(() => list ? {
title: list.name,
2023-09-30 19:53:52 +00:00
icon: 'ph-list ph-bold pg-lg',
} : null));
</script>
2023-03-01 05:22:53 +00:00
<style lang="scss" module>
2023-03-02 11:47:24 +00:00
.main {
2023-05-08 09:30:40 +00:00
min-height: calc(100cqh - (var(--stickyTop, 0px) + var(--stickyBottom, 0px)));
2023-03-02 11:47:24 +00:00
}
2023-03-01 05:22:53 +00:00
.userItem {
display: flex;
}
.userItemBody {
flex: 1;
min-width: 0;
margin-right: 8px;
&:hover {
text-decoration: none;
}
}
2023-03-01 05:22:53 +00:00
.remove {
width: 32px;
height: 32px;
align-self: center;
}
2023-03-02 11:47:24 +00:00
2023-10-03 11:26:11 +00:00
.menu {
width: 32px;
height: 32px;
align-self: center;
}
.more {
margin-left: auto;
margin-right: auto;
}
2023-03-02 11:47:24 +00:00
.footer {
-webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px));
border-top: solid 0.5px var(--divider);
}
</style>