feat: 2つの検索画面の統合 (#9949) (#10038)

* feat: 検索画面の UI を統一

* fix: エラーの修正

* add: changelog

---------

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
Khsmty 2023-02-25 09:01:21 +09:00 committed by GitHub
parent 68e53f1526
commit 64be363adc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 137 additions and 126 deletions

View file

@ -2,7 +2,7 @@
## 13.x.x (unreleased) ## 13.x.x (unreleased)
### Improvements ### Improvements
- - feat: 検索画面の統合 (Khsmty)
### Bugfixes ### Bugfixes
- -

View file

@ -36,7 +36,6 @@ import { $i, refreshAccount, login, updateAccount, signout } from '@/account';
import { defaultStore, ColdDeviceStorage } from '@/store'; import { defaultStore, ColdDeviceStorage } from '@/store';
import { fetchInstance, instance } from '@/instance'; import { fetchInstance, instance } from '@/instance';
import { makeHotkey } from '@/scripts/hotkey'; import { makeHotkey } from '@/scripts/hotkey';
import { search } from '@/scripts/search';
import { deviceKind } from '@/scripts/device-kind'; import { deviceKind } from '@/scripts/device-kind';
import { initializeSw } from '@/scripts/initialize-sw'; import { initializeSw } from '@/scripts/initialize-sw';
import { reloadChannel } from '@/scripts/unison-reload'; import { reloadChannel } from '@/scripts/unison-reload';
@ -47,6 +46,7 @@ import { deckStore } from './ui/deck/deck-store';
import { miLocalStorage } from './local-storage'; import { miLocalStorage } from './local-storage';
import { claimAchievement, claimedAchievements } from './scripts/achievements'; import { claimAchievement, claimedAchievements } from './scripts/achievements';
import { fetchCustomEmojis } from './custom-emojis'; import { fetchCustomEmojis } from './custom-emojis';
import { mainRouter } from './router';
console.info(`Misskey v${version}`); console.info(`Misskey v${version}`);
@ -352,7 +352,9 @@ const hotkeys = {
'd': (): void => { 'd': (): void => {
defaultStore.set('darkMode', !defaultStore.state.darkMode); defaultStore.set('darkMode', !defaultStore.state.darkMode);
}, },
's': search, 's': (): void => {
mainRouter.push('/search');
}
}; };
if ($i) { if ($i) {

View file

@ -1,7 +1,6 @@
import { computed, reactive } from 'vue'; import { computed, reactive } from 'vue';
import { $i } from './account'; import { $i } from './account';
import { miLocalStorage } from './local-storage'; import { miLocalStorage } from './local-storage';
import { search } from '@/scripts/search';
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';
@ -42,7 +41,7 @@ export const navbarItemDef = reactive({
search: { search: {
title: i18n.ts.search, title: i18n.ts.search,
icon: 'ti ti-search', icon: 'ti ti-search',
action: () => search(), to: '/search',
}, },
lists: { lists: {
title: i18n.ts.lists, title: i18n.ts.lists,

View file

@ -11,23 +11,6 @@
<div v-else-if="tab === 'roles'"> <div v-else-if="tab === 'roles'">
<XRoles/> <XRoles/>
</div> </div>
<div v-else-if="tab === 'search'">
<MkSpacer :content-max="1200">
<div>
<MkInput v-model="searchQuery" :debounce="true" type="search">
<template #prefix><i class="ti ti-search"></i></template>
<template #label>{{ i18n.ts.searchUser }}</template>
</MkInput>
<MkRadios v-model="searchOrigin">
<option value="combined">{{ i18n.ts.all }}</option>
<option value="local">{{ i18n.ts.local }}</option>
<option value="remote">{{ i18n.ts.remote }}</option>
</MkRadios>
</div>
<MkUserList v-if="searchQuery" ref="searchEl" class="_margin" :pagination="searchPagination"/>
</MkSpacer>
</div>
</div> </div>
</MkStickyContainer> </MkStickyContainer>
</template> </template>
@ -38,11 +21,8 @@ import XFeatured from './explore.featured.vue';
import XUsers from './explore.users.vue'; import XUsers from './explore.users.vue';
import XRoles from './explore.roles.vue'; import XRoles from './explore.roles.vue';
import MkFoldableSection from '@/components/MkFoldableSection.vue'; import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkInput from '@/components/MkInput.vue';
import MkRadios from '@/components/MkRadios.vue';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import MkUserList from '@/components/MkUserList.vue';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
tag?: string; tag?: string;
@ -53,22 +33,11 @@ const props = withDefaults(defineProps<{
let tab = $ref(props.initialTab); let tab = $ref(props.initialTab);
let tagsEl = $shallowRef<InstanceType<typeof MkFoldableSection>>(); let tagsEl = $shallowRef<InstanceType<typeof MkFoldableSection>>();
let searchQuery = $ref(null);
let searchOrigin = $ref('combined');
watch(() => props.tag, () => { watch(() => props.tag, () => {
if (tagsEl) tagsEl.toggleContent(props.tag == null); if (tagsEl) tagsEl.toggleContent(props.tag == null);
}); });
const searchPagination = {
endpoint: 'users/search' as const,
limit: 10,
params: computed(() => (searchQuery && searchQuery !== '') ? {
query: searchQuery,
origin: searchOrigin,
} : null),
};
const headerActions = $computed(() => []); const headerActions = $computed(() => []);
const headerTabs = $computed(() => [{ const headerTabs = $computed(() => [{
@ -83,10 +52,6 @@ const headerTabs = $computed(() => [{
key: 'roles', key: 'roles',
icon: 'ti ti-badges', icon: 'ti ti-badges',
title: i18n.ts.roles, title: i18n.ts.roles,
}, {
key: 'search',
icon: 'ti ti-search',
title: i18n.ts.search,
}]); }]);
definePageMetadata(computed(() => ({ definePageMetadata(computed(() => ({

View file

@ -2,18 +2,41 @@
<MkStickyContainer> <MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template> <template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :content-max="800"> <MkSpacer :content-max="800">
<MkNotes ref="notes" :pagination="pagination"/> <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>
</MkSpacer> </MkSpacer>
</MkStickyContainer> </MkStickyContainer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'; import { computed, onMounted } from 'vue';
import MkNotes from '@/components/MkNotes.vue'; import MkNotes from '@/components/MkNotes.vue';
import MkUserList from '@/components/MkUserList.vue';
import MkInput from '@/components/MkInput.vue';
import MkTab from '@/components/MkTab.vue';
import MkRadios from '@/components/MkRadios.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 } from '@/router'; import { useRouter, mainRouter } from '@/router';
import { $i } from '@/account'; import { $i } from '@/account';
const router = useRouter(); const router = useRouter();
@ -21,14 +44,82 @@ const router = useRouter();
const props = defineProps<{ const props = defineProps<{
query: string; query: string;
channel?: string; channel?: string;
type?: string;
origin?: string;
}>(); }>();
const query = props.query; 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
// 2359( 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;
}
if ($i != null) { if ($i != null) {
if (query.startsWith('https://') || (query.startsWith('@') && !query.includes(' '))) { if (query.startsWith('https://') || (query.startsWith('@') && !query.includes(' '))) {
const promise = os.api('ap/show', { const promise = os.api('ap/show', {
uri: props.query, uri: query,
}); });
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject); os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
@ -43,21 +134,32 @@ if ($i != null) {
} }
} }
const pagination = { window.history.replaceState('', '', `/search?q=${encodeURIComponent(query)}&type=${searchType}${searchType === 'user' ? `&origin=${searchOrigin}` : ''}`);
};
const notePagination = {
endpoint: 'notes/search' as const, endpoint: 'notes/search' as const,
limit: 10, limit: 10,
params: computed(() => ({ params: computed(() => ({
query: props.query, query: searchQuery,
channelId: props.channel, 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(() => []);
definePageMetadata(computed(() => ({ definePageMetadata(computed(() => ({
title: i18n.t('searchWith', { q: props.query }), title: searchQuery ? i18n.t('searchWith', { q: searchQuery }) : i18n.ts.search,
icon: 'ti ti-search', icon: 'ti ti-search',
}))); })));
</script> </script>

View file

@ -213,6 +213,8 @@ export const routes = [{
query: { query: {
q: 'query', q: 'query',
channel: 'channel', channel: 'channel',
type: 'type',
origin: 'origin',
}, },
}, { }, {
path: '/authorize-follow', path: '/authorize-follow',

View file

@ -1,63 +0,0 @@
import * as os from '@/os';
import { i18n } from '@/i18n';
import { mainRouter } from '@/router';
export async function search() {
const { canceled, result: query } = await os.inputText({
title: i18n.ts.search,
});
if (canceled || query == null || query === '') return;
const q = query.trim();
if (q.startsWith('@') && !q.includes(' ')) {
mainRouter.push(`/${q}`);
return;
}
if (q.startsWith('#')) {
mainRouter.push(`/tags/${encodeURIComponent(q.substr(1))}`);
return;
}
// like 2018/03/12
if (/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}/.test(q.replace(/-/g, '/'))) {
const date = new Date(q.replace(/-/g, '/'));
// 日付しか指定されてない場合、例えば 2018/03/12 ならユーザーは
// 2018/03/12 のコンテンツを「含む」結果になることを期待するはずなので
// 23時間59分進める(そのままだと 2018/03/12 00:00:00 「まで」の
// 結果になってしまい、2018/03/12 のコンテンツは含まれない)
if (q.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 (q.startsWith('https://')) {
const promise = os.api('ap/show', {
uri: q,
});
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;
}
mainRouter.push(`/search?q=${encodeURIComponent(q)}`);
}

View file

@ -45,11 +45,11 @@
import { defineAsyncComponent, defineComponent } from 'vue'; import { defineAsyncComponent, defineComponent } from 'vue';
import { openInstanceMenu } from './_common_/common'; import { openInstanceMenu } from './_common_/common';
import { host } from '@/config'; import { host } from '@/config';
import { search } from '@/scripts/search';
import * as os from '@/os'; import * as os from '@/os';
import { navbarItemDef } from '@/navbar'; import { navbarItemDef } from '@/navbar';
import { openAccountMenu } from '@/account'; import { openAccountMenu } from '@/account';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import { mainRouter } from '@/router';
export default defineComponent({ export default defineComponent({
components: { components: {
@ -103,7 +103,7 @@ export default defineComponent({
}, },
search() { search() {
search(); mainRouter.push('/search');
}, },
more(ev) { more(ev) {

View file

@ -44,12 +44,12 @@
import { defineAsyncComponent, defineComponent } from 'vue'; import { defineAsyncComponent, defineComponent } from 'vue';
import { openInstanceMenu } from './_common_/common'; import { openInstanceMenu } from './_common_/common';
import { host } from '@/config'; import { host } from '@/config';
import { search } from '@/scripts/search';
import * as os from '@/os'; import * as os from '@/os';
import { navbarItemDef } from '@/navbar'; import { navbarItemDef } from '@/navbar';
import { openAccountMenu } from '@/account'; import { openAccountMenu } from '@/account';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import { StickySidebar } from '@/scripts/sticky-sidebar'; import { StickySidebar } from '@/scripts/sticky-sidebar';
import { mainRouter } from '@/router';
//import MisskeyLogo from '@assets/client/misskey.svg'; //import MisskeyLogo from '@assets/client/misskey.svg';
export default defineComponent({ export default defineComponent({
@ -120,7 +120,7 @@ export default defineComponent({
}, },
search() { search() {
search(); mainRouter.push('/search');
}, },
more(ev) { more(ev) {

View file

@ -40,7 +40,6 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import XHeader from './header.vue'; import XHeader from './header.vue';
import { host, instanceName } from '@/config'; import { host, instanceName } from '@/config';
import { search } from '@/scripts/search';
import * as os from '@/os'; import * as os from '@/os';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import { ColdDeviceStorage } from '@/store'; import { ColdDeviceStorage } from '@/store';
@ -77,7 +76,9 @@ export default defineComponent({
if (ColdDeviceStorage.get('syncDeviceDarkMode')) return; if (ColdDeviceStorage.get('syncDeviceDarkMode')) return;
this.$store.set('darkMode', !this.$store.state.darkMode); this.$store.set('darkMode', !this.$store.state.darkMode);
}, },
's': search, 's': () => {
mainRouter.push('/search');
},
'h|/': this.help, 'h|/': this.help,
}; };
}, },

View file

@ -58,7 +58,6 @@ import { ComputedRef, onMounted, provide } from 'vue';
import XHeader from './header.vue'; import XHeader from './header.vue';
import XKanban from './kanban.vue'; import XKanban from './kanban.vue';
import { host, instanceName } from '@/config'; import { host, instanceName } from '@/config';
import { search } from '@/scripts/search';
import * as os from '@/os'; import * as os from '@/os';
import { instance } from '@/instance'; import { instance } from '@/instance';
import XSigninDialog from '@/components/MkSigninDialog.vue'; import XSigninDialog from '@/components/MkSigninDialog.vue';
@ -97,7 +96,9 @@ const keymap = $computed(() => {
if (ColdDeviceStorage.get('syncDeviceDarkMode')) return; if (ColdDeviceStorage.get('syncDeviceDarkMode')) return;
defaultStore.set('darkMode', !defaultStore.state.darkMode); defaultStore.set('darkMode', !defaultStore.state.darkMode);
}, },
's': search, 's': () => {
mainRouter.push('/search');
},
}; };
}); });

View file

@ -27,7 +27,7 @@ import XSigninDialog from '@/components/MkSigninDialog.vue';
import XSignupDialog from '@/components/MkSignupDialog.vue'; import XSignupDialog from '@/components/MkSignupDialog.vue';
import * as os from '@/os'; import * as os from '@/os';
import { instance } from '@/instance'; import { instance } from '@/instance';
import { search } from '@/scripts/search'; import { mainRouter } from '@/router';
export default defineComponent({ export default defineComponent({
data() { data() {
@ -55,7 +55,9 @@ export default defineComponent({
}, {}, 'closed'); }, {}, 'closed');
}, },
search, search() {
mainRouter.push('/search');
},
}, },
}); });
</script> </script>