mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-20 17:48:11 +09:00
98 lines
2.2 KiB
Vue
98 lines
2.2 KiB
Vue
<template>
|
|
<MkStickyContainer>
|
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
|
<MkSpacer :content-max="800">
|
|
<swiper
|
|
:modules="[Virtual]"
|
|
:space-between="20"
|
|
:virtual="true"
|
|
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)"
|
|
@swiper="setSwiperRef"
|
|
@slide-change="onSlideChange"
|
|
>
|
|
<swiper-slide>
|
|
<XNotes ref="notes" :pagination="notesPagination"/>
|
|
</swiper-slide>
|
|
<swiper-slide>
|
|
<XUserList ref="searchEl" class="_gap" :pagination="usersPagination"/>
|
|
</swiper-slide>
|
|
</swiper>
|
|
</MkSpacer>
|
|
</MkStickyContainer>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { computed, watch, onMounted } from 'vue';
|
|
import { Virtual } from 'swiper';
|
|
import { Swiper, SwiperSlide } from 'swiper/vue';
|
|
import XNotes from '@/components/MkNotes.vue';
|
|
import { i18n } from '@/i18n';
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
import { defaultStore } from '@/store';
|
|
import 'swiper/scss';
|
|
import 'swiper/scss/virtual';
|
|
|
|
const props = defineProps<{
|
|
query: string;
|
|
channel?: string;
|
|
}>();
|
|
|
|
const notesPagination = {
|
|
endpoint: 'notes/search' as const,
|
|
limit: 10,
|
|
params: computed(() => ({
|
|
query: props.query,
|
|
channelId: props.channel,
|
|
})),
|
|
};
|
|
|
|
const usersPagination = {
|
|
endpoint: 'users/search' as const,
|
|
limit: 10,
|
|
params: computed(() => ({
|
|
query: props.query,
|
|
origin: 'combined',
|
|
})),
|
|
};
|
|
|
|
const tabs = ['search', 'users'];
|
|
let tab = $ref(tabs[0]);
|
|
watch($$(tab), () => (syncSlide(tabs.indexOf(tab))));
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
const headerTabs = $computed(() => [ {
|
|
key: 'search',
|
|
icon: 'ph-magnifying-glass ph-bold ph-lg',
|
|
title: i18n.ts.search,
|
|
}, {
|
|
key: 'users',
|
|
icon: 'ph-users ph-bold ph-lg',
|
|
title: i18n.ts.users,
|
|
}]);
|
|
|
|
let swiperRef = null;
|
|
|
|
function setSwiperRef(swiper) {
|
|
swiperRef = swiper;
|
|
syncSlide(tabs.indexOf(tab));
|
|
}
|
|
|
|
function onSlideChange() {
|
|
tab = tabs[swiperRef.activeIndex];
|
|
}
|
|
|
|
function syncSlide(index) {
|
|
swiperRef.slideTo(index);
|
|
}
|
|
|
|
onMounted(() => {
|
|
syncSlide(tabs.indexOf(swiperRef.activeIndex));
|
|
});
|
|
|
|
definePageMetadata(computed(() => ({
|
|
title: i18n.t('searchWith', { q: props.query }),
|
|
icon: 'ph-magnifying-glass ph-bold ph-lg',
|
|
})));
|
|
</script>
|