2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2022-06-20 17:38:49 +09:00
|
|
|
<MkStickyContainer>
|
2023-03-16 11:56:20 +09:00
|
|
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
|
2023-05-19 16:20:53 +09:00
|
|
|
<MkSpacer v-if="tab === 'note'" :contentMax="800">
|
2023-05-11 18:10:34 +09:00
|
|
|
<div v-if="notesSearchAvailable">
|
|
|
|
<XNote/>
|
2023-02-25 09:01:21 +09:00
|
|
|
</div>
|
|
|
|
<div v-else>
|
2023-03-16 11:56:20 +09:00
|
|
|
<MkInfo warn>{{ i18n.ts.notesSearchNotAvailable }}</MkInfo>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
|
2023-05-19 16:20:53 +09:00
|
|
|
<MkSpacer v-else-if="tab === 'user'" :contentMax="800">
|
2023-05-11 18:10:34 +09:00
|
|
|
<XUser/>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkSpacer>
|
2023-04-24 02:37:42 +09:00
|
|
|
<MkSpacer v-else-if="tab === 'event'" :content-max="800">
|
|
|
|
<div class="_gaps">
|
|
|
|
<div class="_gaps">
|
2023-04-24 02:53:44 +09:00
|
|
|
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search">
|
|
|
|
<template #prefix><i class="ti ti-search"></i></template>
|
|
|
|
</MkInput>
|
2023-04-24 02:37:42 +09:00
|
|
|
<MkSelect v-model="eventSort" small>
|
2023-04-24 12:29:47 +09:00
|
|
|
<template #label>{{ i18n.ts.sort }}</template>
|
|
|
|
<option value="startDate">{{ i18n.ts._event.startDate }}</option>
|
|
|
|
<option value="createdAt">{{ i18n.ts.reverseChronological }}</option>
|
2023-04-24 02:37:42 +09:00
|
|
|
</MkSelect>
|
2023-04-24 03:51:54 +09:00
|
|
|
<section>
|
|
|
|
<MkInput v-model="startDate" small type="date" class="input">
|
2023-04-24 12:29:47 +09:00
|
|
|
<template #label>{{ i18n.ts._event.startDate }}</template>
|
2023-04-24 03:51:54 +09:00
|
|
|
</MkInput>
|
|
|
|
<MkInput v-model="endDate" small type="date" class="input">
|
2023-04-24 12:29:47 +09:00
|
|
|
<template #label>{{ i18n.ts._event.endDate }}</template>
|
2023-04-24 03:51:54 +09:00
|
|
|
</MkInput>
|
|
|
|
</section>
|
2023-04-24 02:37:42 +09:00
|
|
|
<MkButton large primary gradate rounded @click="search">{{ i18n.ts.search }}</MkButton>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<MkFoldableSection v-if="eventPagination">
|
|
|
|
<template #header>{{ i18n.ts.searchResult }}</template>
|
|
|
|
<MkNotes :key="key" :pagination="eventPagination" :get-date="eventSort === 'startDate' ? note => note.event.start : undefined"/>
|
|
|
|
</MkFoldableSection>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkStickyContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-13 02:21:43 +09:00
|
|
|
<script lang="ts" setup>
|
2023-05-11 18:10:34 +09:00
|
|
|
import { computed, defineAsyncComponent, 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 MkRadios from '@/components/MkRadios.vue';
|
2023-03-16 11:56:20 +09:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-04-24 02:37:42 +09:00
|
|
|
import MkSelect from '@/components/MkSelect.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-03-16 11:56:20 +09:00
|
|
|
import { $i } from '@/account';
|
|
|
|
import { instance } from '@/instance';
|
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2023-06-18 04:47:08 +09:00
|
|
|
import { $ref } from 'vue/macros';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-05-11 18:10:34 +09:00
|
|
|
const XNote = defineAsyncComponent(() => import('./search.note.vue'));
|
|
|
|
const XUser = defineAsyncComponent(() => import('./search.user.vue'));
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-03-16 11:56:20 +09:00
|
|
|
let tab = $ref('note');
|
2023-02-25 09:01:21 +09:00
|
|
|
let searchQuery = $ref('');
|
2023-06-18 04:47:08 +09:00
|
|
|
let key = $ref('');
|
2023-02-25 09:01:21 +09:00
|
|
|
let searchOrigin = $ref('combined');
|
2023-04-24 02:37:42 +09:00
|
|
|
let eventSort = $ref('startDate');
|
2023-03-16 11:56:20 +09:00
|
|
|
let notePagination = $ref();
|
|
|
|
let userPagination = $ref();
|
2023-04-24 02:37:42 +09:00
|
|
|
let eventPagination = $ref();
|
2023-04-24 03:51:54 +09:00
|
|
|
let startDate = $ref(null);
|
|
|
|
let endDate = $ref(null);
|
2023-03-16 11:56:20 +09:00
|
|
|
|
|
|
|
const notesSearchAvailable = (($i == null && instance.policies.canSearchNotes) || ($i != null && $i.policies.canSearchNotes));
|
2023-02-25 09:01:21 +09:00
|
|
|
|
2023-03-16 11:56:20 +09:00
|
|
|
async function search() {
|
2023-02-25 09:01:21 +09:00
|
|
|
const query = searchQuery.toString().trim();
|
|
|
|
|
2023-04-24 02:53:44 +09:00
|
|
|
// only notes/users search require the query string
|
2023-04-24 02:37:42 +09:00
|
|
|
if ((query == null || query === '') && tab !== 'event') return;
|
2023-02-25 09:01:21 +09:00
|
|
|
|
2023-03-29 17:22:34 +09:00
|
|
|
if (query.startsWith('https://')) {
|
|
|
|
const promise = os.api('ap/show', {
|
|
|
|
uri: query,
|
|
|
|
});
|
|
|
|
|
|
|
|
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
|
|
|
|
|
|
|
const res = await promise;
|
|
|
|
|
|
|
|
if (res.type === 'User') {
|
|
|
|
router.push(`/@${res.object.username}@${res.object.host}`);
|
|
|
|
} else if (res.type === 'Note') {
|
|
|
|
router.push(`/notes/${res.object.id}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-16 11:56:20 +09:00
|
|
|
if (tab === 'note') {
|
|
|
|
notePagination = {
|
|
|
|
endpoint: 'notes/search',
|
|
|
|
limit: 10,
|
|
|
|
params: {
|
|
|
|
query: searchQuery,
|
|
|
|
channelId: props.channel,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} else if (tab === 'user') {
|
|
|
|
userPagination = {
|
|
|
|
endpoint: 'users/search',
|
|
|
|
limit: 10,
|
|
|
|
params: {
|
|
|
|
query: searchQuery,
|
|
|
|
origin: searchOrigin,
|
|
|
|
},
|
|
|
|
};
|
2023-04-24 02:37:42 +09:00
|
|
|
} else if (tab === 'event') {
|
|
|
|
eventPagination = {
|
|
|
|
endpoint: 'notes/events/search',
|
|
|
|
limit: 10,
|
2023-04-24 12:29:47 +09:00
|
|
|
offsetMode: true,
|
2023-04-24 02:37:42 +09:00
|
|
|
params: {
|
2023-04-24 03:51:54 +09:00
|
|
|
query: !searchQuery ? undefined : searchQuery,
|
2023-04-24 02:37:42 +09:00
|
|
|
sortBy: eventSort,
|
2023-04-24 03:51:54 +09:00
|
|
|
sinceDate: startDate ? (new Date(startDate)).getTime() : undefined,
|
|
|
|
untilDate: endDate ? (new Date(endDate)).getTime() + 1000 * 3600 * 24 : undefined,
|
2023-04-24 02:37:42 +09:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// only refresh search on query/key change
|
|
|
|
key = JSON.stringify(eventPagination);
|
|
|
|
|
|
|
|
return;
|
2023-02-25 09:01:21 +09:00
|
|
|
}
|
|
|
|
|
2023-03-16 11:56:20 +09:00
|
|
|
key = query;
|
|
|
|
}
|
2022-01-13 02:21:43 +09:00
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
2023-03-16 11:56:20 +09:00
|
|
|
const headerTabs = $computed(() => [{
|
|
|
|
key: 'note',
|
|
|
|
title: i18n.ts.notes,
|
|
|
|
icon: 'ti ti-pencil',
|
|
|
|
}, {
|
|
|
|
key: 'user',
|
|
|
|
title: i18n.ts.users,
|
|
|
|
icon: 'ti ti-users',
|
2023-04-24 02:37:42 +09:00
|
|
|
}, {
|
|
|
|
key: 'event',
|
2023-04-24 12:29:47 +09:00
|
|
|
title: i18n.ts.events,
|
2023-04-24 02:37:42 +09:00
|
|
|
icon: 'ti ti-calendar',
|
2023-03-16 11:56:20 +09:00
|
|
|
}]);
|
2022-06-20 17:38:49 +09:00
|
|
|
|
|
|
|
definePageMetadata(computed(() => ({
|
2023-05-11 18:10:34 +09:00
|
|
|
title: 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>
|