fix: update search text and title when route changes (#3701)

This commit is contained in:
guemax 2024-07-15 12:55:04 +02:00 committed by GitHub
parent 1ae1688a82
commit 3c177a06ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -152,14 +152,22 @@ export default {
return _this.getPreferenceBoolean("searchHistory", false) && localStorage.getItem("search_history"); return _this.getPreferenceBoolean("searchHistory", false) && localStorage.getItem("search_history");
}, },
}, },
watch: {
$route() {
this.updateSearchTextFromURLSearchParams();
},
},
mounted() { mounted() {
this.fetchAuthConfig(); this.fetchAuthConfig();
const query = new URLSearchParams(window.location.search).get("search_query"); this.updateSearchTextFromURLSearchParams();
if (query) this.onSearchTextChange(query);
this.focusOnSearchBar(); this.focusOnSearchBar();
this.homePagePath = this.getHomePage(this); this.homePagePath = this.getHomePage(this);
}, },
methods: { 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 // focus on search bar when Ctrl+k is pressed
focusOnSearchBar() { focusOnSearchBar() {
hotkeys("ctrl+k", event => { hotkeys("ctrl+k", event => {

View file

@ -56,6 +56,11 @@ export default {
this.updateResults(); this.updateResults();
this.saveQueryToHistory(); this.saveQueryToHistory();
}, },
updated() {
if (this.$route.query.search_query !== undefined) {
document.title = this.$route.query.search_query + " - Piped";
}
},
activated() { activated() {
this.handleRedirect(); this.handleRedirect();
window.addEventListener("scroll", this.handleScroll); window.addEventListener("scroll", this.handleScroll);