jormungandr-bite/packages/client/src/pages/explore.vue

123 lines
3.2 KiB
Vue
Raw Normal View History

<template>
<MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
<div class="lznhrdub">
2022-09-13 17:36:58 -06:00
<MkSpacer :content-max="1200">
<swiper
:modules="[Virtual]"
:space-between="20"
:virtual="true"
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)"
2022-09-13 17:36:58 -06:00
@swiper="setSwiperRef"
@slide-change="onSlideChange"
>
<swiper-slide>
<XFeatured/>
</swiper-slide>
<swiper-slide>
<XUsers/>
</swiper-slide>
<swiper-slide>
2022-09-09 13:09:12 -06:00
<div>
<MkInput v-model="searchQuery" :debounce="true" type="search" class="_formBlock">
2022-11-06 19:49:47 -07:00
<template #prefix><i class="ph-magnifying-glass-bold ph-lg"></i></template>
2022-09-09 13:09:12 -06:00
<template #label>{{ i18n.ts.searchUser }}</template>
</MkInput>
<MkRadios v-model="searchOrigin" class="_formBlock">
<option value="combined">{{ i18n.ts.all }}</option>
<option value="local">{{ i18n.ts.local }}</option>
<option value="remote">{{ i18n.ts.remote }}</option>
</MkRadios>
</div>
<XUserList v-if="searchQuery" ref="searchEl" class="_gap" :pagination="searchPagination"/>
2022-09-13 17:36:58 -06:00
</swiper-slide>
</swiper>
</MkSpacer>
</div>
</MkStickyContainer>
</template>
<script lang="ts" setup>
2022-11-12 14:38:28 -07:00
import { computed, watch, onMounted } from 'vue';
2022-09-09 13:09:12 -06:00
import { Virtual } from 'swiper';
2022-10-25 12:54:08 -06:00
import { Swiper, SwiperSlide } from 'swiper/vue';
import XFeatured from './explore.featured.vue';
import XUsers from './explore.users.vue';
2022-09-13 17:36:58 -06:00
import type MkFolder from '@/components/MkFolder.vue';
2021-11-11 10:02:25 -07:00
import MkInput from '@/components/form/input.vue';
import MkRadios from '@/components/form/radios.vue';
import { definePageMetadata } from '@/scripts/page-metadata';
2022-09-15 11:43:48 -06:00
import { deviceKind } from '@/scripts/device-kind';
import { i18n } from '@/i18n';
import XUserList from '@/components/MkUserList.vue';
import { defaultStore } from '@/store';
2022-09-09 13:09:12 -06:00
import 'swiper/scss';
import 'swiper/scss/virtual';
const props = defineProps<{
tag?: string;
}>();
2022-09-09 14:56:42 -06:00
const tabs = ['featured', 'users', 'search'];
2022-10-25 20:19:35 -06:00
let tab = $ref(tabs[0]);
watch($$(tab), () => (syncSlide(tabs.indexOf(tab))));
2022-09-09 13:09:12 -06:00
let tagsEl = $ref<InstanceType<typeof MkFolder>>();
let searchQuery = $ref(null);
let searchOrigin = $ref('combined');
watch(() => props.tag, () => {
if (tagsEl) tagsEl.toggleContent(props.tag == null);
});
const searchPagination = {
endpoint: 'users/search' as const,
limit: 10,
params: computed(() => (searchQuery && searchQuery !== '') ? {
query: searchQuery,
origin: searchOrigin,
} : null),
};
const headerActions = $computed(() => []);
const headerTabs = $computed(() => [{
key: 'featured',
2022-11-06 19:49:47 -07:00
icon: 'ph-lightning-bold ph-lg',
title: i18n.ts.featured,
}, {
2022-07-13 03:09:41 -06:00
key: 'users',
2022-11-06 19:49:47 -07:00
icon: 'ph-users-bold ph-lg',
title: i18n.ts.users,
}, {
key: 'search',
2022-11-06 19:49:47 -07:00
icon: 'ph-magnifying-glass-bold ph-lg',
title: i18n.ts.search,
}]);
definePageMetadata(computed(() => ({
title: i18n.ts.explore,
2022-11-06 19:49:47 -07:00
icon: 'ph-hash-bold ph-lg',
})));
2022-09-09 13:09:12 -06:00
let swiperRef = null;
function setSwiperRef(swiper) {
swiperRef = swiper;
2022-09-09 14:59:15 -06:00
syncSlide(tabs.indexOf(tab));
2022-09-09 13:09:12 -06:00
}
function onSlideChange() {
2022-10-25 20:19:35 -06:00
tab = tabs[swiperRef.activeIndex];
2022-09-09 13:09:12 -06:00
}
function syncSlide(index) {
swiperRef.slideTo(index);
}
2022-11-12 14:38:28 -07:00
onMounted(() => {
syncSlide(tabs.indexOf(swiperRef.activeIndex));
});
</script>