rudeshark.net/packages/client/src/pages/explore.vue

130 lines
3.1 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-09 21:09:12 +02:00
<swiper
:modules="[Virtual]"
:space-between="20"
:virtual="true"
@swiper="setSwiperRef"
@slide-change="onSlideChange"
>
<swiper-slide>
<XFeatured/>
</swiper-slide>
<swiper-slide>
<XUsers/>
</swiper-slide>
<swiper-slide>
<MkSpacer :content-max="1200">
<div>
<MkInput v-model="searchQuery" :debounce="true" type="search" class="_formBlock">
<template #prefix><i class="fas fa-search"></i></template>
<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"/>
</MkSpacer>
</swiper-slide>
</swiper>
</div>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { computed, watch } from 'vue';
2022-09-09 21:09:12 +02:00
import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import XFeatured from './explore.featured.vue';
import XUsers from './explore.users.vue';
import MkFolder from '@/components/MkFolder.vue';
2021-11-11 18:02:25 +01:00
import MkInput from '@/components/form/input.vue';
import MkRadios from '@/components/form/radios.vue';
import number from '@/filters/number';
import * as os from '@/os';
import { definePageMetadata } from '@/scripts/page-metadata';
import { i18n } from '@/i18n';
import { instance } from '@/instance';
import XUserList from '@/components/MkUserList.vue';
2022-09-09 21:09:12 +02:00
import 'swiper/scss';
import 'swiper/scss/virtual';
const props = defineProps<{
tag?: string;
}>();
2022-09-09 21:09:12 +02:00
// let tab = $ref('featured');
const tab = $computed({
get: () => getSrc(),
set: (x) => {
syncSlide(['featured', 'users', 'search'].indexOf(x));
},
});
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',
icon: 'fas fa-bolt',
title: i18n.ts.featured,
}, {
2022-07-13 11:09:41 +02:00
key: 'users',
icon: 'fas fa-users',
title: i18n.ts.users,
}, {
key: 'search',
icon: 'fas fa-magnifying-glass',
title: i18n.ts.search,
}]);
definePageMetadata(computed(() => ({
title: i18n.ts.explore,
icon: 'fas fa-hashtag',
})));
2022-09-09 21:09:12 +02:00
let swiperRef = null;
function setSwiperRef(swiper) {
swiperRef = swiper;
}
function onSlideChange() {
saveSrc(timelines[swiperRef.activeIndex]);
}
function syncSlide(index) {
swiperRef.slideTo(index);
}
function getSrc() {
const dSrc = $ref('featured');
syncSlide(dSrc);
return dSrc;
}
</script>