enhance(client): tweak search page
This commit is contained in:
parent
6da6c4dd45
commit
925cc06aea
|
@ -973,6 +973,7 @@ rolesAssignedToMe: "自分に割り当てられたロール"
|
||||||
resetPasswordConfirm: "パスワードリセットしますか?"
|
resetPasswordConfirm: "パスワードリセットしますか?"
|
||||||
sensitiveWords: "センシティブワード"
|
sensitiveWords: "センシティブワード"
|
||||||
sensitiveWordsDescription: "設定したワードが含まれるノートの公開範囲をホームにします。改行で区切って複数設定できます。"
|
sensitiveWordsDescription: "設定したワードが含まれるノートの公開範囲をホームにします。改行で区切って複数設定できます。"
|
||||||
|
notesSearchNotAvailable: "ノート検索は利用できません。"
|
||||||
|
|
||||||
_achievements:
|
_achievements:
|
||||||
earnedAt: "獲得日時"
|
earnedAt: "獲得日時"
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { computed, reactive } from 'vue';
|
||||||
import { $i } from './account';
|
import { $i } from './account';
|
||||||
import { miLocalStorage } from './local-storage';
|
import { miLocalStorage } from './local-storage';
|
||||||
import { openInstanceMenu } from './ui/_common_/common';
|
import { openInstanceMenu } from './ui/_common_/common';
|
||||||
|
import { lookup } from './scripts/lookup';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { ui } from '@/config';
|
import { ui } from '@/config';
|
||||||
|
@ -44,6 +45,13 @@ export const navbarItemDef = reactive({
|
||||||
icon: 'ti ti-search',
|
icon: 'ti ti-search',
|
||||||
to: '/search',
|
to: '/search',
|
||||||
},
|
},
|
||||||
|
lookup: {
|
||||||
|
title: i18n.ts.lookup,
|
||||||
|
icon: 'ti ti-world-search',
|
||||||
|
action: (ev) => {
|
||||||
|
lookup();
|
||||||
|
},
|
||||||
|
},
|
||||||
lists: {
|
lists: {
|
||||||
title: i18n.ts.lists,
|
title: i18n.ts.lists,
|
||||||
icon: 'ti ti-list',
|
icon: 'ti ti-list',
|
||||||
|
|
|
@ -75,9 +75,11 @@ const headerActions = $computed(() => [tab === 'all' ? {
|
||||||
const headerTabs = $computed(() => [{
|
const headerTabs = $computed(() => [{
|
||||||
key: 'all',
|
key: 'all',
|
||||||
title: i18n.ts.all,
|
title: i18n.ts.all,
|
||||||
|
icon: 'ti ti-point',
|
||||||
}, {
|
}, {
|
||||||
key: 'unread',
|
key: 'unread',
|
||||||
title: i18n.ts.unread,
|
title: i18n.ts.unread,
|
||||||
|
icon: 'ti ti-loader',
|
||||||
}, {
|
}, {
|
||||||
key: 'mentions',
|
key: 'mentions',
|
||||||
title: i18n.ts.mentions,
|
title: i18n.ts.mentions,
|
||||||
|
|
|
@ -1,26 +1,42 @@
|
||||||
<template>
|
<template>
|
||||||
<MkStickyContainer>
|
<MkStickyContainer>
|
||||||
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
||||||
<MkSpacer :content-max="800">
|
<MkSpacer v-if="tab === 'note'" :content-max="800">
|
||||||
<MkInput v-model="searchQuery" :large="true" :autofocus="true" :debounce="true" type="search" style="margin-bottom: var(--margin);" @update:model-value="search()">
|
<div v-if="notesSearchAvailable" class="_gaps">
|
||||||
<template #prefix><i class="ti ti-search"></i></template>
|
<div class="_gaps">
|
||||||
</MkInput>
|
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search">
|
||||||
<MkTab v-model="searchType" style="margin-bottom: var(--margin);" @update:model-value="search()">
|
<template #prefix><i class="ti ti-search"></i></template>
|
||||||
<option value="note">{{ i18n.ts.note }}</option>
|
</MkInput>
|
||||||
<option value="user">{{ i18n.ts.user }}</option>
|
<MkButton large primary gradate rounded @click="search">{{ i18n.ts.search }}</MkButton>
|
||||||
</MkTab>
|
</div>
|
||||||
|
|
||||||
<div v-if="searchType === 'note'">
|
<MkFoldableSection v-if="notePagination">
|
||||||
<MkNotes v-if="searchQuery" ref="notes" :pagination="notePagination"/>
|
<template #header>{{ i18n.ts.searchResult }}</template>
|
||||||
|
<MkNotes :key="key" :pagination="notePagination"/>
|
||||||
|
</MkFoldableSection>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<MkRadios v-model="searchOrigin" style="margin-bottom: var(--margin);" @update:model-value="search()">
|
<MkInfo warn>{{ i18n.ts.notesSearchNotAvailable }}</MkInfo>
|
||||||
<option value="combined">{{ i18n.ts.all }}</option>
|
</div>
|
||||||
<option value="local">{{ i18n.ts.local }}</option>
|
</MkSpacer>
|
||||||
<option value="remote">{{ i18n.ts.remote }}</option>
|
<MkSpacer v-else-if="tab === 'user'" :content-max="800">
|
||||||
</MkRadios>
|
<div class="_gaps">
|
||||||
|
<div class="_gaps">
|
||||||
|
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search">
|
||||||
|
<template #prefix><i class="ti ti-search"></i></template>
|
||||||
|
</MkInput>
|
||||||
|
<MkRadios v-model="searchOrigin" @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>
|
||||||
|
<MkButton large primary gradate rounded @click="search">{{ i18n.ts.search }}</MkButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
<MkUserList v-if="searchQuery" ref="users" :pagination="userPagination"/>
|
<MkFoldableSection v-if="userPagination">
|
||||||
|
<template #header>{{ i18n.ts.searchResult }}</template>
|
||||||
|
<MkUserList :key="key" :pagination="userPagination"/>
|
||||||
|
</MkFoldableSection>
|
||||||
</div>
|
</div>
|
||||||
</MkSpacer>
|
</MkSpacer>
|
||||||
</MkStickyContainer>
|
</MkStickyContainer>
|
||||||
|
@ -31,14 +47,15 @@ import { computed, onMounted } from 'vue';
|
||||||
import MkNotes from '@/components/MkNotes.vue';
|
import MkNotes from '@/components/MkNotes.vue';
|
||||||
import MkUserList from '@/components/MkUserList.vue';
|
import MkUserList from '@/components/MkUserList.vue';
|
||||||
import MkInput from '@/components/MkInput.vue';
|
import MkInput from '@/components/MkInput.vue';
|
||||||
import MkTab from '@/components/MkTab.vue';
|
|
||||||
import MkRadios from '@/components/MkRadios.vue';
|
import MkRadios from '@/components/MkRadios.vue';
|
||||||
|
import MkButton from '@/components/MkButton.vue';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { definePageMetadata } from '@/scripts/page-metadata';
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { useRouter, mainRouter } from '@/router';
|
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
||||||
|
import { $i } from '@/account';
|
||||||
const router = useRouter();
|
import { instance } from '@/instance';
|
||||||
|
import MkInfo from '@/components/MkInfo.vue';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
query: string;
|
query: string;
|
||||||
|
@ -47,97 +64,60 @@ const props = defineProps<{
|
||||||
origin?: string;
|
origin?: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
let key = $ref('');
|
||||||
|
let tab = $ref('note');
|
||||||
let searchQuery = $ref('');
|
let searchQuery = $ref('');
|
||||||
let searchType = $ref('note');
|
|
||||||
let searchOrigin = $ref('combined');
|
let searchOrigin = $ref('combined');
|
||||||
|
let notePagination = $ref();
|
||||||
|
let userPagination = $ref();
|
||||||
|
|
||||||
|
const notesSearchAvailable = (($i == null && instance.policies.canSearchNotes) || ($i != null && $i.policies.canSearchNotes));
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
tab = props.type ?? 'note';
|
||||||
searchQuery = props.query ?? '';
|
searchQuery = props.query ?? '';
|
||||||
searchType = props.type ?? 'note';
|
|
||||||
searchOrigin = props.origin ?? 'combined';
|
searchOrigin = props.origin ?? 'combined';
|
||||||
|
|
||||||
if (searchQuery) {
|
|
||||||
search();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const search = async () => {
|
async function search() {
|
||||||
const query = searchQuery.toString().trim();
|
const query = searchQuery.toString().trim();
|
||||||
|
|
||||||
if (query == null || query === '') return;
|
if (query == null || query === '') return;
|
||||||
|
|
||||||
if (query.startsWith('@') && !query.includes(' ')) {
|
if (tab === 'note') {
|
||||||
mainRouter.push(`/${query}`);
|
notePagination = {
|
||||||
return;
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.startsWith('#')) {
|
key = query;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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') {
|
|
||||||
mainRouter.push(`/@${res.object.username}@${res.object.host}`);
|
|
||||||
} else if (res.type === 'Note') {
|
|
||||||
mainRouter.push(`/notes/${res.object.id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.history.replaceState('', '', `/search?q=${encodeURIComponent(query)}&type=${searchType}${searchType === 'user' ? `&origin=${searchOrigin}` : ''}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const notePagination = {
|
|
||||||
endpoint: 'notes/search' as const,
|
|
||||||
limit: 10,
|
|
||||||
params: computed(() => ({
|
|
||||||
query: searchQuery,
|
|
||||||
channelId: props.channel,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
const userPagination = {
|
|
||||||
endpoint: 'users/search' as const,
|
|
||||||
limit: 10,
|
|
||||||
params: computed(() => ({
|
|
||||||
query: searchQuery,
|
|
||||||
origin: searchOrigin,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
|
|
||||||
const headerActions = $computed(() => []);
|
const headerActions = $computed(() => []);
|
||||||
|
|
||||||
const headerTabs = $computed(() => []);
|
const headerTabs = $computed(() => [{
|
||||||
|
key: 'note',
|
||||||
|
title: i18n.ts.notes,
|
||||||
|
icon: 'ti ti-pencil',
|
||||||
|
}, {
|
||||||
|
key: 'user',
|
||||||
|
title: i18n.ts.users,
|
||||||
|
icon: 'ti ti-users',
|
||||||
|
}]);
|
||||||
|
|
||||||
definePageMetadata(computed(() => ({
|
definePageMetadata(computed(() => ({
|
||||||
title: searchQuery ? i18n.t('searchWith', { q: searchQuery }) : i18n.ts.search,
|
title: searchQuery ? i18n.t('searchWith', { q: searchQuery }) : i18n.ts.search,
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
import * as os from '@/os';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
import { mainRouter } from '@/router';
|
||||||
|
import { Router } from '@/nirax';
|
||||||
|
|
||||||
|
export async function lookup(router?: Router) {
|
||||||
|
const _router = router ?? mainRouter;
|
||||||
|
|
||||||
|
const { canceled, result: query } = await os.inputText({
|
||||||
|
title: i18n.ts.lookup,
|
||||||
|
});
|
||||||
|
if (canceled) return;
|
||||||
|
|
||||||
|
if (query.startsWith('@') && !query.includes(' ')) {
|
||||||
|
_router.push(`/${query}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.startsWith('#')) {
|
||||||
|
_router.push(`/tags/${encodeURIComponent(query.substr(1))}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue