From a5f09c90ddbbd5623572f546d075617bddd9a660 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 20 Dec 2018 01:09:35 +0900 Subject: [PATCH] [Client] Resolve #3686 --- .../views/components/ui.header.search.vue | 22 +++++++++++++++-- .../app/mobile/views/components/ui.nav.vue | 24 ++++++++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/client/app/desktop/views/components/ui.header.search.vue b/src/client/app/desktop/views/components/ui.header.search.vue index c2f9eab0a..4ade74bc6 100644 --- a/src/client/app/desktop/views/components/ui.header.search.vue +++ b/src/client/app/desktop/views/components/ui.header.search.vue @@ -14,16 +14,34 @@ export default Vue.extend({ i18n: i18n('desktop/views/components/ui.header.search.vue'), data() { return { - q: '' + q: '', + wait: false }; }, methods: { - onSubmit() { + async onSubmit() { + if (this.wait) return; + const q = this.q.trim(); if (q.startsWith('@')) { this.$router.push(`/${q}`); } else if (q.startsWith('#')) { this.$router.push(`/tags/${encodeURIComponent(q.substr(1))}`); + } else if (q.startsWith('https://')) { + this.wait = true; + try { + const res = await this.$root.api('ap/show', { + uri: q + }); + if (res.type == 'User') { + this.$router.push(`/@${res.object.username}@${res.object.host}`); + } else if (res.type == 'Note') { + this.$router.push(`/notes/${res.object.id}`); + } + } catch (e) { + // TODO + } + this.wait = false; } else { this.$router.push(`/search?q=${encodeURIComponent(q)}`); } diff --git a/src/client/app/mobile/views/components/ui.nav.vue b/src/client/app/mobile/views/components/ui.nav.vue index d12a6f7d2..ebd19e9f5 100644 --- a/src/client/app/mobile/views/components/ui.nav.vue +++ b/src/client/app/mobile/views/components/ui.nav.vue @@ -60,7 +60,8 @@ export default Vue.extend({ hasGameInvitation: false, connection: null, aboutUrl: `/docs/${lang}/about`, - announcements: [] + announcements: [], + searching: false, }; }, @@ -95,17 +96,34 @@ export default Vue.extend({ methods: { search() { + if (this.searching) return; + this.$root.dialog({ title: this.$t('search'), input: true - }).then(({ canceled, result: query }) => { + }).then(async ({ canceled, result: query }) => { if (canceled) return; - const q = query.trim(); + const q = this.q.trim(); if (q.startsWith('@')) { this.$router.push(`/${q}`); } else if (q.startsWith('#')) { this.$router.push(`/tags/${encodeURIComponent(q.substr(1))}`); + } else if (q.startsWith('https://')) { + this.searching = true; + try { + const res = await this.$root.api('ap/show', { + uri: q + }); + if (res.type == 'User') { + this.$router.push(`/@${res.object.username}@${res.object.host}`); + } else if (res.type == 'Note') { + this.$router.push(`/notes/${res.object.id}`); + } + } catch (e) { + // TODO + } + this.searching = false; } else { this.$router.push(`/search?q=${encodeURIComponent(q)}`); }