refactor: restructure api module and implement articles pagination with dynamic routing

This commit is contained in:
Flook
2026-05-06 05:58:38 +07:00
parent b4725b184b
commit 2d9cbb3376
12 changed files with 195 additions and 12 deletions
+35
View File
@@ -0,0 +1,35 @@
import asyncio
import flet as ft
from app.api.articles import get_article
from app.state import state
def article_detail_page(page: ft.Page, article_id: int):
content = ft.Column(expand=True)
async def load_article():
content.controls.clear()
content.controls.append(ft.ProgressRing())
page.update()
article = await asyncio.to_thread(
get_article,
article_id,
state.access_token
)
content.controls.clear()
content.controls.extend([
ft.Text(article['title'], size=16, weight=ft.FontWeight.BOLD),
ft.Text(article['body']),
ft.FilledButton(
'ย้อนกลับ',
on_click=lambda e: asyncio.create_task(page.push_route('/articles'))
)
])
page.update()
asyncio.create_task(load_article())
return content