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");
},
},
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 => {

View File

@ -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);