hippofish/packages/frontend/src/pages/channels.vue

160 lines
4.8 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 09:20:53 +02:00
<MkSpacer :contentMax="700">
<MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs">
<div v-if="tab === 'search'" key="search">
<div class="_gaps">
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search" @enter="search">
2024-01-21 13:11:23 +01:00
<template #prefix><i class="ph-magnifying-glass ph-bold ph-lg"></i></template>
</MkInput>
<MkRadios v-model="searchType" @update:modelValue="search()">
<option value="nameAndDescription">{{ i18n.ts._channel.nameAndDescription }}</option>
<option value="nameOnly">{{ i18n.ts._channel.nameOnly }}</option>
</MkRadios>
<MkButton large primary gradate rounded @click="search">{{ i18n.ts.search }}</MkButton>
</div>
<MkFoldableSection v-if="channelPagination">
<template #header>{{ i18n.ts.searchResult }}</template>
<MkChannelList :key="key" :pagination="channelPagination"/>
</MkFoldableSection>
</div>
<div v-if="tab === 'featured'" key="featured">
<MkPagination v-slot="{items}" :pagination="featuredPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_margin" :channel="channel"/>
</MkPagination>
</div>
<div v-else-if="tab === 'favorites'" key="favorites">
<MkPagination v-slot="{items}" :pagination="favoritesPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_margin" :channel="channel"/>
</MkPagination>
</div>
<div v-else-if="tab === 'following'" key="following">
<MkPagination v-slot="{items}" :pagination="followingPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_margin" :channel="channel"/>
</MkPagination>
</div>
<div v-else-if="tab === 'owned'" key="owned">
2024-01-21 13:11:23 +01:00
<MkButton class="new" @click="create()"><i class="ph-plus ph-bold ph-lg"></i></MkButton>
<MkPagination v-slot="{items}" :pagination="ownedPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_margin" :channel="channel"/>
</MkPagination>
</div>
</MkHorizontalSwipe>
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue';
import MkChannelPreview from '@/components/MkChannelPreview.vue';
import MkChannelList from '@/components/MkChannelList.vue';
import MkPagination from '@/components/MkPagination.vue';
import MkInput from '@/components/MkInput.vue';
import MkRadios from '@/components/MkRadios.vue';
import MkButton from '@/components/MkButton.vue';
import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
2023-09-19 09:37:43 +02:00
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import { useRouter } from '@/router/supplier.js';
const router = useRouter();
const props = defineProps<{
query: string;
type?: string;
}>();
const key = ref('');
const tab = ref('featured');
const searchQuery = ref('');
const searchType = ref('nameAndDescription');
const channelPagination = ref();
onMounted(() => {
searchQuery.value = props.query ?? '';
searchType.value = props.type ?? 'nameAndDescription';
});
const featuredPagination = {
endpoint: 'channels/featured' as const,
noPaging: true,
};
const favoritesPagination = {
endpoint: 'channels/my-favorites' as const,
limit: 100,
noPaging: true,
};
const followingPagination = {
endpoint: 'channels/followed' as const,
limit: 10,
};
const ownedPagination = {
endpoint: 'channels/owned' as const,
limit: 10,
};
async function search() {
const query = searchQuery.value.toString().trim();
if (query == null) return;
const type = searchType.value.toString().trim();
channelPagination.value = {
endpoint: 'channels/search',
limit: 10,
params: {
query: searchQuery.value,
type: type,
},
};
key.value = query + type;
}
function create() {
router.push('/channels/new');
}
const headerActions = computed(() => [{
2023-09-30 21:53:52 +02:00
icon: 'ph-plus ph-bold ph-lg',
text: i18n.ts.create,
handler: create,
}]);
const headerTabs = computed(() => [{
key: 'search',
title: i18n.ts.search,
2023-09-30 21:53:52 +02:00
icon: 'ph-magnifying-glass ph-bold ph-lg',
}, {
key: 'featured',
title: i18n.ts._channel.featured,
2023-10-01 00:46:42 +02:00
icon: 'ph-shooting-star ph-bold ph-lg',
}, {
key: 'favorites',
title: i18n.ts.favorites,
icon: 'ph-star ph-bold ph-lg',
}, {
key: 'following',
title: i18n.ts._channel.following,
2023-09-30 21:53:52 +02:00
icon: 'ph-eye ph-bold ph-lg',
}, {
key: 'owned',
title: i18n.ts._channel.owned,
2024-02-05 12:39:15 +01:00
icon: 'ph-pencil-simple-line ph-bold ph-lg',
}]);
definePageMetadata(() => ({
title: i18n.ts.channel,
2023-09-30 21:53:52 +02:00
icon: 'ph-television ph-bold ph-lg',
}));
</script>