sync - tui loads but no data in views

This commit is contained in:
2025-09-26 09:22:50 -07:00
parent 75a68a4e86
commit 8c7015545a
3 changed files with 38 additions and 20 deletions

10
main.py
View File

@@ -56,6 +56,16 @@ class CyclingCoachApp(App):
background: $accent; background: $accent;
color: $text; color: $text;
} }
TabbedContent {
height: 1fr;
width: 1fr;
}
TabPane {
height: 1fr;
width: 1fr;
}
""" """
TITLE = "AI Cycling Coach" TITLE = "AI Cycling Coach"

View File

@@ -20,7 +20,6 @@ class BaseView(Widget):
) )
return worker return worker
@work(thread=True)
async def _async_wrapper(self, coro: Coroutine, callback: Callable[[Any], None] = None) -> None: async def _async_wrapper(self, coro: Coroutine, callback: Callable[[Any], None] = None) -> None:
"""Wrapper for async operations with cancellation support.""" """Wrapper for async operations with cancellation support."""
try: try:

View File

@@ -13,6 +13,7 @@ from textual.widgets import (
from textual.widget import Widget from textual.widget import Widget
from textual.reactive import reactive from textual.reactive import reactive
from textual.message import Message from textual.message import Message
from textual import on
from typing import List, Dict, Optional from typing import List, Dict, Optional
from backend.app.database import AsyncSessionLocal from backend.app.database import AsyncSessionLocal
@@ -304,45 +305,53 @@ Elevation Gain: {workout.get('elevation_gain_m', 'N/A')} m
def on_mount(self) -> None: def on_mount(self) -> None:
"""Load workout data when mounted.""" """Load workout data when mounted."""
self.loading = True self.loading = True
# self.run_worker(self._load_workouts_and_handle_result_sync, thread=True)
# def _load_workouts_and_handle_result_sync(self) -> None: async def load_workouts_data(self) -> None:
# """Synchronous wrapper to load workouts data and handle the result.""" """Load workout data and handle the result."""
# try: self.loading = True
# # Run the async part using asyncio.run self.refresh()
# workouts, sync_status = asyncio.run(self._load_workouts_data()) try:
# self.workouts = workouts workouts, sync_status = await self._load_workouts_data()
# self.sync_status = sync_status self.on_workouts_loaded((workouts, sync_status))
# self.loading = False except Exception as e:
# self.call_after_refresh(lambda: self.refresh(layout=True)) self.log(f"Error loading workouts data: {e}", severity="error")
# except Exception as e: self.loading = False
# self.log(f"Error loading workouts data: {e}", severity="error") self.refresh()
# self.loading = False
# self.call_after_refresh(lambda: self.refresh()) @on(TabbedContent.TabActivated)
async def on_tab_activated(self, event: TabbedContent.TabActivated) -> None:
"""Handle tab activation to load data for the active tab."""
if event.pane.id == "workouts-tab":
await self.load_workouts_data()
async def _load_workouts_data(self) -> tuple[list, dict]: async def _load_workouts_data(self) -> tuple[list, dict]:
"""Load workouts and sync status (async worker).""" """Load workouts and sync status (async worker)."""
self.log("Attempting to load workouts data...")
try: try:
async with AsyncSessionLocal() as db: async with AsyncSessionLocal() as db:
workout_service = WorkoutService(db) workout_service = WorkoutService(db)
return ( workouts = await workout_service.get_workouts(limit=50)
await workout_service.get_workouts(limit=50), sync_status = await workout_service.get_sync_status()
await workout_service.get_sync_status() self.log(f"Workouts data loaded: {len(workouts)} workouts, sync status: {sync_status}")
) return workouts, sync_status
except Exception as e: except Exception as e:
self.log(f"Error loading workouts: {str(e)}", severity="error") self.log(f"Error loading workouts: {str(e)}", severity="error")
raise raise
def on_workouts_loaded(self, result: tuple[list, dict]) -> None: def on_workouts_loaded(self, result: tuple[list, dict]) -> None:
"""Handle loaded workout data.""" """Handle loaded workout data."""
print("Entering on_workouts_loaded")
try: try:
workouts, sync_status = result workouts, sync_status = result
print(f"on_workouts_loaded received: {len(workouts)} workouts, sync status: {sync_status}")
self.workouts = workouts self.workouts = workouts
self.sync_status = sync_status self.sync_status = sync_status
self.loading = False self.loading = False
self.refresh(layout=True) self.refresh(layout=True)
self.populate_workouts_table()
self.update_sync_status()
except Exception as e: except Exception as e:
self.log(f"Error loading workouts data: {e}", severity="error") print(f"Error in on_workouts_loaded: {e}")
self.loading = False self.loading = False
self.refresh() self.refresh()