Fix search with URL fetching twice

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-02-07 17:04:03 +01:00
parent 94df5bd1be
commit f4496ccc6d
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -87,7 +87,7 @@ const tabsName = {
}; };
}, },
skip() { skip() {
return !this.searchTerm; return !this.searchTerm || this.isURL(this.searchTerm);
}, },
}, },
}, },
@ -104,6 +104,13 @@ export default class Search extends Vue {
searchGroups: SearchGroup = { total: 0, elements: [] }; searchGroups: SearchGroup = { total: 0, elements: [] };
activeTab: SearchTabs = tabsName[this.searchType]; activeTab: SearchTabs = tabsName[this.searchType];
@Watch('searchEvents')
async redirectURLToEvent() {
if (this.searchEvents.total === 1 && this.isURL(this.searchTerm)) {
return await this.$router.replace({ name: RouteName.EVENT, params: { uuid: this.searchEvents.elements[0].uuid } });
}
}
changeTab(index: number) { changeTab(index: number) {
switch (index) { switch (index) {
case SearchTabs.EVENTS: case SearchTabs.EVENTS:
@ -136,6 +143,12 @@ export default class Search extends Vue {
return this.searchGroups.elements.map(group => Object.assign(new Group(), group)); return this.searchGroups.elements.map(group => Object.assign(new Group(), group));
} }
isURL(url: string): boolean {
const a = document.createElement('a');
a.href = url;
return (a.host && a.host !== window.location.host) as boolean;
}
} }
</script> </script>
<style lang="scss"> <style lang="scss">