ユーザTLの余白をクリックして上部に戻れるように

This commit is contained in:
kakkokari-gtyih 2024-06-03 19:38:41 +09:00
parent 2c0d72fc1b
commit 322f132da1
5 changed files with 45 additions and 3 deletions

View File

@ -710,6 +710,7 @@ function loadConversation() {
.noteHeaderInstanceIcon { .noteHeaderInstanceIcon {
width: 32px; width: 32px;
height: 32px; height: 32px;
border-radius: 4px;
} }
.noteHeaderUsername { .noteHeaderUsername {

View File

@ -11,7 +11,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<a :href="`/@${user.username}`" target="_blank" rel="noopener noreferrer" :class="$style.avatarLink"> <a :href="`/@${user.username}`" target="_blank" rel="noopener noreferrer" :class="$style.avatarLink">
<MkAvatar :class="$style.avatar" :user="user"/> <MkAvatar :class="$style.avatar" :user="user"/>
</a> </a>
<div :class="$style.headerTitle"> <div :class="$style.headerTitle" @click="top">
<I18n :src="i18n.ts.noteOf" tag="div"> <I18n :src="i18n.ts.noteOf" tag="div">
<template #user> <template #user>
<a :href="`/@${user.username}`" target="_blank" rel="noopener noreferrer"> <a :href="`/@${user.username}`" target="_blank" rel="noopener noreferrer">
@ -29,8 +29,10 @@ SPDX-License-Identifier: AGPL-3.0-only
</a> </a>
</div> </div>
<MkNotes <MkNotes
ref="notesEl"
:class="$style.userTimelineNotes" :class="$style.userTimelineNotes"
:pagination="pagination" :pagination="pagination"
:disableAutoLoad="!normalizedEnableAutoLoad"
:noGap="true" :noGap="true"
:ad="false" :ad="false"
/> />
@ -40,7 +42,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed } from 'vue'; import { ref, computed, shallowRef } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import MkNotes from '@/components/MkNotes.vue'; import MkNotes from '@/components/MkNotes.vue';
import XNotFound from '@/pages/not-found.vue'; import XNotFound from '@/pages/not-found.vue';
@ -49,14 +51,21 @@ import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { instance } from '@/instance.js'; import { instance } from '@/instance.js';
import { url, instanceName } from '@/config.js'; import { url, instanceName } from '@/config.js';
import { scrollToTop } from '@/scripts/scroll.js';
import { isLink } from '@/scripts/is-link.js';
const props = defineProps<{ const props = defineProps<{
username: string; username: string;
showHeader?: string; showHeader?: string;
enableAutoLoad?: string;
}>(); }>();
// : true
const normalizedShowHeader = computed(() => props.showHeader !== 'false'); const normalizedShowHeader = computed(() => props.showHeader !== 'false');
// : false
const normalizedEnableAutoLoad = computed(() => props.enableAutoLoad === 'true');
const user = ref<Misskey.entities.UserLite | null>(null); const user = ref<Misskey.entities.UserLite | null>(null);
const pagination = computed(() => ({ const pagination = computed(() => ({
endpoint: 'users/notes', endpoint: 'users/notes',
@ -66,6 +75,17 @@ const pagination = computed(() => ({
} as Paging)); } as Paging));
const loading = ref(true); const loading = ref(true);
const notesEl = shallowRef<InstanceType<typeof MkNotes> | null>(null);
function top(ev: MouseEvent) {
const target = ev.target as HTMLElement | null;
if (target && isLink(target)) return;
if (notesEl.value) {
scrollToTop(notesEl.value.$el as HTMLElement, { behavior: 'smooth' });
}
}
misskeyApi('users/show', { misskeyApi('users/show', {
username: props.username, username: props.username,
}).then(res => { }).then(res => {
@ -106,6 +126,7 @@ misskeyApi('users/show', {
} }
.headerTitle { .headerTitle {
flex-grow: 1;
font-weight: 700; font-weight: 700;
line-height: 1.1; line-height: 1.1;
@ -117,6 +138,7 @@ misskeyApi('users/show', {
} }
.instanceIconLink { .instanceIconLink {
flex-shrink: 0;
display: block; display: block;
margin-left: auto; margin-left: auto;
height: 24px; height: 24px;

View File

@ -563,6 +563,7 @@ const routes: RouteDef[] = [{
component: page(() => import('@/pages/embed/user-timeline.vue')), component: page(() => import('@/pages/embed/user-timeline.vue')),
query: { query: {
header: 'showHeader', header: 'showHeader',
autoload: 'enableAutoLoad',
} }
}, { }, {
path: '/timeline', path: '/timeline',

View File

@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
export function isLink(el: HTMLElement) {
if (el.tagName === 'A') return true;
if (el.parentElement) {
return isLink(el.parentElement);
}
return false;
};

View File

@ -10,6 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only
$style.rootForEmbedPage, $style.rootForEmbedPage,
{ {
[$style.rounded]: embedRounded, [$style.rounded]: embedRounded,
[$style.noBorder]: embedNoBorder,
} }
]" ]"
:style="maxHeight > 0 ? { maxHeight: `${maxHeight}px`, '--embedMaxHeight': `${maxHeight}px` } : {}" :style="maxHeight > 0 ? { maxHeight: `${maxHeight}px`, '--embedMaxHeight': `${maxHeight}px` } : {}"
@ -65,6 +66,7 @@ provide('EMBED_PAGE', true);
//#region Embed Style //#region Embed Style
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
const embedRounded = ref(params.get('rounded') !== 'false'); const embedRounded = ref(params.get('rounded') !== 'false');
const embedNoBorder = ref(params.get('border') === 'false');
const maxHeight = ref(params.get('maxHeight') ? parseInt(params.get('maxHeight')!) : 0); const maxHeight = ref(params.get('maxHeight') ? parseInt(params.get('maxHeight')!) : 0);
//#endregion //#endregion
@ -73,7 +75,7 @@ const rootEl = shallowRef<HTMLElement | null>(null);
let previousHeight = 0; let previousHeight = 0;
const resizeObserver = new ResizeObserver(async () => { const resizeObserver = new ResizeObserver(async () => {
const height = rootEl.value!.scrollHeight + 2; // border 1px const height = rootEl.value!.scrollHeight + (embedNoBorder.value ? 0 : 2); // border 1px
if (Math.abs(previousHeight - height) < 1) return; // 1px if (Math.abs(previousHeight - height) < 1) return; // 1px
postMessageToParentWindow('misskey:embed:changeHeight', { postMessageToParentWindow('misskey:embed:changeHeight', {
height: (maxHeight.value > 0 && height > maxHeight.value) ? maxHeight.value : height, height: (maxHeight.value > 0 && height > maxHeight.value) ? maxHeight.value : height,
@ -106,6 +108,10 @@ if (_DEV_) document.documentElement.classList.add('embed');
&.rounded { &.rounded {
border-radius: var(--radius); border-radius: var(--radius);
} }
&.noBorder {
border: none;
}
} }
.routerViewContainer { .routerViewContainer {