enhance: 既存のファイルコンテナの「もっと見る」をクリックしたらファイルタブに飛べるように

This commit is contained in:
kakkokari-gtyih 2024-12-14 19:31:24 +09:00
parent 68d4a25d9a
commit abde4866e8
6 changed files with 45 additions and 18 deletions

View file

@ -30,7 +30,7 @@ SPDX-License-Identifier: AGPL-3.0-only
> >
<div v-show="showBody" ref="contentEl" :class="[$style.content, { [$style.omitted]: omitted }]"> <div v-show="showBody" ref="contentEl" :class="[$style.content, { [$style.omitted]: omitted }]">
<slot></slot> <slot></slot>
<button v-if="omitted" :class="$style.fade" class="_button" @click="() => { ignoreOmit = true; omitted = false; }"> <button v-if="omitted" :class="$style.fade" class="_button" @click="showMore">
<span :class="$style.fadeLabel">{{ i18n.ts.showMore }}</span> <span :class="$style.fadeLabel">{{ i18n.ts.showMore }}</span>
</button> </button>
</div> </div>
@ -48,6 +48,7 @@ const props = withDefaults(defineProps<{
thin?: boolean; thin?: boolean;
naked?: boolean; naked?: boolean;
foldable?: boolean; foldable?: boolean;
onUnfold?: () => boolean; // return false to prevent unfolding
scrollable?: boolean; scrollable?: boolean;
expanded?: boolean; expanded?: boolean;
maxHeight?: number | null; maxHeight?: number | null;
@ -101,6 +102,13 @@ const omitObserver = new ResizeObserver((entries, observer) => {
calcOmit(); calcOmit();
}); });
function showMore() {
if (props.onUnfold && !props.onUnfold()) return;
ignoreOmit.value = true;
omitted.value = false;
}
onMounted(() => { onMounted(() => {
watch(showBody, v => { watch(showBody, v => {
if (!rootEl.value) return; if (!rootEl.value) return;

View file

@ -5,13 +5,13 @@ SPDX-License-Identifier: AGPL-3.0-only
<template> <template>
<template v-for="file in note.files"> <template v-for="file in note.files">
<div v-if="file.isSensitive && !showingFiles.includes(file.id)" :class="$style.sensitive" @click="showingFiles.push(file.id)"> <div v-if="file.isSensitive && !showingFiles.includes(file.id)" :class="[$style.sensitive, { [$style.square]: square }]" @click="showingFiles.push(file.id)">
<div> <div>
<div><i class="ti ti-eye-exclamation"></i> {{ i18n.ts.sensitive }}</div> <div><i class="ti ti-eye-exclamation"></i> {{ i18n.ts.sensitive }}</div>
<div>{{ i18n.ts.clickToShow }}</div> <div>{{ i18n.ts.clickToShow }}</div>
</div> </div>
</div> </div>
<MkA v-else :class="$style.img" :to="notePage(note)"> <MkA v-else :class="[$style.img, { [$style.square]: square }]" :to="notePage(note)">
<!-- TODO: 画像以外のファイルに対応 --> <!-- TODO: 画像以外のファイルに対応 -->
<ImgWithBlurhash :hash="file.blurhash" :src="thumbnail(file)" :title="file.name"/> <ImgWithBlurhash :hash="file.blurhash" :src="thumbnail(file)" :title="file.name"/>
</MkA> </MkA>
@ -28,8 +28,9 @@ import * as Misskey from 'misskey-js';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy.js'; import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy.js';
const props = defineProps<{ defineProps<{
note: Misskey.entities.Note; note: Misskey.entities.Note;
square?: boolean;
}>(); }>();
const showingFiles = ref<string[]>([]); const showingFiles = ref<string[]>([]);
@ -42,10 +43,20 @@ function thumbnail(image: Misskey.entities.DriveFile): string {
</script> </script>
<style lang="scss" module> <style lang="scss" module>
.square {
width: 100%;
height: auto;
aspect-ratio: 1;
}
.img { .img {
height: 220px; height: 220px;
border-radius: 6px; border-radius: 6px;
overflow: clip; overflow: clip;
&.square {
height: 100%;
}
} }
.empty { .empty {

View file

@ -8,7 +8,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<div :class="$style.root"> <div :class="$style.root">
<MkPagination v-slot="{items}" :pagination="pagination"> <MkPagination v-slot="{items}" :pagination="pagination">
<div :class="$style.stream"> <div :class="$style.stream">
<MkMedias v-for="note in items" :note="note"/> <MkMedias v-for="note in items" :note="note" square/>
</div> </div>
</MkPagination> </MkPagination>
</div> </div>
@ -46,10 +46,4 @@ const pagination = {
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
grid-gap: 6px; grid-gap: 6px;
} }
@media (min-width: 720px) {
.stream {
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
}
</style> </style>

View file

@ -136,7 +136,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkInfo v-else-if="$i && $i.id === user.id">{{ i18n.ts.userPagePinTip }}</MkInfo> <MkInfo v-else-if="$i && $i.id === user.id">{{ i18n.ts.userPagePinTip }}</MkInfo>
<template v-if="narrow"> <template v-if="narrow">
<MkLazy> <MkLazy>
<XFiles :key="user.id" :user="user"/> <XFiles :key="user.id" :user="user" @unfold="emit('unfoldFiles')"/>
</MkLazy> </MkLazy>
<MkLazy> <MkLazy>
<XActivity :key="user.id" :user="user"/> <XActivity :key="user.id" :user="user"/>
@ -150,7 +150,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div> </div>
</div> </div>
<div v-if="!narrow" class="sub _gaps" style="container-type: inline-size;"> <div v-if="!narrow" class="sub _gaps" style="container-type: inline-size;">
<XFiles :key="user.id" :user="user"/> <XFiles :key="user.id" :user="user" @unfold="emit('unfoldFiles')"/>
<XActivity :key="user.id" :user="user"/> <XActivity :key="user.id" :user="user"/>
</div> </div>
</div> </div>
@ -212,6 +212,10 @@ const props = withDefaults(defineProps<{
disableNotes: false, disableNotes: false,
}); });
const emit = defineEmits<{
(ev: 'unfoldFiles'): void;
}>();
const router = useRouter(); const router = useRouter();
const user = ref(props.user); const user = ref(props.user);

View file

@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<MkContainer :max-height="300" :foldable="true"> <MkContainer :max-height="300" :foldable="true" :onUnfold="unfoldContainer">
<template #icon><i class="ti ti-photo"></i></template> <template #icon><i class="ti ti-photo"></i></template>
<template #header>{{ i18n.ts.files }}</template> <template #header>{{ i18n.ts.files }}</template>
<div :class="$style.root"> <div :class="$style.root">
@ -35,7 +35,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { getStaticImageUrl } from '@/scripts/media-proxy.js'; import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy.js';
import { notePage } from '@/filters/note.js'; import { notePage } from '@/filters/note.js';
import { misskeyApi } from '@/scripts/misskey-api.js'; import { misskeyApi } from '@/scripts/misskey-api.js';
import MkContainer from '@/components/MkContainer.vue'; import MkContainer from '@/components/MkContainer.vue';
@ -47,6 +47,10 @@ const props = defineProps<{
user: Misskey.entities.UserDetailed; user: Misskey.entities.UserDetailed;
}>(); }>();
const emit = defineEmits<{
(ev: 'unfold'): void;
}>();
const fetching = ref(true); const fetching = ref(true);
const files = ref<{ const files = ref<{
note: Misskey.entities.Note; note: Misskey.entities.Note;
@ -54,10 +58,15 @@ const files = ref<{
}[]>([]); }[]>([]);
const showingFiles = ref<string[]>([]); const showingFiles = ref<string[]>([]);
function unfoldContainer(): boolean {
emit('unfold');
return false;
}
function thumbnail(image: Misskey.entities.DriveFile): string { function thumbnail(image: Misskey.entities.DriveFile): string {
return defaultStore.state.disableShowingAnimatedImages return defaultStore.state.disableShowingAnimatedImages
? getStaticImageUrl(image.url) ? getStaticImageUrl(image.url)
: image.thumbnailUrl; : image.thumbnailUrl ?? getProxiedImageUrl(image.url, 'preview');
} }
onMounted(() => { onMounted(() => {
@ -67,6 +76,7 @@ onMounted(() => {
limit: 15, limit: 15,
}).then(notes => { }).then(notes => {
for (const note of notes) { for (const note of notes) {
if (!note.files) continue;
for (const file of note.files) { for (const file of note.files) {
files.value.push({ files.value.push({
note, note,

View file

@ -9,7 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<div> <div>
<div v-if="user"> <div v-if="user">
<MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs"> <MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs">
<XHome v-if="tab === 'home'" key="home" :user="user"/> <XHome v-if="tab === 'home'" key="home" :user="user" @unfoldFiles="() => { tab = 'files'; }"/>
<MkSpacer v-else-if="tab === 'notes'" key="notes" :contentMax="800" style="padding-top: 0"> <MkSpacer v-else-if="tab === 'notes'" key="notes" :contentMax="800" style="padding-top: 0">
<XTimeline :user="user"/> <XTimeline :user="user"/>
</MkSpacer> </MkSpacer>
@ -105,7 +105,7 @@ const headerTabs = computed(() => user.value ? [{
title: i18n.ts.notes, title: i18n.ts.notes,
icon: 'ti ti-pencil', icon: 'ti ti-pencil',
}, { }, {
key: 'file', key: 'files',
title: i18n.ts.files, title: i18n.ts.files,
icon: 'ti ti-photo', icon: 'ti ti-photo',
}, { }, {