egirlskey/packages/frontend/src/pages/list.vue

156 lines
3.9 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 07:20:53 +00:00
<MKSpacer v-if="!(typeof error === 'undefined')" :contentMax="1200">
<div :class="$style.root">
<img :class="$style.img" :src="serverErrorImageUrl" class="_ghost"/>
<p :class="$style.text">
2023-09-30 19:53:52 +00:00
<i class="ph-warning ph-bold ph-lg"></i>
{{ i18n.ts.nothing }}
</p>
</div>
</MKSpacer>
2023-05-19 07:20:53 +00:00
<MkSpacer v-else-if="list" :contentMax="700" :class="$style.main">
<div v-if="list" class="members _margin">
<div :class="$style.member_text">{{ 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>
</div>
</div>
</div>
2023-09-30 19:53:52 +00:00
<MkButton v-if="list.isLiked" v-tooltip="i18n.ts.unlike" inline :class="$style.button" asLike primary @click="unlike()"><i class="ph-heart-break ph-bold ph-lg"></i><span v-if="list.likedCount > 0" class="count">{{ list.likedCount }}</span></MkButton>
<MkButton v-if="!list.isLiked" v-tooltip="i18n.ts.like" inline :class="$style.button" asLike @click="like()"><i class="ph-heart ph-bold ph-lg"></i><span v-if="1 > 0" class="count">{{ list.likedCount }}</span></MkButton>
<MkButton inline @click="create()"><i class="ph-download ph-bold ph-lg" :class="$style.import"></i>{{ i18n.ts.import }}</MkButton>
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { watch, computed, ref } from 'vue';
import * as Misskey from 'misskey-js';
2023-09-19 07:37:43 +00:00
import * as os from '@/os.js';
import { userPage } from '@/filters/user.js';
import { i18n } from '@/i18n.js';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import MkButton from '@/components/MkButton.vue';
2023-09-19 07:37:43 +00:00
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { serverErrorImageUrl } from '@/instance.js';
const props = defineProps<{
listId: string;
}>();
const list = ref<Misskey.entities.UserList | null>(null);
const error = ref();
const users = ref<Misskey.entities.UserDetailed[]>([]);
function fetchList(): void {
os.api('users/lists/show', {
listId: props.listId,
forPublic: true,
}).then(_list => {
list.value = _list;
os.api('users/show', {
userIds: list.value.userIds,
}).then(_users => {
users.value = _users;
});
}).catch(err => {
error.value = err;
});
}
function like() {
os.apiWithDialog('users/lists/favorite', {
listId: list.value.id,
}).then(() => {
list.value.isLiked = true;
list.value.likedCount++;
});
}
function unlike() {
os.apiWithDialog('users/lists/unfavorite', {
listId: list.value.id,
}).then(() => {
list.value.isLiked = false;
list.value.likedCount--;
});
}
async function create() {
const { canceled, result: name } = await os.inputText({
title: i18n.ts.enterListName,
});
if (canceled) return;
await os.apiWithDialog('users/lists/create-from-public', { name: name, listId: list.value.id });
}
watch(() => props.listId, fetchList, { immediate: true });
const headerActions = computed(() => []);
const headerTabs = computed(() => []);
definePageMetadata(computed(() => list.value ? {
title: list.value.name,
icon: 'ph-list ph-bold ph-lg',
} : null));
</script>
<style lang="scss" module>
.main {
min-height: calc(100cqh - (var(--stickyTop, 0px) + var(--stickyBottom, 0px)));
}
.userItem {
display: flex;
}
.userItemBody {
flex: 1;
min-width: 0;
margin-right: 8px;
&:hover {
text-decoration: none;
}
}
.member_text {
margin: 5px;
}
.root {
padding: 32px;
text-align: center;
align-items: center;
}
.text {
margin: 0 0 8px 0;
}
.img {
vertical-align: bottom;
width: 128px;
height: 128px;
margin-bottom: 16px;
border-radius: var(--radius-md);
}
.button {
margin-right: 10px;
}
.import {
margin-right: 4px;
}
</style>