1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-24 03:28:27 +09:00
MisskeyIO/packages/frontend/src/pages/my-lists/list.vue

163 lines
3.6 KiB
Vue
Raw Normal View History

2022-07-20 22:24:26 +09:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
2023-03-02 20:47:24 +09:00
<MkSpacer :content-max="700" :class="$style.main">
<div v-if="list" class="members _margin">
<div class="">{{ i18n.ts.members }}</div>
<div class="_gaps_s">
<div v-for="user in users" :key="user.id" :class="$style.userItem">
<MkA :class="$style.userItemBody" :to="`${userPage(user)}`">
<MkUserCardMini :user="user"/>
</MkA>
<button class="_button" :class="$style.remove" @click="removeUser(user, $event)"><i class="ti ti-x"></i></button>
2021-12-02 20:09:12 +09:00
</div>
2023-03-02 20:47:24 +09:00
</div>
2022-07-20 22:24:26 +09:00
</div>
</MkSpacer>
2023-03-02 20:47:24 +09:00
<template #footer>
<div :class="$style.footer">
<MkSpacer :content-max="700" :margin-min="16" :margin-max="16">
<div class="_buttons">
<MkButton inline rounded primary @click="addUser()">{{ i18n.ts.addUser }}</MkButton>
<MkButton inline rounded @click="renameList()">{{ i18n.ts.rename }}</MkButton>
<MkButton inline rounded danger @click="deleteList()">{{ i18n.ts.delete }}</MkButton>
</div>
</MkSpacer>
</div>
</template>
2022-07-20 22:24:26 +09:00
</MkStickyContainer>
</template>
<script lang="ts" setup>
2022-07-20 22:24:26 +09:00
import { computed, watch } from 'vue';
import MkButton from '@/components/MkButton.vue';
2021-11-12 02:02:25 +09:00
import * as os from '@/os';
import { mainRouter } from '@/router';
import { definePageMetadata } from '@/scripts/page-metadata';
2022-07-04 23:33:55 +09:00
import { i18n } from '@/i18n';
2023-03-01 14:22:53 +09:00
import { userPage } from '@/filters/user';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
2023-03-24 16:58:57 +09:00
import { userListsCache } from '@/cache';
const props = defineProps<{
listId: string;
}>();
let list = $ref(null);
let users = $ref([]);
function fetchList() {
os.api('users/lists/show', {
listId: props.listId,
}).then(_list => {
list = _list;
os.api('users/show', {
userIds: list.userIds,
}).then(_users => {
users = _users;
});
});
}
function addUser() {
os.selectUser().then(user => {
os.apiWithDialog('users/lists/push', {
listId: list.id,
userId: user.id,
}).then(() => {
users.push(user);
});
});
}
2023-03-01 14:22:53 +09:00
async function removeUser(user, ev) {
os.popupMenu([{
text: i18n.ts.remove,
icon: 'ti ti-x',
danger: true,
action: async () => {
os.api('users/lists/pull', {
listId: list.id,
userId: user.id,
}).then(() => {
users = users.filter(x => x.id !== user.id);
});
},
}], ev.currentTarget ?? ev.target);
}
async function renameList() {
const { canceled, result: name } = await os.inputText({
title: i18n.ts.enterListName,
default: list.name,
});
if (canceled) return;
await os.api('users/lists/update', {
listId: list.id,
name: name,
});
2023-03-24 16:58:57 +09:00
userListsCache.delete();
list.name = name;
}
async function deleteList() {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.t('removeAreYouSure', { x: list.name }),
});
if (canceled) return;
2023-03-24 16:58:57 +09:00
await os.apiWithDialog('users/lists/delete', {
listId: list.id,
});
2023-03-24 16:58:57 +09:00
userListsCache.delete();
mainRouter.push('/my/lists');
}
watch(() => props.listId, fetchList, { immediate: true });
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
definePageMetadata(computed(() => list ? {
title: list.name,
icon: 'ti ti-list',
} : null));
</script>
2023-03-01 14:22:53 +09:00
<style lang="scss" module>
2023-03-02 20:47:24 +09:00
.main {
2023-03-03 08:48:52 +09:00
min-height: calc(var(--containerHeight) - (var(--stickyTop, 0px) + var(--stickyBottom, 0px)));
2023-03-02 20:47:24 +09:00
}
2023-03-01 14:22:53 +09:00
.userItem {
display: flex;
}
.userItemBody {
flex: 1;
min-width: 0;
margin-right: 8px;
&:hover {
text-decoration: none;
}
}
2023-03-01 14:22:53 +09:00
.remove {
width: 32px;
height: 32px;
align-self: center;
}
2023-03-02 20:47:24 +09:00
.footer {
-webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px));
border-top: solid 0.5px var(--divider);
}
</style>