Sharkey/packages/frontend/src/pages/channel.vue

342 lines
10 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 v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 10:20:53 +03:00
<MkSpacer :contentMax="700" :class="$style.main">
<MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs">
<div v-if="channel && tab === 'overview'" key="overview" class="_gaps">
<div class="_panel" :class="$style.bannerContainer">
<XChannelFollowButton :channel="channel" :full="true" :class="$style.subscribe"/>
2024-01-21 14:11:23 +02:00
<MkButton v-if="favorited" v-tooltip="i18n.ts.unfavorite" asLike class="button" rounded primary :class="$style.favorite" @click="unfavorite()"><i class="ph-star ph-bold ph-lg"></i></MkButton>
<MkButton v-else v-tooltip="i18n.ts.favorite" asLike class="button" rounded :class="$style.favorite" @click="favorite()"><i class="ph-star ph-bold ph-lg"></i></MkButton>
<div :style="{ backgroundImage: channel.bannerUrl ? `url(${channel.bannerUrl})` : undefined }" :class="$style.banner">
<div :class="$style.bannerStatus">
2024-01-21 14:11:23 +02:00
<div><i class="ph-users ph-bold ph-lg"></i><I18n :src="i18n.ts._channel.usersCount" tag="span" style="margin-left: 4px;"><template #n><b>{{ channel.usersCount }}</b></template></I18n></div>
<div><i class="ph-pencil ph-bold ph-lg"></i><I18n :src="i18n.ts._channel.notesCount" tag="span" style="margin-left: 4px;"><template #n><b>{{ channel.notesCount }}</b></template></I18n></div>
</div>
<div v-if="channel.isSensitive" :class="$style.sensitiveIndicator">{{ i18n.ts.sensitive }}</div>
<div :class="$style.bannerFade"></div>
</div>
<div v-if="channel.description" :class="$style.description">
<Mfm :text="channel.description" :isNote="false"/>
</div>
2021-12-23 09:10:13 +02:00
</div>
<MkFoldableSection>
2024-01-21 14:11:23 +02:00
<template #header><i class="ph-push-pin ph-bold ph-lg" style="margin-right: 0.5em;"></i>{{ i18n.ts.pinnedNotes }}</template>
<div v-if="channel.pinnedNotes && channel.pinnedNotes.length > 0" class="_gaps">
<MkNote v-for="note in channel.pinnedNotes" :key="note.id" class="_panel" :note="note"/>
</div>
</MkFoldableSection>
</div>
<div v-if="channel && tab === 'timeline'" key="timeline" class="_gaps">
<MkInfo v-if="channel.isArchived" warn>{{ i18n.ts.thisChannelArchived }}</MkInfo>
<!-- スマホタブレットの場合キーボードが表示されると投稿が見づらくなるのでデスクトップ場合のみ自動でフォーカスを当てる -->
<MkPostForm v-if="$i && defaultStore.reactiveState.showFixedPostFormInChannel.value" :channel="channel" class="post-form _panel" fixed :autofocus="deviceKind === 'desktop'"/>
<MkTimeline :key="channelId" src="channel" :channel="channelId" @before="before" @after="after" @note="miLocalStorage.setItemAsJson(`channelLastReadedAt:${channel.id}`, Date.now())"/>
</div>
<div v-else-if="tab === 'featured'" key="featured">
<MkNotes :pagination="featuredPagination"/>
</div>
<div v-else-if="tab === 'search'" key="search">
<div class="_gaps">
<div>
<MkInput v-model="searchQuery" @enter="search()">
2024-01-21 14:11:23 +02:00
<template #prefix><i class="ph-magnifying-glass ph-bold ph-lg"></i></template>
</MkInput>
<MkButton primary rounded style="margin-top: 8px;" @click="search()">{{ i18n.ts.search }}</MkButton>
</div>
<MkNotes v-if="searchPagination" :key="searchKey" :pagination="searchPagination"/>
2023-05-05 04:05:33 +03:00
</div>
</div>
</MkHorizontalSwipe>
</MkSpacer>
2023-03-04 03:34:54 +02:00
<template #footer>
<div :class="$style.footer">
2023-05-19 10:20:53 +03:00
<MkSpacer :contentMax="700" :marginMin="16" :marginMax="16">
2023-03-04 03:34:54 +02:00
<div class="_buttonsCenter">
2023-09-30 22:53:52 +03:00
<MkButton inline rounded primary gradate @click="openPostForm()"><i class="ph-pencil ph-bold ph-lg"></i> {{ i18n.ts.postToTheChannel }}</MkButton>
2023-03-04 03:34:54 +02:00
</div>
</MkSpacer>
</div>
</template>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { computed, watch, ref } from 'vue';
import * as Misskey from 'misskey-js';
import MkPostForm from '@/components/MkPostForm.vue';
import MkTimeline from '@/components/MkTimeline.vue';
import XChannelFollowButton from '@/components/MkChannelFollowButton.vue';
2023-09-19 10:37:43 +03:00
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
2023-09-19 10:37:43 +03:00
import { $i, iAmModerator } from '@/account.js';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { deviceKind } from '@/scripts/device-kind.js';
import MkNotes from '@/components/MkNotes.vue';
2023-09-19 10:37:43 +03:00
import { url } from '@/config.js';
2023-03-04 03:34:54 +02:00
import MkButton from '@/components/MkButton.vue';
2023-05-05 04:05:33 +03:00
import MkInput from '@/components/MkInput.vue';
2023-09-19 10:37:43 +03:00
import { defaultStore } from '@/store.js';
import MkNote from '@/components/MkNote.vue';
import MkInfo from '@/components/MkInfo.vue';
import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
import { PageHeaderItem } from '@/types/page-header.js';
import { isSupportShare } from '@/scripts/navigator.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { miLocalStorage } from '@/local-storage.js';
import { useRouter } from '@/router/supplier.js';
const router = useRouter();
const props = defineProps<{
channelId: string;
}>();
const tab = ref('overview');
const channel = ref<Misskey.entities.Channel | null>(null);
const favorited = ref(false);
const searchQuery = ref('');
const searchPagination = ref();
const searchKey = ref('');
const featuredPagination = computed(() => ({
endpoint: 'notes/featured' as const,
limit: 10,
params: {
channelId: props.channelId,
},
}));
watch(() => props.channelId, async () => {
channel.value = await misskeyApi('channels/show', {
channelId: props.channelId,
});
favorited.value = channel.value.isFavorited ?? false;
if (favorited.value || channel.value.isFollowing) {
tab.value = 'timeline';
}
if ((favorited.value || channel.value.isFollowing) && channel.value.lastNotedAt) {
const lastReadedAt: number = miLocalStorage.getItemAsJson(`channelLastReadedAt:${channel.value.id}`) ?? 0;
const lastNotedAt = Date.parse(channel.value.lastNotedAt);
if (lastNotedAt > lastReadedAt) {
miLocalStorage.setItemAsJson(`channelLastReadedAt:${channel.value.id}`, lastNotedAt);
}
}
}, { immediate: true });
function edit() {
router.push(`/channels/${channel.value?.id}/edit`);
}
2023-03-04 03:34:54 +02:00
function openPostForm() {
os.post({
channel: channel.value,
2023-03-04 03:34:54 +02:00
});
}
function favorite() {
if (!channel.value) return;
os.apiWithDialog('channels/favorite', {
channelId: channel.value.id,
}).then(() => {
favorited.value = true;
});
}
async function unfavorite() {
if (!channel.value) return;
const confirm = await os.confirm({
type: 'warning',
text: i18n.ts.unfavoriteConfirm,
});
if (confirm.canceled) return;
os.apiWithDialog('channels/unfavorite', {
channelId: channel.value.id,
}).then(() => {
favorited.value = false;
});
}
2023-05-05 04:05:33 +03:00
async function search() {
if (!channel.value) return;
const query = searchQuery.value.toString().trim();
2023-05-05 04:05:33 +03:00
if (query == null) return;
searchPagination.value = {
2023-05-05 04:05:33 +03:00
endpoint: 'notes/search',
limit: 10,
params: {
query: query,
channelId: channel.value.id,
2023-05-05 04:05:33 +03:00
},
};
searchKey.value = query;
2023-05-05 04:05:33 +03:00
}
const headerActions = computed(() => {
if (channel.value && channel.value.userId) {
const headerItems: PageHeaderItem[] = [];
headerItems.push({
icon: 'ph-share-network ph-bold ph-lg',
text: i18n.ts.copyUrl,
handler: async (): Promise<void> => {
if (!channel.value) {
console.warn('failed to copy channel URL. channel.value is null.');
return;
}
copyToClipboard(`${url}/channels/${channel.value.id}`);
os.success();
},
});
if (isSupportShare()) {
headerItems.push({
2023-12-23 03:09:23 +02:00
icon: 'ph-share-network ph-bold ph-lg',
text: i18n.ts.share,
handler: async (): Promise<void> => {
if (!channel.value) {
console.warn('failed to share channel. channel.value is null.');
return;
}
navigator.share({
title: channel.value.name,
text: channel.value.description ?? undefined,
url: `${url}/channels/${channel.value.id}`,
});
},
});
}
if (($i && $i.id === channel.value.userId) || iAmModerator) {
headerItems.push({
2023-12-23 03:09:23 +02:00
icon: 'ph-gear ph-bold ph-lg',
text: i18n.ts.edit,
handler: edit,
});
}
return headerItems.length > 0 ? headerItems : null;
} else {
return null;
}
});
const headerTabs = computed(() => [{
2023-03-04 03:50:21 +02:00
key: 'overview',
title: i18n.ts.overview,
2023-09-30 22:53:52 +03:00
icon: 'ph-info ph-bold ph-lg',
2023-03-04 03:50:21 +02:00
}, {
key: 'timeline',
title: i18n.ts.timeline,
2023-09-30 22:53:52 +03:00
icon: 'ph-house ph-bold ph-lg',
}, {
key: 'featured',
title: i18n.ts.featured,
icon: 'ph-lightning ph-bold ph-lg',
2023-05-05 04:05:33 +03:00
}, {
key: 'search',
title: i18n.ts.search,
2023-09-30 22:53:52 +03:00
icon: 'ph-magnifying-glass ph-bold ph-lg',
}]);
definePageMetadata(computed(() => channel.value ? {
title: channel.value.name,
2023-09-30 22:53:52 +03:00
icon: 'ph-television ph-bold ph-lg',
} : null));
</script>
2023-03-04 03:34:54 +02:00
<style lang="scss" module>
2023-03-04 03:50:21 +02:00
.main {
2023-05-08 12:30:40 +03:00
min-height: calc(100cqh - (var(--stickyTop, 0px) + var(--stickyBottom, 0px)));
2023-03-04 03:50:21 +02:00
}
2023-03-04 03:34:54 +02:00
.footer {
-webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px));
background: var(--acrylicBg);
2023-03-04 03:34:54 +02:00
border-top: solid 0.5px var(--divider);
}
2023-03-04 03:50:21 +02:00
.bannerContainer {
2020-10-18 06:16:42 +03:00
position: relative;
2023-03-04 03:50:21 +02:00
}
.subscribe {
position: absolute;
z-index: 1;
top: 16px;
left: 16px;
}
.favorite {
position: absolute;
z-index: 1;
top: 16px;
right: 16px;
}
2023-03-04 03:50:21 +02:00
.banner {
position: relative;
height: 200px;
background-position: center;
background-size: cover;
}
.bannerFade {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 64px;
background: linear-gradient(0deg, var(--panel), var(--X15));
}
.bannerStatus {
position: absolute;
z-index: 1;
bottom: 16px;
right: 16px;
padding: 8px 12px;
font-size: 80%;
background: rgba(0, 0, 0, 0.7);
border-radius: var(--radius-sm);
2023-03-04 03:50:21 +02:00
color: #fff;
}
2020-10-18 06:16:42 +03:00
2023-03-04 03:50:21 +02:00
.description {
padding: 16px;
}
.sensitiveIndicator {
position: absolute;
z-index: 1;
bottom: 16px;
left: 16px;
background: rgba(0, 0, 0, 0.7);
color: var(--warn);
border-radius: var(--radius-sm);
font-weight: bold;
font-size: 1em;
padding: 4px 7px;
}
</style>