hippofish/packages/client/src/pages/gallery/index.vue

158 lines
4.2 KiB
Vue
Raw Normal View History

<template>
<MkStickyContainer>
2023-04-05 07:59:41 +02:00
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs" :display-back-button="true"/></template>
2022-09-14 06:33:03 +02:00
<MkSpacer :content-max="1200">
<swiper
:modules="[Virtual]"
:space-between="20"
:virtual="true"
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)"
2022-09-14 06:33:03 +02:00
@swiper="setSwiperRef"
@slide-change="onSlideChange"
>
<swiper-slide>
<MkFolder class="_gap">
2023-03-11 22:01:04 +01:00
<template #header><i class="ph-clock ph-bold ph-lg"></i> {{ i18n.ts.recentPosts }}</template>
<MkPagination v-slot="{items}" :pagination="recentPostsPagination" :disable-auto-load="true">
<div class="vfpdbgtk">
<MkGalleryPostPreview v-for="post in items" :key="post.id" :post="post" class="post"/>
</div>
</MkPagination>
</MkFolder>
<MkFolder class="_gap">
2023-03-11 22:01:04 +01:00
<template #header><i class="ph-fire-simple ph-bold ph-lg"></i> {{ i18n.ts.popularPosts }}</template>
<MkPagination v-slot="{items}" :pagination="popularPostsPagination" :disable-auto-load="true">
<div class="vfpdbgtk">
<MkGalleryPostPreview v-for="post in items" :key="post.id" :post="post" class="post"/>
</div>
</MkPagination>
</MkFolder>
2022-09-14 06:33:03 +02:00
</swiper-slide>
<swiper-slide>
<MkPagination v-slot="{items}" :pagination="likedPostsPagination">
<div class="vfpdbgtk">
<MkGalleryPostPreview v-for="like in items" :key="like.id" :post="like.post" class="post"/>
</div>
</MkPagination>
2022-09-14 06:33:03 +02:00
</swiper-slide>
<swiper-slide>
2023-03-11 22:01:04 +01:00
<MkA to="/gallery/new" class="_link" style="margin: 16px;"><i class="ph-plus ph-bold ph-lg"></i> {{ i18n.ts.postToGallery }}</MkA>
<MkPagination v-slot="{items}" :pagination="myPostsPagination">
<div class="vfpdbgtk">
<MkGalleryPostPreview v-for="post in items" :key="post.id" :post="post" class="post"/>
</div>
</MkPagination>
2022-09-14 06:33:03 +02:00
</swiper-slide>
</swiper>
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
2022-12-12 00:19:41 +01:00
import { computed, defineComponent, watch, onMounted } from 'vue';
2022-09-14 06:33:03 +02:00
import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import MkFolder from '@/components/MkFolder.vue';
import MkPagination from '@/components/MkPagination.vue';
import MkGalleryPostPreview from '@/components/MkGalleryPostPreview.vue';
import { definePageMetadata } from '@/scripts/page-metadata';
2022-09-15 19:43:48 +02:00
import { deviceKind } from '@/scripts/device-kind';
import { i18n } from '@/i18n';
2022-06-30 14:38:34 +02:00
import { useRouter } from '@/router';
import { defaultStore } from '@/store';
2022-09-14 06:33:03 +02:00
import 'swiper/scss';
import 'swiper/scss/virtual';
2022-06-30 14:38:34 +02:00
const router = useRouter();
const props = defineProps<{
tag?: string;
}>();
2022-09-14 06:33:03 +02:00
const tabs = ['explore', 'liked', 'my'];
2022-10-26 04:19:42 +02:00
let tab = $ref(tabs[0]);
watch($$(tab), () => (syncSlide(tabs.indexOf(tab))));
let tagsRef = $ref();
const recentPostsPagination = {
endpoint: 'gallery/posts' as const,
limit: 6,
};
const popularPostsPagination = {
endpoint: 'gallery/featured' as const,
limit: 5,
};
const myPostsPagination = {
endpoint: 'i/gallery/posts' as const,
limit: 5,
};
const likedPostsPagination = {
endpoint: 'i/gallery/likes' as const,
limit: 5,
};
watch(() => props.tag, () => {
if (tagsRef) tagsRef.tags.toggleContent(props.tag == null);
});
2022-06-30 14:38:34 +02:00
const headerActions = $computed(() => [{
2023-03-11 22:01:04 +01:00
icon: 'ph-plus ph-bold ph-lg',
2022-06-30 14:38:34 +02:00
text: i18n.ts.create,
handler: () => {
router.push('/gallery/new');
},
}]);
2022-06-30 14:38:34 +02:00
const headerTabs = $computed(() => [{
key: 'explore',
title: i18n.ts.gallery,
2023-03-11 22:01:04 +01:00
icon: 'ph-image-square ph-bold ph-lg',
2022-06-30 14:38:34 +02:00
}, {
key: 'liked',
title: i18n.ts._gallery.liked,
2023-03-11 22:01:04 +01:00
icon: 'ph-heart ph-bold ph-lg',
2022-06-30 14:38:34 +02:00
}, {
key: 'my',
title: i18n.ts._gallery.my,
2023-03-11 22:01:04 +01:00
icon: 'ph-crown-simple ph-bold ph-lg',
2022-06-30 14:38:34 +02:00
}]);
definePageMetadata({
title: i18n.ts.gallery,
2023-03-11 22:01:04 +01:00
icon: 'ph-image-square ph-bold ph-lg',
});
2022-09-14 06:33:03 +02: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);
}
2022-12-12 00:19:41 +01:00
onMounted(() => {
syncSlide(tabs.indexOf(swiperRef.activeIndex));
});
</script>
<style lang="scss" scoped>
.vfpdbgtk {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
grid-gap: 12px;
margin: 0 var(--margin);
> .post {
}
}
</style>