basically refactored the email viewer

This commit is contained in:
Tim Bendt
2025-05-14 15:11:24 -06:00
parent 5c9ad69309
commit fc57e201a2
20 changed files with 1348 additions and 575 deletions

View File

@@ -1,43 +1,105 @@
from textual import on
from textual.app import ComposeResult
import logging
from textual.screen import ModalScreen
from textual.widgets import Input, Label, Button
from textual.containers import Horizontal, Vertical
from textual.widgets import Input, Label, Button, ListView, ListItem
from textual.containers import Vertical, Horizontal, Container
from textual import on, work
from apis.taskwarrior import client as taskwarrior_client
class CreateTaskScreen(ModalScreen):
"""Screen for creating a new task."""
class CreateTaskScreen(ModalScreen[str]):
def compose(self) -> ComposeResult:
yield Vertical(
Horizontal(
Label("$>", id="task_prompt"),
Label("task add ", id="task_prompt_label"),
Input(placeholder="arguments", id="task_input"),
),
Horizontal(
Button("Cancel", id="cancel"),
Button("Submit", id="submit", variant="primary"),
def __init__(self, subject="", from_addr="", **kwargs):
super().__init__(**kwargs)
self.subject = subject
self.from_addr = from_addr
self.selected_project = None
def compose(self):
yield Container(
Vertical(
Label("Create Task", id="create_task_title"),
Horizontal(
Label("Subject:"),
Input(placeholder="Task subject", value=self.subject, id="subject_input"),
),
Horizontal(
Label("Project:"),
Input(placeholder="Project name", id="project_input"),
),
Horizontal(
Label("Tags:"),
Input(placeholder="Comma-separated tags", id="tags_input"),
),
Horizontal(
Label("Due:"),
Input(placeholder="Due date (e.g., today, tomorrow, fri)", id="due_input"),
),
Horizontal(
Label("Priority:"),
Input(placeholder="Priority (H, M, L)", id="priority_input"),
),
Horizontal(
Button("Create", id="create_btn", variant="primary"),
Button("Cancel", id="cancel_btn", variant="error"),
),
id="create_task_form",
),
id="create_task_container",
classes="modal_screen",
)
@on(Input.Submitted)
def handle_task_args(self) -> None:
input_widget = self.query_one("#task_input", Input)
self.visible = False
self.disabled = True
self.loading = True
task_args = input_widget.value
self.dismiss(task_args)
def on_mount(self):
self.styles.align = ("center", "middle")
def on_key(self, event) -> None:
if event.key == "escape" or event.key == "ctrl+c":
self.dismiss()
@on(Button.Pressed, "#create_btn")
def on_create_pressed(self):
"""Create the task when the Create button is pressed."""
# Get input values
subject = self.query_one("#subject_input").value
project = self.query_one("#project_input").value
tags_input = self.query_one("#tags_input").value
due = self.query_one("#due_input").value
priority = self.query_one("#priority_input").value
def button_on_click(self, event):
if event.button.id == "cancel":
# Process tags (split by commas and trim whitespace)
tags = [tag.strip() for tag in tags_input.split(",")] if tags_input else []
# Add a tag for the sender, if provided
if self.from_addr and "@" in self.from_addr:
domain = self.from_addr.split("@")[1].split(".")[0]
if domain and domain not in ["gmail", "yahoo", "hotmail", "outlook"]:
tags.append(domain)
# Create the task
self.create_task_worker(subject, tags, project, due, priority)
@on(Button.Pressed, "#cancel_btn")
def on_cancel_pressed(self):
"""Dismiss the screen when Cancel is pressed."""
self.dismiss()
@work(exclusive=True)
async def create_task_worker(self, subject, tags=None, project=None, due=None, priority=None):
"""Worker to create a task using the Taskwarrior API client."""
if not subject:
self.app.show_status("Task subject cannot be empty.", "error")
return
# Validate priority
if priority and priority not in ["H", "M", "L"]:
self.app.show_status("Priority must be H, M, or L.", "warning")
priority = None
# Create the task
success, result = await taskwarrior_client.create_task(
task_description=subject,
tags=tags or [],
project=project,
due=due,
priority=priority
)
if success:
self.app.show_status(f"Task created: {subject}", "success")
self.dismiss()
elif event.button.id == "submit":
input_widget = self.query_one("#task_input", Input)
task_args = input_widget.value
self.dismiss(task_args)
else:
self.app.show_status(f"Failed to create task: {result}", "error")