From f4496ccc6d4c9c0855910efce6c7a5e429b10a4b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 7 Feb 2020 17:04:03 +0100 Subject: [PATCH] Fix search with URL fetching twice Signed-off-by: Thomas Citharel --- js/src/views/Search.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/js/src/views/Search.vue b/js/src/views/Search.vue index 98a2bdc44..9bc7eb05c 100644 --- a/js/src/views/Search.vue +++ b/js/src/views/Search.vue @@ -87,7 +87,7 @@ const tabsName = { }; }, 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: [] }; 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) { switch (index) { case SearchTabs.EVENTS: @@ -136,6 +143,12 @@ export default class Search extends Vue { 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; + } + }