sort and order search results

This commit is contained in:
2026-02-05 18:56:34 +11:00
parent 73ed6a3388
commit bf62188876

View File

@@ -64,6 +64,11 @@ class SearchScreen(Screen):
} }
""" """
def __init__(self):
super().__init__()
self.selects_changed = [] # just used to prevent some issues
def action_view_repo(self, author: str, repo_name: str): def action_view_repo(self, author: str, repo_name: str):
self.app.switch_screen(RepoViewScreen(author, repo_name)) self.app.switch_screen(RepoViewScreen(author, repo_name))
@@ -75,12 +80,19 @@ class SearchScreen(Screen):
loading.display = True loading.display = True
# get params we need to send
sort = self.query_one("#sort-select").value
order = self.query_one("#order-select").value
users_or_repos = self.query_one("#search-select").value
# send off a request # send off a request
response = requests.get( response = requests.get(
url=self.app.GITEA_HOST + "api/v1/repos/search", url=self.app.GITEA_HOST + "api/v1/repos/search",
params={ params={
"q": query_input.value, "q": query_input.value,
"limit": 20 "limit": 20,
"sort": sort,
"order": order
} }
) )
@@ -105,6 +117,13 @@ class SearchScreen(Screen):
def on_input_submitted(self, event: Input.Submitted): def on_input_submitted(self, event: Input.Submitted):
if event.input.id == "query": if event.input.id == "query":
self.action_search_query() self.action_search_query()
def on_select_changed(self, event: Select.Changed):
if not event.select.id in self.selects_changed:
self.selects_changed.append(event.select.id)
return
self.action_search_query()
def on_mount(self): def on_mount(self):
self.action_search_query() self.action_search_query()
@@ -115,17 +134,17 @@ class SearchScreen(Screen):
with HorizontalGroup(id="search-box"): with HorizontalGroup(id="search-box"):
yield Input(placeholder="Search repos...", id="query") yield Input(placeholder="Search repos...", id="query")
yield Select.from_values([ yield Select([
"Alphabetical", ("Alphabetical", "alpha"),
"Creation date", ("Creation date", "created"),
"Last updated", ("Last updated", "updated"),
"Size", ("Size", "size"),
"ID" ("ID", "id")
], id="sort-select", allow_blank=False, value="Last updated") ], id="sort-select", allow_blank=False, value="updated")
yield Select.from_values([ yield Select([
"Ascending", ("Ascending", "asc"),
"Descending" ("Descending", "desc")
], id="order-select", allow_blank=False, value="Ascending") ], id="order-select", allow_blank=False, value="desc")
yield Select.from_values([ yield Select.from_values([
"Repositories", "Repositories",
"Users", "Users",