inline links in repo results
This commit is contained in:
@@ -20,30 +20,27 @@ class SearchResult(HorizontalGroup):
|
||||
|
||||
Static {
|
||||
width: auto;
|
||||
link-style: bold;
|
||||
link-color: $primary;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
author: str,
|
||||
name: str,
|
||||
description: str,
|
||||
is_fork: bool,
|
||||
updated_at: datetime
|
||||
repo_data: dict
|
||||
):
|
||||
super().__init__()
|
||||
self.author = author
|
||||
self.repo_name = name
|
||||
self.description = description
|
||||
self.is_fork = is_fork
|
||||
self.updated_at = updated_at.replace(tzinfo=None)
|
||||
self.repo_data = repo_data
|
||||
self.author = repo_data["owner"]
|
||||
self.repo_name = repo_data["name"]
|
||||
self.description = repo_data["description"]
|
||||
self.is_fork = repo_data["fork"]
|
||||
self.updated_at = datetime.fromisoformat(repo_data["updated_at"]).replace(tzinfo=None)
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
updated_string = time_delta(datetime.now() - self.updated_at)
|
||||
yield Static(f"[b]{self.author}[/] / [b]{self.repo_name}[/]{' [d]\[[blue]fork[/]]' if self.is_fork else ''}\n{self.description}\n[d]Updated {updated_string} ago")
|
||||
yield Static(f"[@click='view_user({self.author["id"]})']{self.author["login"]}[/] / [@click=view_repo('')]{self.repo_name}[/]{' [d]\[[cyan]fork[/]]' if self.is_fork else ''}\n{self.description}\n[d]Updated {updated_string} ago")
|
||||
|
||||
class SearchScreen(Screen):
|
||||
DEFAULT_CSS = """
|
||||
@@ -90,13 +87,7 @@ class SearchScreen(Screen):
|
||||
to_mount = []
|
||||
print(response.json())
|
||||
for result in response.json()["data"]:
|
||||
to_mount.append(SearchResult(
|
||||
result["owner"]["login"],
|
||||
result["name"],
|
||||
result["description"],
|
||||
result["fork"],
|
||||
datetime.fromisoformat(result["updated_at"])
|
||||
))
|
||||
to_mount.append(SearchResult(result))
|
||||
results.mount_all(to_mount)
|
||||
|
||||
# self explanitory
|
||||
|
||||
Reference in New Issue
Block a user