2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header
|
|
|
|
><MkPageHeader
|
|
|
|
v-model:tab="tab"
|
|
|
|
:actions="headerActions"
|
|
|
|
:tabs="headerTabs"
|
|
|
|
:display-back-button="true"
|
|
|
|
/></template>
|
|
|
|
<MkSpacer :content-max="800">
|
2023-05-26 04:47:10 +02:00
|
|
|
<swiper
|
2023-05-26 23:02:17 +02:00
|
|
|
:round-lengths="true"
|
2023-05-26 04:47:10 +02:00
|
|
|
:touch-angle="25"
|
|
|
|
:threshold="10"
|
2023-09-02 01:27:33 +02:00
|
|
|
:centered-slides="true"
|
2023-04-01 20:28:34 +02:00
|
|
|
:modules="[Virtual]"
|
2023-07-30 07:39:06 +02:00
|
|
|
:space-between="30"
|
2023-04-01 20:28:34 +02:00
|
|
|
:virtual="true"
|
2023-06-26 21:47:05 +02:00
|
|
|
:allow-touch-move="
|
|
|
|
defaultStore.state.swipeOnMobile &&
|
|
|
|
(deviceKind !== 'desktop' ||
|
|
|
|
defaultStore.state.swipeOnDesktop)
|
|
|
|
"
|
2023-04-01 20:28:34 +02:00
|
|
|
@swiper="setSwiperRef"
|
|
|
|
@slide-change="onSlideChange"
|
|
|
|
>
|
|
|
|
<swiper-slide>
|
2023-04-08 02:01:42 +02:00
|
|
|
<XNotes ref="notes" :pagination="notesPagination" />
|
2023-04-01 20:28:34 +02:00
|
|
|
</swiper-slide>
|
|
|
|
<swiper-slide>
|
2023-04-08 02:01:42 +02:00
|
|
|
<XUserList
|
|
|
|
ref="users"
|
|
|
|
class="_gap"
|
|
|
|
:pagination="usersPagination"
|
|
|
|
/>
|
2023-04-01 20:28:34 +02:00
|
|
|
</swiper-slide>
|
|
|
|
</swiper>
|
2023-04-08 02:01:42 +02:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-12 18:21:43 +01:00
|
|
|
<script lang="ts" setup>
|
2023-09-02 01:27:33 +02:00
|
|
|
import { computed, onMounted, ref, watch } from "vue";
|
2023-07-11 06:16:56 +02:00
|
|
|
import { Virtual } from "swiper/modules";
|
2023-04-08 02:01:42 +02:00
|
|
|
import { Swiper, SwiperSlide } from "swiper/vue";
|
2024-03-01 14:17:02 +01:00
|
|
|
import moment from "moment";
|
2023-04-08 02:01:42 +02:00
|
|
|
import XNotes from "@/components/MkNotes.vue";
|
|
|
|
import XUserList from "@/components/MkUserList.vue";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
|
|
|
import { defaultStore } from "@/store";
|
2023-06-21 23:13:46 +02:00
|
|
|
import { deviceKind } from "@/scripts/device-kind";
|
2023-10-17 03:57:20 +02:00
|
|
|
import icon from "@/scripts/icon";
|
2024-03-07 03:06:45 +01:00
|
|
|
import { me } from "@/me";
|
2023-04-08 02:01:42 +02:00
|
|
|
import "swiper/scss";
|
|
|
|
import "swiper/scss/virtual";
|
2024-03-01 14:17:02 +01:00
|
|
|
import { api } from "@/os";
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-12 18:21:43 +01:00
|
|
|
const props = defineProps<{
|
2024-03-01 14:17:02 +01:00
|
|
|
query?: string;
|
|
|
|
user?: string;
|
|
|
|
host?: string;
|
|
|
|
since?: string;
|
|
|
|
until?: string;
|
2022-01-12 18:21:43 +01:00
|
|
|
channel?: string;
|
2024-03-01 14:17:02 +01:00
|
|
|
withFiles: "0" | "1";
|
|
|
|
searchCwAndAlt: "0" | "1";
|
2022-01-12 18:21:43 +01:00
|
|
|
}>();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2024-03-01 14:17:02 +01:00
|
|
|
const userId = props.user == null ? undefined : await getUserId(props.user);
|
|
|
|
|
2023-04-01 20:28:34 +02:00
|
|
|
const notesPagination = {
|
2023-04-08 02:01:42 +02:00
|
|
|
endpoint: "notes/search" as const,
|
2022-01-12 18:21:43 +01:00
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
2024-03-01 14:17:02 +01:00
|
|
|
query: props.query ?? undefined,
|
|
|
|
userId,
|
|
|
|
host: props.host == null ? undefined : getHost(props.host),
|
|
|
|
sinceDate:
|
|
|
|
props.since == null ? undefined : getUnixTime(props.since, false),
|
2024-03-28 17:26:52 +01:00
|
|
|
untilDate: props.until == null ? undefined : getUnixTime(props.until, true),
|
2024-03-01 14:17:02 +01:00
|
|
|
withFiles: props.withFiles === "1",
|
|
|
|
searchCwAndAlt: props.searchCwAndAlt === "1",
|
2022-01-12 18:21:43 +01:00
|
|
|
channelId: props.channel,
|
2022-06-20 10:38:49 +02:00
|
|
|
})),
|
2022-01-12 18:21:43 +01:00
|
|
|
};
|
|
|
|
|
2023-04-01 20:28:34 +02:00
|
|
|
const usersPagination = {
|
2023-04-08 02:01:42 +02:00
|
|
|
endpoint: "users/search" as const,
|
2023-04-01 20:28:34 +02:00
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
2024-04-12 10:37:32 +02:00
|
|
|
// FIXME: query is necessary for user search
|
|
|
|
query: props.query!,
|
|
|
|
origin: "combined" as const,
|
2023-04-01 20:28:34 +02:00
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
2024-03-01 14:17:02 +01:00
|
|
|
async function getUserId(user: string): Promise<string> {
|
2024-03-07 03:06:45 +01:00
|
|
|
if (user === "me") return me!.id;
|
2024-03-01 14:17:02 +01:00
|
|
|
|
|
|
|
const split = (user.startsWith("@") ? user.slice(1) : user).split("@");
|
|
|
|
const username = split[0];
|
|
|
|
const host = split.length === 1 ? undefined : split[1];
|
|
|
|
|
|
|
|
return (await api("users/show", { username, host })).id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHost(host: string): string | null {
|
|
|
|
if (host === "local") return null;
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUnixTime(date: string, nextDay: boolean): number {
|
|
|
|
return moment(date, date.length === 4 ? "MMDD" : "YYYYMMDD")
|
|
|
|
.add(nextDay ? 1 : 0, "days")
|
|
|
|
.valueOf();
|
|
|
|
}
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const tabs = ["notes", "users"];
|
2023-09-02 01:16:23 +02:00
|
|
|
const tab = ref(tabs[0]);
|
2023-08-12 02:44:46 +02:00
|
|
|
watch(tab, () => syncSlide(tabs.indexOf(tab.value)));
|
2023-04-01 20:28:34 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const headerActions = computed(() => []);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const headerTabs = computed(() => [
|
2023-04-08 02:01:42 +02:00
|
|
|
{
|
|
|
|
key: "notes",
|
2023-10-17 03:57:20 +02:00
|
|
|
icon: `${icon("ph-magnifying-glass")}`,
|
2023-04-08 02:01:42 +02:00
|
|
|
title: i18n.ts.notes,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "users",
|
2023-10-17 03:57:20 +02:00
|
|
|
icon: `${icon("ph-users")}`,
|
2023-04-08 02:01:42 +02:00
|
|
|
title: i18n.ts.users,
|
|
|
|
},
|
|
|
|
]);
|
2023-04-01 20:28:34 +02:00
|
|
|
|
|
|
|
let swiperRef = null;
|
|
|
|
|
|
|
|
function setSwiperRef(swiper) {
|
|
|
|
swiperRef = swiper;
|
2023-08-12 02:44:46 +02:00
|
|
|
syncSlide(tabs.indexOf(tab.value));
|
2023-04-01 20:28:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSlideChange() {
|
2023-08-12 02:44:46 +02:00
|
|
|
tab.value = tabs[swiperRef.activeIndex];
|
2023-04-01 20:28:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function syncSlide(index) {
|
|
|
|
swiperRef.slideTo(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
syncSlide(tabs.indexOf(swiperRef.activeIndex));
|
|
|
|
});
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
definePageMetadata(
|
|
|
|
computed(() => ({
|
|
|
|
title: i18n.t("searchWith", { q: props.query }),
|
2023-10-17 03:57:20 +02:00
|
|
|
icon: `${icon("ph-magnifying-glass")}`,
|
2023-07-06 03:28:27 +02:00
|
|
|
})),
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2020-01-29 20:37:25 +01:00
|
|
|
</script>
|