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,28 +1,49 @@
import asyncio
import logging
from textual import work
from textual.screen import ModalScreen
from apis.taskwarrior import client as taskwarrior_client
from maildir_gtd.screens.CreateTask import CreateTaskScreen
class TaskAction:
def __init__(self, app):
self.app = app
def action_create_task(app) -> None:
"""Show the input modal for creating a task."""
def action_create_task(app):
"""Show the create task screen."""
async def check_task(task_args: str) -> bool:
try:
result = await asyncio.create_subprocess_shell(
f"task add {task_args}",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await result.communicate()
if result.returncode == 0:
app.show_status(f"Task created: {stdout.decode()}")
else:
app.show_status(
f"Failed to create task: {stderr.decode()}", severity="error"
)
except Exception as e:
app.show_status(f"Error: {e}", severity="error")
return True
return False
current_message_id = app.current_message_id
if not current_message_id:
app.show_status("No message selected to create task from.", "error")
return
app.push_screen(CreateTaskScreen(), check_task)
# Prepare data for the create task screen
metadata = app.message_store.get_metadata(current_message_id)
subject = metadata.get("subject", "No subject") if metadata else "No subject"
from_addr = metadata["from"].get("addr", "Unknown") if metadata else "Unknown"
# Show the create task screen with the current message data
app.push_screen(CreateTaskScreen(subject=subject, from_addr=from_addr))
@work(exclusive=True)
async def create_task(subject, description=None, tags=None, project=None, due=None, priority=None):
"""
Create a task with the Taskwarrior API client.
"""
try:
success, result = await taskwarrior_client.create_task(
task_description=subject,
tags=tags or [],
project=project,
due=due,
priority=priority
)
if success:
return True, result
else:
logging.error(f"Failed to create task: {result}")
return False, result
except Exception as e:
logging.error(f"Exception creating task: {e}")
return False, str(e)