2024-09-30 18:06:00 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader v-model:tab="currentTab" :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkHorizontalSwipe v-model:tab="currentTab" :tabs="headerTabs">
|
2024-10-02 00:28:04 +02:00
|
|
|
<MkSpacer :contentMax="1200">
|
|
|
|
<div :class="$style.columns">
|
2024-10-02 06:20:39 +02:00
|
|
|
<MkPullToRefresh :refresher="() => reloadLatestNotes()">
|
|
|
|
<MkPagination ref="latestNotesPaging" :pagination="latestNotesPagination" @init="onListReady">
|
2024-10-02 00:28:04 +02:00
|
|
|
<template #empty>
|
|
|
|
<div class="_fullinfo">
|
2024-10-02 06:08:52 +02:00
|
|
|
<img :src="infoImageUrl" class="_ghost" :alt="i18n.ts.noNotes" aria-hidden="true"/>
|
2024-10-02 00:28:04 +02:00
|
|
|
<div>{{ i18n.ts.noNotes }}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #default="{ items: notes }">
|
2024-10-02 06:20:39 +02:00
|
|
|
<MkDateSeparatedList v-slot="{ item: note }" :items="notes" :class="$style.panel" :noGap="true">
|
2024-10-02 00:28:04 +02:00
|
|
|
<FollowingFeedEntry :note="note" @select="selectUser"/>
|
|
|
|
</MkDateSeparatedList>
|
|
|
|
</template>
|
|
|
|
</MkPagination>
|
|
|
|
</MkPullToRefresh>
|
|
|
|
|
2024-10-02 06:20:39 +02:00
|
|
|
<MkPullToRefresh :refresher="() => reloadUserNotes()">
|
2024-10-02 04:21:08 +02:00
|
|
|
<div v-if="selectedUser" :class="$style.userInfo">
|
|
|
|
<MkUserInfo class="user" :user="selectedUser"/>
|
2024-10-02 06:20:39 +02:00
|
|
|
<MkNotes :noGap="true" :pagination="userNotesPagination"/>
|
2024-10-02 04:21:08 +02:00
|
|
|
</div>
|
2024-10-02 06:20:39 +02:00
|
|
|
<div v-else-if="selectedUserError" :class="$style.panel">{{ selectedUserError }}</div>
|
2024-10-02 06:11:57 +02:00
|
|
|
<MkLoading v-else-if="selectedUserId"/>
|
2024-10-02 00:28:04 +02:00
|
|
|
</MkPullToRefresh>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
2024-09-30 18:06:00 +02:00
|
|
|
</MkHorizontalSwipe>
|
|
|
|
</MkStickyContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export type FollowingFeedTab = typeof followingTab | typeof mutualsTab;
|
|
|
|
export const followingTab = 'following' as const;
|
|
|
|
export const mutualsTab = 'mutuals' as const;
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-10-02 04:21:08 +02:00
|
|
|
import { computed, Ref, ref, shallowRef } from 'vue';
|
|
|
|
import * as Misskey from 'misskey-js';
|
2024-09-30 18:06:00 +02:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
|
|
|
|
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
|
|
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
|
|
|
import { infoImageUrl } from '@/instance.js';
|
|
|
|
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
|
|
|
|
import { Tab } from '@/components/global/MkPageHeader.tabs.vue';
|
2024-09-30 19:56:10 +02:00
|
|
|
import { PageHeaderItem } from '@/types/page-header.js';
|
2024-10-01 20:37:09 +02:00
|
|
|
import FollowingFeedEntry from '@/components/FollowingFeedEntry.vue';
|
2024-10-02 00:28:04 +02:00
|
|
|
import MkNotes from '@/components/MkNotes.vue';
|
2024-10-02 04:21:08 +02:00
|
|
|
import MkUserInfo from '@/components/MkUserInfo.vue';
|
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2024-09-30 18:06:00 +02:00
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
initialTab?: FollowingFeedTab,
|
|
|
|
}>(), {
|
|
|
|
initialTab: followingTab,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Vue complains, but we *want* to lose reactivity here.
|
2024-10-02 06:44:26 +02:00
|
|
|
// Otherwise, the user would be unable to change the tab.
|
2024-09-30 18:06:00 +02:00
|
|
|
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
|
2024-10-02 04:21:08 +02:00
|
|
|
const currentTab: Ref<FollowingFeedTab> = ref(props.initialTab);
|
|
|
|
const mutualsOnly: Ref<boolean> = computed(() => currentTab.value === mutualsTab);
|
2024-09-30 18:06:00 +02:00
|
|
|
|
2024-10-02 04:21:08 +02:00
|
|
|
const selectedUserError: Ref<string> = ref('');
|
|
|
|
const selectedUserId: Ref<string> = ref('');
|
|
|
|
const selectedUser: Ref<Misskey.entities.UserDetailed | null> = ref(null);
|
2024-10-02 00:28:04 +02:00
|
|
|
|
2024-10-02 04:21:08 +02:00
|
|
|
async function selectUser(userId: string): Promise<void> {
|
|
|
|
selectedUserError.value = '';
|
2024-10-02 00:28:04 +02:00
|
|
|
selectedUserId.value = userId;
|
2024-10-02 04:21:08 +02:00
|
|
|
selectedUser.value = null;
|
|
|
|
|
|
|
|
if (userId) {
|
|
|
|
await misskeyApi('users/show', { userId })
|
|
|
|
.then(user => selectedUser.value = user)
|
|
|
|
.catch(error => {
|
|
|
|
console.error('Error fetching user info', error);
|
2024-10-02 06:09:10 +02:00
|
|
|
|
|
|
|
return selectedUserError.value =
|
|
|
|
typeof(error) === 'string'
|
2024-10-02 06:11:57 +02:00
|
|
|
? String(error)
|
|
|
|
: JSON.stringify(error);
|
2024-10-02 04:21:08 +02:00
|
|
|
});
|
|
|
|
}
|
2024-10-02 00:28:04 +02:00
|
|
|
}
|
|
|
|
|
2024-10-02 06:20:39 +02:00
|
|
|
async function reloadLatestNotes() {
|
|
|
|
await latestNotesPaging.value?.reload();
|
2024-10-02 00:28:04 +02:00
|
|
|
}
|
|
|
|
|
2024-10-02 06:20:39 +02:00
|
|
|
async function reloadUserNotes() {
|
2024-10-02 04:21:08 +02:00
|
|
|
await selectUser(selectedUserId.value);
|
2024-10-02 00:28:04 +02:00
|
|
|
}
|
2024-09-30 18:06:00 +02:00
|
|
|
|
2024-10-02 06:20:39 +02:00
|
|
|
async function reload() {
|
2024-10-02 00:28:04 +02:00
|
|
|
await Promise.all([
|
2024-10-02 06:20:39 +02:00
|
|
|
reloadLatestNotes(),
|
|
|
|
reloadUserNotes(),
|
2024-10-02 00:28:04 +02:00
|
|
|
]);
|
2024-09-30 18:06:00 +02:00
|
|
|
}
|
|
|
|
|
2024-10-02 06:11:57 +02:00
|
|
|
async function onListReady(): Promise<void> {
|
2024-10-02 06:20:39 +02:00
|
|
|
if (!selectedUserId.value && latestNotesPaging.value?.items.size) {
|
2024-10-02 06:11:57 +02:00
|
|
|
// This just gets the first user ID
|
2024-10-02 06:20:39 +02:00
|
|
|
const selectedNote: Misskey.entities.Note = latestNotesPaging.value.items.values().next().value;
|
2024-10-02 06:11:57 +02:00
|
|
|
|
|
|
|
// Wait for 1 second to match the animation effects.
|
|
|
|
// Otherwise, the page appears to load "backwards".
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
await selectUser(selectedNote.userId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-02 06:20:39 +02:00
|
|
|
const latestNotesPaging = shallowRef<InstanceType<typeof MkPagination>>();
|
|
|
|
|
|
|
|
const latestNotesPagination: Paging<'notes/following'> = {
|
2024-09-30 18:06:00 +02:00
|
|
|
endpoint: 'notes/following' as const,
|
|
|
|
limit: 20,
|
|
|
|
params: computed(() => ({
|
|
|
|
mutualsOnly: mutualsOnly.value,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
2024-10-02 06:20:39 +02:00
|
|
|
const userNotesPagination: Paging<'users/notes'> = {
|
2024-10-02 00:28:04 +02:00
|
|
|
endpoint: 'users/notes' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
|
|
|
userId: selectedUserId.value,
|
|
|
|
withRenotes: false,
|
|
|
|
withReplies: true,
|
|
|
|
withChannelNotes: false,
|
|
|
|
withFiles: false,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
2024-09-30 19:56:10 +02:00
|
|
|
const headerActions: PageHeaderItem[] = [
|
|
|
|
{
|
|
|
|
icon: 'ti ti-refresh',
|
|
|
|
text: i18n.ts.reload,
|
2024-10-02 06:20:39 +02:00
|
|
|
handler: () => reload(),
|
2024-09-30 19:56:10 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-09-30 18:06:00 +02:00
|
|
|
const headerTabs = computed(() => [
|
|
|
|
{
|
|
|
|
key: followingTab,
|
|
|
|
icon: 'ti ti-user-check',
|
|
|
|
title: i18n.ts.following,
|
|
|
|
} satisfies Tab,
|
|
|
|
{
|
|
|
|
key: mutualsTab,
|
|
|
|
icon: 'ti ti-user-heart',
|
|
|
|
title: i18n.ts.mutuals,
|
|
|
|
} satisfies Tab,
|
|
|
|
]);
|
|
|
|
|
|
|
|
definePageMetadata(() => ({
|
|
|
|
title: i18n.ts.following,
|
2024-09-30 20:47:35 +02:00
|
|
|
icon: 'ti ti-user-check',
|
2024-09-30 18:06:00 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2024-10-02 06:20:39 +02:00
|
|
|
.panel {
|
2024-09-30 18:06:00 +02:00
|
|
|
background: var(--panel);
|
|
|
|
}
|
2024-10-02 00:28:04 +02:00
|
|
|
|
2024-10-02 06:11:57 +02:00
|
|
|
.info {
|
|
|
|
margin-bottom: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
@container (min-width: 451px) {
|
|
|
|
.info {
|
|
|
|
margin-bottom: 12px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-02 00:28:04 +02:00
|
|
|
.columns {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.columns > * {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.columns > :last-child {
|
|
|
|
min-width: 60%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.columns > :not(:first-child) {
|
|
|
|
margin-left: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.columns > :not(:last-child) {
|
|
|
|
margin-right: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
@container (min-width: 451px) {
|
|
|
|
.columns > :not(:first-child) {
|
|
|
|
margin-left: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.columns > :not(:last-child) {
|
|
|
|
margin-right: 12px;
|
|
|
|
}
|
|
|
|
}
|
2024-10-02 04:21:08 +02:00
|
|
|
|
|
|
|
.userInfo {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: stretch;
|
|
|
|
}
|
|
|
|
|
|
|
|
.userInfo > :not(:first-child) {
|
|
|
|
margin-top: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.userInfo > :not(:last-child) {
|
|
|
|
margin-bottom: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
@container (min-width: 451px) {
|
|
|
|
.userInfo > :not(:first-child) {
|
|
|
|
margin-top: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.userInfo > :not(:last-child) {
|
|
|
|
margin-bottom: 12px;
|
|
|
|
}
|
|
|
|
}
|
2024-09-30 18:06:00 +02:00
|
|
|
</style>
|