fixes to email display
This commit is contained in:
@@ -3,6 +3,7 @@ import sys
|
||||
import json
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import msal
|
||||
import aiohttp
|
||||
@@ -34,6 +35,20 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "maildir_gtd"))
|
||||
from maildir_gtd.screens.DocumentViewer import DocumentViewerScreen
|
||||
|
||||
|
||||
class FolderHistoryEntry:
|
||||
"""Represents an entry in the folder navigation history."""
|
||||
|
||||
def __init__(self, folder_id: str, folder_name: str, parent_id: str = None):
|
||||
self.folder_id = folder_id
|
||||
self.folder_name = folder_name
|
||||
self.parent_id = parent_id
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, FolderHistoryEntry):
|
||||
return False
|
||||
return self.folder_id == other.folder_id
|
||||
|
||||
|
||||
class OneDriveTUI(App):
|
||||
"""A Textual app for OneDrive integration with MSAL authentication."""
|
||||
|
||||
@@ -44,6 +59,8 @@ class OneDriveTUI(App):
|
||||
selected_drive_id = reactive("")
|
||||
drive_name = reactive("")
|
||||
current_view = reactive("Following") # Track current view: "Following" or "Root"
|
||||
current_folder_id = reactive("root") # Track current folder ID
|
||||
current_folder_name = reactive("Root") # Track current folder name
|
||||
|
||||
# App bindings
|
||||
BINDINGS = [
|
||||
@@ -54,6 +71,8 @@ class OneDriveTUI(App):
|
||||
Binding("enter", "open_url", "Open URL"),
|
||||
Binding("v", "view_document", "View Document"),
|
||||
Binding("tab", "next_view", "Switch View"),
|
||||
Binding("backspace", "navigate_back", "Back"),
|
||||
Binding("b", "navigate_back", "Back"),
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
@@ -61,8 +80,8 @@ class OneDriveTUI(App):
|
||||
self.access_token = None
|
||||
self.drives = []
|
||||
self.followed_items = []
|
||||
|
||||
self.current_items = {} # Store currently displayed items
|
||||
self.current_items = {} # Store currently displayed items
|
||||
self.folder_history = [] # History stack for folder navigation
|
||||
self.msal_app = None
|
||||
self.cache = msal.SerializableTokenCache()
|
||||
# Read Azure app credentials from environment variables
|
||||
@@ -287,18 +306,22 @@ class OneDriveTUI(App):
|
||||
self.action_view_document()
|
||||
|
||||
@work
|
||||
async def load_root_items(self, folder_id: str = "", drive_id: str = ""):
|
||||
async def load_root_items(self, folder_id: str = "", drive_id: str = "", track_history: bool = True):
|
||||
"""Load root items from the selected drive."""
|
||||
if not self.access_token or not self.selected_drive_id:
|
||||
return
|
||||
|
||||
self.query_one("#status_label").update("Loading root items...")
|
||||
self.query_one("#status_label").update("Loading drive folder items...")
|
||||
headers = {"Authorization": f"Bearer {self.access_token}"}
|
||||
url = f"https://graph.microsoft.com/v1.0/me/drive/root/children"
|
||||
|
||||
if folder_id and drive_id:
|
||||
url = f"https://graph.microsoft.com/v1.0/drives/{drive_id}/items/{folder_id}/children"
|
||||
if track_history:
|
||||
self.folder_history.append(FolderHistoryEntry(folder_id, self.current_folder_name, drive_id))
|
||||
self.selected_drive_id = drive_id
|
||||
self.current_folder_id = folder_id
|
||||
self.current_folder_name = self.current_items[folder_id].get("name", "Unknown")
|
||||
try:
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
@@ -311,7 +334,7 @@ class OneDriveTUI(App):
|
||||
|
||||
|
||||
# Update the table with the root items
|
||||
self.update_items_table(items_data.get("value", []), is_root_view=True)
|
||||
self.update_items_table(items_data.get("value", []))
|
||||
except Exception as e:
|
||||
self.notify(f"Error loading root items: {str(e)}", severity="error")
|
||||
|
||||
@@ -456,6 +479,16 @@ class OneDriveTUI(App):
|
||||
"""Quit the application."""
|
||||
self.exit()
|
||||
|
||||
async def action_navigate_back(self) -> None:
|
||||
"""Navigate back to the previous folder."""
|
||||
if self.folder_history:
|
||||
previous_entry = self.folder_history.pop()
|
||||
self.current_folder_id = previous_entry.folder_id
|
||||
self.current_folder_name = previous_entry.folder_name
|
||||
self.load_root_items(folder_id=previous_entry.folder_id, drive_id=previous_entry.parent_id, track_history=False)
|
||||
else:
|
||||
self.notify("No previous folder to navigate back to")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = OneDriveTUI()
|
||||
|
||||
Reference in New Issue
Block a user