Add swiper to channels

This commit is contained in:
ThatOneCalculator 2022-09-09 15:32:05 -07:00
parent 038c367fd7
commit a846a2e15c
1 changed files with 56 additions and 18 deletions

View File

@ -1,39 +1,62 @@
<template> <template>
<MkStickyContainer> <MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template> <template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :content-max="700"> <swiper
<div v-if="tab === 'featured'" class="_content grwlizim featured"> :modules="[Virtual]"
<MkPagination v-slot="{items}" :pagination="featuredPagination"> :space-between="20"
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/> :virtual="true"
</MkPagination> @swiper="setSwiperRef"
</div> @slide-change="onSlideChange"
<div v-else-if="tab === 'following'" class="_content grwlizim following"> >
<MkPagination v-slot="{items}" :pagination="followingPagination"> <swiper-slide>
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/> <MkSpacer :content-max="700">
</MkPagination> <div class="_content grwlizim featured">
</div> <MkPagination v-slot="{items}" :pagination="featuredPagination">
<div v-else-if="tab === 'owned'" class="_content grwlizim owned"> <MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/>
<MkButton class="new" @click="create()"><i class="fas fa-plus"></i></MkButton> </MkPagination>
<MkPagination v-slot="{items}" :pagination="ownedPagination"> </div>
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/> </MkSpacer>
</MkPagination> </swiper-slide>
</div> <swiper-slide>
</MkSpacer> <MkSpacer :content-max="700">
<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>
</MkSpacer>
</swiper-slide>
<swiper-slide>
<MkSpacer :content-max="700">
<div class="_content grwlizim owned">
<MkButton class="new" @click="create()"><i class="fas fa-plus"></i></MkButton>
<MkPagination v-slot="{items}" :pagination="ownedPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_gap" :channel="channel"/>
</MkPagination>
</div>
</MkSpacer>
</swiper-slide>
</swiper>
</MkStickyContainer> </MkStickyContainer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, defineComponent, inject } from 'vue'; import { computed, defineComponent, inject } from 'vue';
import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import MkChannelPreview from '@/components/MkChannelPreview.vue'; import MkChannelPreview from '@/components/MkChannelPreview.vue';
import MkPagination from '@/components/MkPagination.vue'; import MkPagination from '@/components/MkPagination.vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import { useRouter } from '@/router'; import { useRouter } from '@/router';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import 'swiper/scss';
import 'swiper/scss/virtual';
const router = useRouter(); const router = useRouter();
let tab = $ref('featured'); let tab = $ref('featured');
const tabs = ['featured', 'following', 'owned'];
const featuredPagination = { const featuredPagination = {
endpoint: 'channels/featured' as const, endpoint: 'channels/featured' as const,
@ -76,4 +99,19 @@ definePageMetadata(computed(() => ({
title: i18n.ts.channel, title: i18n.ts.channel,
icon: 'fas fa-satellite-dish', icon: 'fas fa-satellite-dish',
}))); })));
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> </script>