Sharkey/packages/frontend/src/pages/user/index.vue

129 lines
3.7 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkStickyContainer>
2022-07-01 12:55:45 +03:00
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
<div>
2023-05-24 11:50:15 +03:00
<div v-if="user">
<XHome v-if="tab === 'home'" :user="user"/>
<XTimeline v-else-if="tab === 'notes'" :user="user"/>
<XActivity v-else-if="tab === 'activity'" :user="user"/>
<XAchievements v-else-if="tab === 'achievements'" :user="user"/>
<XReactions v-else-if="tab === 'reactions'" :user="user"/>
<XClips v-else-if="tab === 'clips'" :user="user"/>
<XLists v-else-if="tab === 'lists'" :user="user"/>
<XPages v-else-if="tab === 'pages'" :user="user"/>
<XFlashs v-else-if="tab === 'flashs'" :user="user"/>
2023-05-24 11:50:15 +03:00
<XGallery v-else-if="tab === 'gallery'" :user="user"/>
</div>
<MkError v-else-if="error" @retry="fetchUser()"/>
<MkLoading v-else/>
</div>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { defineAsyncComponent, computed, watch } from 'vue';
import * as Misskey from 'misskey-js';
2023-09-19 10:37:43 +03:00
import { acct as getAcct } from '@/filters/user.js';
import * as os from '@/os.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import { $i } from '@/account.js';
2022-07-01 12:55:45 +03:00
const XHome = defineAsyncComponent(() => import('./home.vue'));
const XTimeline = defineAsyncComponent(() => import('./index.timeline.vue'));
2023-01-02 03:18:47 +02:00
const XActivity = defineAsyncComponent(() => import('./activity.vue'));
const XAchievements = defineAsyncComponent(() => import('./achievements.vue'));
const XReactions = defineAsyncComponent(() => import('./reactions.vue'));
const XClips = defineAsyncComponent(() => import('./clips.vue'));
const XLists = defineAsyncComponent(() => import('./lists.vue'));
const XPages = defineAsyncComponent(() => import('./pages.vue'));
const XFlashs = defineAsyncComponent(() => import('./flashs.vue'));
const XGallery = defineAsyncComponent(() => import('./gallery.vue'));
const props = withDefaults(defineProps<{
acct: string;
page?: string;
}>(), {
2022-07-01 12:55:45 +03:00
page: 'home',
});
2022-07-01 12:55:45 +03:00
let tab = $ref(props.page);
let user = $ref<null | Misskey.entities.UserDetailed>(null);
let error = $ref(null);
function fetchUser(): void {
if (props.acct == null) return;
user = null;
os.api('users/show', Misskey.acct.parse(props.acct)).then(u => {
user = u;
}).catch(err => {
error = err;
});
}
watch(() => props.acct, fetchUser, {
immediate: true,
});
const headerActions = $computed(() => []);
const headerTabs = $computed(() => user ? [{
2022-07-01 12:55:45 +03:00
key: 'home',
title: i18n.ts.overview,
2023-09-30 22:53:52 +03:00
icon: 'ph-house ph-bold ph-lg',
}, {
key: 'notes',
title: i18n.ts.notes,
2023-09-30 22:53:52 +03:00
icon: 'ph-pencil ph-bold ph-lg',
2023-01-02 03:18:47 +02:00
}, {
key: 'activity',
title: i18n.ts.activity,
2023-10-01 01:46:42 +03:00
icon: 'ph-chart-line ph-bold pg-lg',
}, ...(user.host == null ? [{
key: 'achievements',
title: i18n.ts.achievements,
2023-09-30 22:53:52 +03:00
icon: 'ph-trophy ph-bold ph-lg',
}] : []), ...($i && ($i.id === user.id)) || user.publicReactions ? [{
2022-07-01 12:55:45 +03:00
key: 'reactions',
title: i18n.ts.reaction,
2023-09-30 22:53:52 +03:00
icon: 'ph-smiley ph-bold ph-lg',
}] : [], {
2022-07-01 12:55:45 +03:00
key: 'clips',
title: i18n.ts.clips,
2023-09-30 22:53:52 +03:00
icon: 'ph-paperclip ph-bold ph-lg',
}, {
key: 'lists',
title: i18n.ts.lists,
2023-09-30 22:53:52 +03:00
icon: 'ph-list ph-bold pg-lg',
}, {
2022-07-01 12:55:45 +03:00
key: 'pages',
title: i18n.ts.pages,
2023-10-01 01:46:42 +03:00
icon: 'ph-newspaper ph-bold ph-lg',
}, {
key: 'flashs',
title: 'Play',
2023-10-01 01:46:42 +03:00
icon: 'ph-play ph-bold pg-lg',
}, {
2022-07-01 12:55:45 +03:00
key: 'gallery',
title: i18n.ts.gallery,
2023-09-30 22:53:52 +03:00
icon: 'ph-images-square ph-bold pg-lg',
2023-01-02 09:41:05 +02:00
}] : []);
definePageMetadata(computed(() => user ? {
2023-09-30 22:53:52 +03:00
icon: 'ph-user ph-bold ph-lg',
title: user.name ? `${user.name} (@${user.username})` : `@${user.username}`,
subtitle: `@${getAcct(user)}`,
userName: user,
avatar: user,
path: `/@${user.username}`,
share: {
title: user.name,
},
} : null));
</script>