iceshrimp/packages/client/src/pages/channels.vue

119 lines
3.2 KiB
Vue
Raw Normal View History

<template>
<MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :content-max="700">
<swiper
:modules="[Virtual]"
:space-between="20"
:virtual="true"
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)"
@swiper="setSwiperRef"
@slide-change="onSlideChange"
>
<swiper-slide>
2022-09-10 07:32:05 +09:00
<div class="_content grwlizim featured">
<MkPagination v-slot="{items}" :pagination="featuredPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/>
</MkPagination>
</div>
</swiper-slide>
<swiper-slide>
2022-09-10 07:32:05 +09:00
<div class="_content grwlizim following">
<MkPagination v-slot="{items}" :pagination="followingPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/>
</MkPagination>
</div>
</swiper-slide>
<swiper-slide>
2022-09-10 07:32:05 +09:00
<div class="_content grwlizim owned">
2023-03-12 06:01:04 +09:00
<MkButton class="new" @click="create()"><i class="ph-plus ph-bold ph-lg"></i></MkButton>
2022-09-10 07:32:05 +09:00
<MkPagination v-slot="{items}" :pagination="ownedPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/>
</MkPagination>
</div>
</swiper-slide>
</swiper>
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
2022-10-26 11:48:25 +09:00
import { computed, defineComponent, inject, watch } from 'vue';
2022-09-10 07:32:05 +09:00
import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import MkChannelPreview from '@/components/MkChannelPreview.vue';
import MkPagination from '@/components/MkPagination.vue';
import MkButton from '@/components/MkButton.vue';
import { useRouter } from '@/router';
import { definePageMetadata } from '@/scripts/page-metadata';
2022-09-16 02:43:48 +09:00
import { deviceKind } from '@/scripts/device-kind';
import { i18n } from '@/i18n';
import { defaultStore } from '@/store';
2022-09-10 07:32:05 +09:00
import 'swiper/scss';
import 'swiper/scss/virtual';
const router = useRouter();
2022-09-10 07:32:05 +09:00
const tabs = ['featured', 'following', 'owned'];
2022-10-26 11:19:42 +09:00
let tab = $ref(tabs[0]);
watch($$(tab), () => (syncSlide(tabs.indexOf(tab))));
const featuredPagination = {
endpoint: 'channels/featured' as const,
limit: 10,
noPaging: false,
};
const followingPagination = {
endpoint: 'channels/followed' as const,
limit: 10,
};
const ownedPagination = {
endpoint: 'channels/owned' as const,
limit: 10,
};
function create() {
router.push('/channels/new');
}
const headerActions = $computed(() => [{
2023-03-12 06:01:04 +09:00
icon: 'ph-plus ph-bold ph-lg',
text: i18n.ts.create,
handler: create,
}]);
const headerTabs = $computed(() => [{
key: 'featured',
title: i18n.ts._channel.featured,
2023-03-12 06:01:04 +09:00
icon: 'ph-fire-simple ph-bold ph-lg',
}, {
key: 'following',
title: i18n.ts._channel.following,
2023-03-12 06:01:04 +09:00
icon: 'ph-heart ph-bold ph-lg',
}, {
key: 'owned',
title: i18n.ts._channel.owned,
2023-03-12 06:01:04 +09:00
icon: 'ph-crown-simple ph-bold ph-lg',
}]);
definePageMetadata(computed(() => ({
title: i18n.ts.channel,
2023-03-12 06:01:04 +09:00
icon: 'ph-television ph-bold ph-lg',
})));
2022-09-10 07:32:05 +09:00
let swiperRef = null;
function setSwiperRef(swiper) {
swiperRef = swiper;
syncSlide(tabs.indexOf(tab));
}
function onSlideChange() {
tab = tabs[swiperRef.activeIndex];
}
function syncSlide(index) {
swiperRef.slideTo(index);
}
</script>