From ddff3ac1621614b424e4a6a3c0ddb7efc1ae1cb9 Mon Sep 17 00:00:00 2001 From: Nachtalb Date: Fri, 30 Apr 2021 01:07:31 +0200 Subject: [PATCH] Stay in chan during search by searching on /chat-:id/search --- client/components/MessageSearchForm.vue | 3 +- client/components/Windows/SearchResults.vue | 33 +++++++-------------- client/js/router.js | 2 +- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/client/components/MessageSearchForm.vue b/client/components/MessageSearchForm.vue index 09a65347..233e099f 100644 --- a/client/components/MessageSearchForm.vue +++ b/client/components/MessageSearchForm.vue @@ -131,8 +131,7 @@ export default { .push({ name: "SearchResults", params: { - uuid: this.network.uuid, - target: this.channel.name, + id: this.channel.id, }, query: { q: this.searchInput, diff --git a/client/components/Windows/SearchResults.vue b/client/components/Windows/SearchResults.vue index 732622a2..ed307cf5 100644 --- a/client/components/Windows/SearchResults.vue +++ b/client/components/Windows/SearchResults.vue @@ -17,8 +17,7 @@
Searching in - {{ $route.params.target }} forSearching in {{ channel.name }} for {{ $route.query.q }} @@ -122,15 +121,8 @@ export default { return this.search.results.slice().reverse(); }, chan() { - if (!this.search) { - return; - } - - const chan = this.$store.getters.findChannelOnNetwork( - this.search.networkUuid, - this.search.target - ); - return chan; + const chanId = parseInt(this.$route.params.id, 10); + return this.$store.getters.findChannel(chanId); }, network() { if (!this.chan) { @@ -148,14 +140,13 @@ export default { }, }, watch: { - "$route.params.uuid"() { - this.doSearch(); - }, - "$route.params.target"() { + "$route.params.id"() { this.doSearch(); + this.setActiveChannel(); }, "$route.query.q"() { this.doSearch(); + this.setActiveChannel(); }, messages() { this.moreResultsAvailable = this.messages.length && !(this.messages.length % 100); @@ -170,11 +161,9 @@ export default { }); } }, - chan() { - this.setActiveChannel(); - }, }, mounted() { + this.setActiveChannel(); this.doSearch(); this.$root.$on("re-search", this.doSearch); // Enable MessageSearchForm to search for the same query again }, @@ -203,8 +192,8 @@ export default { } socket.emit("search", { - networkUuid: this.$route.params.uuid, - channelName: this.$route.params.target, + networkUuid: this.network.uuid, + channelName: this.channel.name, searchTerm: this.$route.query.q, offset: this.offset, }); @@ -217,8 +206,8 @@ export default { this.oldChatHeight = this.$refs.chat.scrollHeight; socket.emit("search", { - networkUuid: this.$route.params.uuid, - channelName: this.$route.params.target, + networkUuid: this.network.uuid, + channelName: this.channel.name, searchTerm: this.$route.query.q, offset: this.offset + 1, }); diff --git a/client/js/router.js b/client/js/router.js index 108bf4cc..a6be4368 100644 --- a/client/js/router.js +++ b/client/js/router.js @@ -66,7 +66,7 @@ const router = new VueRouter({ }, { name: "SearchResults", - path: "/search/:uuid/:target", + path: "/chan-:id/search", component: SearchResults, }, ],