switched from tabs to spaces lmao
This commit is contained in:
11
screens/repo_view_screen.py
Normal file
11
screens/repo_view_screen.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from textual.screen import Screen
|
||||||
|
from textual.app import ComposeResult
|
||||||
|
from widgets import Navbar
|
||||||
|
|
||||||
|
|
||||||
|
class RepoViewScreen(Screen):
|
||||||
|
def __init__(self, repo_id: int):
|
||||||
|
super().__init__(self)
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Navbar()
|
||||||
@@ -11,104 +11,104 @@ import requests
|
|||||||
|
|
||||||
|
|
||||||
class SearchResult(HorizontalGroup):
|
class SearchResult(HorizontalGroup):
|
||||||
DEFAULT_CSS = """
|
DEFAULT_CSS = """
|
||||||
SearchResult {
|
SearchResult {
|
||||||
padding: 0 1;
|
padding: 0 1;
|
||||||
margin: 0 1;
|
margin: 0 1;
|
||||||
margin-top: 1;
|
margin-top: 1;
|
||||||
border: tall $surface;
|
border: tall $surface;
|
||||||
|
|
||||||
Static {
|
Static {
|
||||||
width: auto;
|
width: auto;
|
||||||
link-style: bold;
|
link-style: bold;
|
||||||
link-color: $primary;
|
link-color: $primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
repo_data: dict
|
repo_data: dict
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.repo_data = repo_data
|
self.repo_data = repo_data
|
||||||
self.author = repo_data["owner"]
|
self.author = repo_data["owner"]
|
||||||
self.repo_name = repo_data["name"]
|
self.repo_name = repo_data["name"]
|
||||||
self.description = repo_data["description"]
|
self.description = repo_data["description"]
|
||||||
self.is_fork = repo_data["fork"]
|
self.is_fork = repo_data["fork"]
|
||||||
self.updated_at = datetime.fromisoformat(repo_data["updated_at"]).replace(tzinfo=None)
|
self.updated_at = datetime.fromisoformat(repo_data["updated_at"]).replace(tzinfo=None)
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
updated_string = time_delta(datetime.now() - self.updated_at)
|
updated_string = time_delta(datetime.now() - self.updated_at)
|
||||||
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")
|
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):
|
class SearchScreen(Screen):
|
||||||
DEFAULT_CSS = """
|
DEFAULT_CSS = """
|
||||||
#search-box {
|
#search-box {
|
||||||
padding: 1;
|
padding: 1;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
border-bottom: hkey $surface;
|
border-bottom: hkey $surface;
|
||||||
|
|
||||||
#query {
|
#query {
|
||||||
width: 1fr;
|
width: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search-select {
|
#search-select {
|
||||||
width: 25;
|
width: 25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def action_search_query(self):
|
def action_search_query(self):
|
||||||
query_input = self.query_one("#query")
|
query_input = self.query_one("#query")
|
||||||
loading = self.query_one(LoadingIndicator)
|
loading = self.query_one(LoadingIndicator)
|
||||||
results = self.query_one(ScrollableContainer)
|
results = self.query_one(ScrollableContainer)
|
||||||
|
|
||||||
loading.display = True
|
loading.display = True
|
||||||
|
|
||||||
# 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
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
loading.display = False
|
loading.display = False
|
||||||
|
|
||||||
# error handling
|
# error handling
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
self.notify(response.text, title="Error while getting search results:", severity="error")
|
self.notify(response.text, title="Error while getting search results:", severity="error")
|
||||||
return
|
return
|
||||||
|
|
||||||
# display results
|
# display results
|
||||||
results.remove_children(SearchResult)
|
results.remove_children(SearchResult)
|
||||||
to_mount = []
|
to_mount = []
|
||||||
print(response.json())
|
print(response.json())
|
||||||
for result in response.json()["data"]:
|
for result in response.json()["data"]:
|
||||||
to_mount.append(SearchResult(result))
|
to_mount.append(SearchResult(result))
|
||||||
results.mount_all(to_mount)
|
results.mount_all(to_mount)
|
||||||
|
|
||||||
# self explanitory
|
# self explanitory
|
||||||
query_input.clear()
|
query_input.clear()
|
||||||
|
|
||||||
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_mount(self):
|
def on_mount(self):
|
||||||
self.action_search_query()
|
self.action_search_query()
|
||||||
#self.query_one(LoadingIndicator).display = False
|
#self.query_one(LoadingIndicator).display = False
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Navbar()
|
yield Navbar()
|
||||||
|
|
||||||
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.from_values([
|
||||||
"Repositories",
|
"Repositories",
|
||||||
], id="search-select", allow_blank=False)
|
], id="search-select", allow_blank=False)
|
||||||
|
|
||||||
with ScrollableContainer(id="results"):
|
with ScrollableContainer(id="results"):
|
||||||
yield LoadingIndicator()
|
yield LoadingIndicator()
|
||||||
@@ -10,38 +10,38 @@ from random import choice
|
|||||||
|
|
||||||
|
|
||||||
class WelcomeScreen(Screen):
|
class WelcomeScreen(Screen):
|
||||||
DEFAULT_CSS = """
|
DEFAULT_CSS = """
|
||||||
Center {
|
Center {
|
||||||
padding: 2;
|
padding: 2;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
Static {
|
Static {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectLabel {
|
EffectLabel {
|
||||||
text-style: bold;
|
text-style: bold;
|
||||||
min-width: 100%;
|
min-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#buttons {
|
|
||||||
margin-top: 1;
|
|
||||||
align: center middle;
|
|
||||||
Button {
|
|
||||||
margin: 0 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
#buttons {
|
||||||
yield Navbar()
|
margin-top: 1;
|
||||||
with Center():
|
align: center middle;
|
||||||
with open("banner.txt", "r") as f:
|
Button {
|
||||||
yield EffectLabel(text=f.read(), effect=choice(list(effects.keys())))
|
margin: 0 2;
|
||||||
|
}
|
||||||
yield Static("[d]Gitea, in your terminal.[/]")
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
with HorizontalGroup(id="buttons"):
|
def compose(self) -> ComposeResult:
|
||||||
yield Button("Explore", variant="primary", flat=True)
|
yield Navbar()
|
||||||
yield Button("another button lol", flat=True)
|
with Center():
|
||||||
|
with open("banner.txt", "r") as f:
|
||||||
|
yield EffectLabel(text=f.read(), effect=choice(list(effects.keys())))
|
||||||
|
|
||||||
|
yield Static("[d]Gitea, in your terminal.[/]")
|
||||||
|
|
||||||
|
with HorizontalGroup(id="buttons"):
|
||||||
|
yield Button("Explore", variant="primary", flat=True)
|
||||||
|
yield Button("another button lol", flat=True)
|
||||||
@@ -3,19 +3,19 @@ from textual.containers import HorizontalGroup
|
|||||||
|
|
||||||
|
|
||||||
class Navbar(HorizontalGroup):
|
class Navbar(HorizontalGroup):
|
||||||
DEFAULT_CSS = """
|
DEFAULT_CSS = """
|
||||||
Navbar {
|
Navbar {
|
||||||
background: $surface-darken-1;
|
background: $surface-darken-1;
|
||||||
border-bottom: hkey $surface;
|
border-bottom: hkey $surface;
|
||||||
height: 3;
|
height: 3;
|
||||||
padding: 1;
|
padding: 1;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
|
|
||||||
#hamburger-menu {
|
#hamburger-menu {
|
||||||
max-width: 1;
|
max-width: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
yield Button("≡", compact=True, id="hamburger-menu")
|
yield Button("≡", compact=True, id="hamburger-menu")
|
||||||
Reference in New Issue
Block a user