[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'),
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)}`);
}

View File

@ -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)}`);
}