[Client] Resolve #3686

This commit is contained in:
syuilo 2018-12-20 01:09:35 +09:00
parent d059d7f972
commit a5f09c90dd
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
2 changed files with 41 additions and 5 deletions

View file

@ -14,16 +14,34 @@ export default Vue.extend({
i18n: i18n('desktop/views/components/ui.header.search.vue'), i18n: i18n('desktop/views/components/ui.header.search.vue'),
data() { data() {
return { return {
q: '' q: '',
wait: false
}; };
}, },
methods: { methods: {
onSubmit() { async onSubmit() {
if (this.wait) return;
const q = this.q.trim(); const q = this.q.trim();
if (q.startsWith('@')) { if (q.startsWith('@')) {
this.$router.push(`/${q}`); this.$router.push(`/${q}`);
} else if (q.startsWith('#')) { } else if (q.startsWith('#')) {
this.$router.push(`/tags/${encodeURIComponent(q.substr(1))}`); 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 { } else {
this.$router.push(`/search?q=${encodeURIComponent(q)}`); this.$router.push(`/search?q=${encodeURIComponent(q)}`);
} }

View file

@ -60,7 +60,8 @@ export default Vue.extend({
hasGameInvitation: false, hasGameInvitation: false,
connection: null, connection: null,
aboutUrl: `/docs/${lang}/about`, aboutUrl: `/docs/${lang}/about`,
announcements: [] announcements: [],
searching: false,
}; };
}, },
@ -95,17 +96,34 @@ export default Vue.extend({
methods: { methods: {
search() { search() {
if (this.searching) return;
this.$root.dialog({ this.$root.dialog({
title: this.$t('search'), title: this.$t('search'),
input: true input: true
}).then(({ canceled, result: query }) => { }).then(async ({ canceled, result: query }) => {
if (canceled) return; if (canceled) return;
const q = query.trim(); const q = this.q.trim();
if (q.startsWith('@')) { if (q.startsWith('@')) {
this.$router.push(`/${q}`); this.$router.push(`/${q}`);
} else if (q.startsWith('#')) { } else if (q.startsWith('#')) {
this.$router.push(`/tags/${encodeURIComponent(q.substr(1))}`); 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 { } else {
this.$router.push(`/search?q=${encodeURIComponent(q)}`); this.$router.push(`/search?q=${encodeURIComponent(q)}`);
} }