Skip to content

Commit

Permalink
Building out notification selection support
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo385 committed Dec 23, 2024
1 parent 16d3831 commit aac4f7f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
22 changes: 21 additions & 1 deletion lazy_github/lib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

from textual.message import Message

from lazy_github.models.github import Branch, FullPullRequest, Issue, IssueComment, PartialPullRequest, Repository
from lazy_github.models.github import (
Branch,
FullPullRequest,
Issue,
IssueComment,
Notification,
PartialPullRequest,
Repository,
)


class RepoSelected(Message):
Expand Down Expand Up @@ -89,3 +97,15 @@ class BranchesLoaded(Message):
def __init__(self, branches: list[Branch]) -> None:
super().__init__()
self.branches = branches


class NotificationMarkedAsRead(Message):
def __init__(self, notification: Notification) -> None:
super().__init__()
self.notification = notification


class NotificationSelected(Message):
def __init__(self, notification: Notification) -> None:
super().__init__()
self.notification = notification
26 changes: 17 additions & 9 deletions lazy_github/ui/screens/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
from textual.app import ComposeResult
from textual.containers import Container
from textual.coordinate import Coordinate
from textual.message import Message
from textual.screen import ModalScreen
from textual.widgets import Markdown, TabbedContent, TabPane
from textual.widgets import DataTable, Markdown, TabbedContent, TabPane

from lazy_github.lib.messages import NotificationMarkedAsRead, NotificationSelected
from lazy_github.lib.bindings import LazyGithubBindings
from lazy_github.lib.constants import BULLET_POINT, CHECKMARK
from lazy_github.lib.github.notifications import fetch_notifications, mark_notification_as_read
from lazy_github.models.github import Notification
from lazy_github.ui.widgets.common import LazyGithubFooter, SearchableDataTable


class NotificationMarkedAsRead(Message):
def __init__(self, notification: Notification) -> None:
super().__init__()
self.notification = notification


class _NotificationsTableTabPane(TabPane):
def __init__(self, prefix: str, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -46,6 +40,16 @@ def add_notification(self, notification: Notification) -> None:
key=str(notification.id),
)

def get_selected_notification(self) -> Notification:
current_row = self.searchable_table.table.cursor_row
id = self.searchable_table.table.get_cell_at(Coordinate(current_row, self.id_column))
return self.notifications[int(id)]

@on(DataTable.RowSelected)
def notification_selected(self) -> None:
notification = self.get_selected_notification()
self.post_message(NotificationSelected(notification))

def on_mount(self) -> None:
self.searchable_table.loading = True
self.searchable_table.table.cursor_type = "row"
Expand Down Expand Up @@ -137,7 +141,7 @@ def on_mount(self) -> None:
self.load_notifications()


class NotificationsModal(ModalScreen[None]):
class NotificationsModal(ModalScreen[Notification | None]):
DEFAULT_CSS = """
NotificationsModal {
height: 80%;
Expand All @@ -160,5 +164,9 @@ def compose(self) -> ComposeResult:
yield NotificationsContainer(id="notifications")
yield LazyGithubFooter()

@on(NotificationSelected)
async def handle_notification_selected(self, message: NotificationSelected) -> None:
self.dismiss(message.notification)

async def action_close(self) -> None:
self.dismiss()
5 changes: 4 additions & 1 deletion lazy_github/ui/screens/primary.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,12 @@ def compose(self):

@work
async def action_view_notifications(self) -> None:
await self.app.push_screen_wait(NotificationsModal())
notification = await self.app.push_screen_wait(NotificationsModal())
self.refresh_notification_count()

if notification:
lg.info(f"Selected notification: {notification}")

async def on_mount(self) -> None:
if LazyGithubContext.config.notifications.enabled:
self.refresh_notification_count()
Expand Down

0 comments on commit aac4f7f

Please sign in to comment.