add backend searching
This commit is contained in:
parent
8501590211
commit
eb071bcfc2
@ -51,9 +51,6 @@ async def home() -> str:
|
||||
|
||||
@app.get("/plugin/store")
|
||||
async def plugin_store() -> str:
|
||||
page = request.args.get("page", default=1, type=int)
|
||||
per_page = 6
|
||||
|
||||
installed_plugins = tutorclient.Client.installed_plugins()
|
||||
plugins: list[dict[str, str]] = [
|
||||
{
|
||||
@ -67,6 +64,12 @@ async def plugin_store() -> str:
|
||||
for p in tutorclient.Client.plugins_in_store()
|
||||
]
|
||||
|
||||
search_query = request.args.get("q", default="", type=str).strip().lower()
|
||||
if search_query:
|
||||
plugins = [plugin for plugin in plugins if search_query in plugin["name"].lower()]
|
||||
|
||||
page = request.args.get("page", default=1, type=int)
|
||||
per_page = 6
|
||||
total_pages = (len(plugins) + per_page - 1) // per_page
|
||||
if page < 1:
|
||||
page = 1
|
||||
@ -109,6 +112,11 @@ async def installed_plugins() -> str:
|
||||
}
|
||||
for plugin_name in installed_plugins
|
||||
]
|
||||
|
||||
search_query = request.args.get("q", default="", type=str).strip().lower()
|
||||
if search_query:
|
||||
plugins = [plugin for plugin in plugins if search_query in plugin["name"].lower()]
|
||||
|
||||
return await render_template(
|
||||
"installed_plugins.html",
|
||||
plugins=plugins,
|
||||
|
||||
@ -1,17 +1,3 @@
|
||||
document.getElementById("search-input").addEventListener("input", function () {
|
||||
let filter = this.value.toLowerCase();
|
||||
let plugins = document.querySelectorAll(".installed-plugin");
|
||||
|
||||
plugins.forEach((plugin) => {
|
||||
let name = plugin.querySelector(".name a").textContent.toLowerCase();
|
||||
if (name.includes(filter)) {
|
||||
plugin.style.display = "";
|
||||
} else {
|
||||
plugin.style.display = "none";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let open = document.querySelectorAll(".open-modal-button");
|
||||
const modal_container = document.getElementById("modal_container");
|
||||
let close = document.querySelectorAll(".close-modal-button");
|
||||
|
||||
@ -103,7 +103,6 @@ body {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
.header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@ -192,7 +191,7 @@ body {
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
div {
|
||||
.details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
@ -223,9 +222,6 @@ body {
|
||||
}
|
||||
}
|
||||
}
|
||||
.details {
|
||||
width: 30em;
|
||||
}
|
||||
}
|
||||
}
|
||||
.store-plugins {
|
||||
|
||||
@ -15,3 +15,19 @@
|
||||
<input id="search-input" type="text" class="form-control search-input" placeholder="Search...">
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
document.getElementById("search-input").addEventListener("keypress", function(event) {
|
||||
if (event.key === "Enter") {
|
||||
const searchInput = this.value.trim();
|
||||
const url = new URL(window.location.href);
|
||||
|
||||
url.searchParams.set("q", searchInput);
|
||||
|
||||
url.searchParams.set("page", 1);
|
||||
window.location.href = url.toString();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user