35 lines
916 B
Python
35 lines
916 B
Python
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 |