From 3c177a06ec0e2aded4fb6ac5eb9d8ced2edb4108 Mon Sep 17 00:00:00 2001 From: guemax <93522160+guemax@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:55:04 +0200 Subject: [PATCH] fix: update search text and title when route changes (#3701) --- src/components/NavBar.vue | 12 ++++++++++-- src/components/SearchResults.vue | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index 85764d1e..0e7fc6ec 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -152,14 +152,22 @@ export default { return _this.getPreferenceBoolean("searchHistory", false) && localStorage.getItem("search_history"); }, }, + watch: { + $route() { + this.updateSearchTextFromURLSearchParams(); + }, + }, mounted() { this.fetchAuthConfig(); - const query = new URLSearchParams(window.location.search).get("search_query"); - if (query) this.onSearchTextChange(query); + this.updateSearchTextFromURLSearchParams(); this.focusOnSearchBar(); this.homePagePath = this.getHomePage(this); }, methods: { + updateSearchTextFromURLSearchParams() { + const query = new URLSearchParams(window.location.search).get("search_query"); + if (query) this.onSearchTextChange(query); + }, // focus on search bar when Ctrl+k is pressed focusOnSearchBar() { hotkeys("ctrl+k", event => { diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index 54d0cd4d..0cca8c94 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -56,6 +56,11 @@ export default { this.updateResults(); this.saveQueryToHistory(); }, + updated() { + if (this.$route.query.search_query !== undefined) { + document.title = this.$route.query.search_query + " - Piped"; + } + }, activated() { this.handleRedirect(); window.addEventListener("scroll", this.handleScroll);