2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2022-06-20 17:38:49 +09:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="800">
|
2023-02-25 09:01:21 +09:00
|
|
|
<MkInput v-model="searchQuery" :large="true" :autofocus="true" :debounce="true" type="search" style="margin-bottom: var(--margin);" @update:model-value="search()">
|
|
|
|
<template #prefix><i class="ti ti-search"></i></template>
|
|
|
|
</MkInput>
|
|
|
|
<MkTab v-model="searchType" style="margin-bottom: var(--margin);" @update:model-value="search()">
|
|
|
|
<option value="note">{{ i18n.ts.note }}</option>
|
|
|
|
<option value="user">{{ i18n.ts.user }}</option>
|
|
|
|
</MkTab>
|
|
|
|
|
|
|
|
<div v-if="searchType === 'note'">
|
|
|
|
<MkNotes v-if="searchQuery" ref="notes" :pagination="notePagination"/>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<MkRadios v-model="searchOrigin" style="margin-bottom: var(--margin);" @update:model-value="search()">
|
|
|
|
<option value="combined">{{ i18n.ts.all }}</option>
|
|
|
|
<option value="local">{{ i18n.ts.local }}</option>
|
|
|
|
<option value="remote">{{ i18n.ts.remote }}</option>
|
|
|
|
</MkRadios>
|
|
|
|
|
|
|
|
<MkUserList v-if="searchQuery" ref="users" :pagination="userPagination"/>
|
|
|
|
</div>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-13 02:21:43 +09:00
|
|
|
<script lang="ts" setup>
|
2023-02-25 09:01:21 +09:00
|
|
|
import { computed, onMounted } from 'vue';
|
2023-02-22 11:00:34 +09:00
|
|
|
import MkNotes from '@/components/MkNotes.vue';
|
2023-02-25 09:01:21 +09:00
|
|
|
import MkUserList from '@/components/MkUserList.vue';
|
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkTab from '@/components/MkTab.vue';
|
|
|
|
import MkRadios from '@/components/MkRadios.vue';
|
2022-01-13 02:21:43 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2023-01-08 11:15:54 +09:00
|
|
|
import * as os from '@/os';
|
2023-02-25 09:01:21 +09:00
|
|
|
import { useRouter, mainRouter } from '@/router';
|
2023-01-08 11:15:54 +09:00
|
|
|
|
|
|
|
const router = useRouter();
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-13 02:21:43 +09:00
|
|
|
const props = defineProps<{
|
|
|
|
query: string;
|
|
|
|
channel?: string;
|
2023-02-25 09:01:21 +09:00
|
|
|
type?: string;
|
|
|
|
origin?: string;
|
2022-01-13 02:21:43 +09:00
|
|
|
}>();
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-02-25 09:01:21 +09:00
|
|
|
let searchQuery = $ref('');
|
|
|
|
let searchType = $ref('note');
|
|
|
|
let searchOrigin = $ref('combined');
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
searchQuery = props.query ?? '';
|
|
|
|
searchType = props.type ?? 'note';
|
|
|
|
searchOrigin = props.origin ?? 'combined';
|
|
|
|
|
|
|
|
if (searchQuery) {
|
|
|
|
search();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const search = async () => {
|
|
|
|
const query = searchQuery.toString().trim();
|
|
|
|
|
|
|
|
if (query == null || query === '') return;
|
|
|
|
|
|
|
|
if (query.startsWith('@') && !query.includes(' ')) {
|
|
|
|
mainRouter.push(`/${query}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.startsWith('#')) {
|
|
|
|
mainRouter.push(`/tags/${encodeURIComponent(query.substr(1))}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// like 2018/03/12
|
|
|
|
if (/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}/.test(query.replace(/-/g, '/'))) {
|
|
|
|
const date = new Date(query.replace(/-/g, '/'));
|
|
|
|
|
|
|
|
// 日付しか指定されてない場合、例えば 2018/03/12 ならユーザーは
|
|
|
|
// 2018/03/12 のコンテンツを「含む」結果になることを期待するはずなので
|
|
|
|
// 23時間59分進める(そのままだと 2018/03/12 00:00:00 「まで」の
|
|
|
|
// 結果になってしまい、2018/03/12 のコンテンツは含まれない)
|
|
|
|
if (query.replace(/-/g, '/').match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/)) {
|
|
|
|
date.setHours(23, 59, 59, 999);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
//v.$root.$emit('warp', date);
|
|
|
|
os.alert({
|
|
|
|
icon: 'ti ti-history',
|
|
|
|
iconOnly: true, autoClose: true,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2023-01-08 11:15:54 +09:00
|
|
|
|
2023-02-25 09:01:21 +09:00
|
|
|
if (query.startsWith('https://')) {
|
2023-01-08 11:15:54 +09:00
|
|
|
const promise = os.api('ap/show', {
|
2023-02-25 09:01:21 +09:00
|
|
|
uri: query,
|
2023-01-08 11:15:54 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
|
|
|
|
|
|
|
const res = await promise;
|
|
|
|
|
|
|
|
if (res.type === 'User') {
|
2023-02-25 09:01:21 +09:00
|
|
|
mainRouter.push(`/@${res.object.username}@${res.object.host}`);
|
2023-01-08 11:15:54 +09:00
|
|
|
} else if (res.type === 'Note') {
|
2023-02-25 09:01:21 +09:00
|
|
|
mainRouter.push(`/notes/${res.object.id}`);
|
2023-01-08 11:15:54 +09:00
|
|
|
}
|
2023-02-25 09:01:21 +09:00
|
|
|
|
|
|
|
return;
|
2023-01-08 11:15:54 +09:00
|
|
|
}
|
|
|
|
|
2023-02-25 09:01:21 +09:00
|
|
|
window.history.replaceState('', '', `/search?q=${encodeURIComponent(query)}&type=${searchType}${searchType === 'user' ? `&origin=${searchOrigin}` : ''}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const notePagination = {
|
2022-01-13 02:26:10 +09:00
|
|
|
endpoint: 'notes/search' as const,
|
2022-01-13 02:21:43 +09:00
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
2023-02-25 09:01:21 +09:00
|
|
|
query: searchQuery,
|
2022-01-13 02:21:43 +09:00
|
|
|
channelId: props.channel,
|
2022-06-20 17:38:49 +09:00
|
|
|
})),
|
2022-01-13 02:21:43 +09:00
|
|
|
};
|
2023-02-25 09:01:21 +09:00
|
|
|
const userPagination = {
|
|
|
|
endpoint: 'users/search' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
|
|
|
query: searchQuery,
|
|
|
|
origin: searchOrigin,
|
|
|
|
})),
|
|
|
|
};
|
2022-01-13 02:21:43 +09:00
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => ({
|
2023-02-25 09:01:21 +09:00
|
|
|
title: searchQuery ? i18n.t('searchWith', { q: searchQuery }) : i18n.ts.search,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-search',
|
2022-06-20 17:38:49 +09:00
|
|
|
})));
|
2020-01-30 04:37:25 +09:00
|
|
|
</script>
|