Files
luk/maildir_gtd/actions/task.py
2025-05-14 15:11:24 -06:00

50 lines
1.6 KiB
Python

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):
"""Show the create task screen."""
current_message_id = app.current_message_id
if not current_message_id:
app.show_status("No message selected to create task from.", "error")
return
# 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)