Added automatic removal of query parameter when search is closed

This commit is contained in:
squidfunk 2022-02-26 10:07:32 +01:00
parent 5acd0c3620
commit e3c26215de
8 changed files with 29 additions and 16 deletions

View File

@ -213,7 +213,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.8aa65030.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.cd6d3f86.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %} {% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script> <script src="{{ path | url }}"></script>
{% endfor %} {% endfor %}

View File

@ -16,5 +16,5 @@
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script src="{{ 'overrides/assets/javascripts/bundle.90528257.min.js' | url }}"></script> <script src="{{ 'overrides/assets/javascripts/bundle.068fb875.min.js' | url }}"></script>
{% endblock %} {% endblock %}

View File

@ -44,7 +44,8 @@ import { translation } from "~/_"
import { import {
getLocation, getLocation,
setToggle, setToggle,
watchElementFocus watchElementFocus,
watchToggle
} from "~/browser" } from "~/browser"
import { import {
SearchMessageType, SearchMessageType,
@ -101,6 +102,18 @@ export function watchSearchQuery(
map(() => searchParams.get("q") || "") map(() => searchParams.get("q") || "")
) )
/* Remove query parameter when search is closed */
watchToggle("search")
.pipe(
filter(active => !active),
take(1)
)
.subscribe(() => {
const url = new URL(location.href)
url.searchParams.delete("q")
history.replaceState({}, "", `${url}`)
})
/* Set query from parameter */ /* Set query from parameter */
param$.subscribe(value => { // TODO: not ideal - find a better way param$.subscribe(value => { // TODO: not ideal - find a better way
if (value) if (value)

View File

@ -84,7 +84,7 @@ export function mountIconSearchQuery(
) )
.subscribe(([, value]) => { .subscribe(([, value]) => {
const path = document.location.pathname const path = document.location.pathname
if (value.length) if (typeof ga === "function" && value.length)
ga("send", "pageview", `${path}?q=[icon]+${value}`) ga("send", "pageview", `${path}?q=[icon]+${value}`)
}) })