refactor: restructure api module and implement articles pagination with dynamic routing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import flet as ft
|
||||
|
||||
from app.layout import main_layout
|
||||
from app.pages.article_detail import article_detail_page
|
||||
from app.pages.login import login_page
|
||||
from app.pages.articles import articles_page
|
||||
from app.pages.courses import courses_page
|
||||
@@ -27,6 +28,7 @@ async def main(page: ft.Page):
|
||||
# ROUTES MAP
|
||||
routes = {
|
||||
"/articles": articles_page,
|
||||
"/articles/{id}": article_detail_page,
|
||||
"/courses": courses_page,
|
||||
"/my_courses": my_courses_page,
|
||||
"/progress": progress_page,
|
||||
@@ -73,8 +75,16 @@ async def main(page: ft.Page):
|
||||
)
|
||||
|
||||
# เปลี่ยน content อย่างเดียว
|
||||
if page.route in routes:
|
||||
main_container.content = routes[page.route]()
|
||||
# จัดการ Dynamic Route ก่อน เช่น ARTICLE DETAIL
|
||||
if page.route.startswith("/articles/"):
|
||||
try:
|
||||
article_id = int(page.route.split('/')[-1])
|
||||
main_container.content = article_detail_page(page, article_id)
|
||||
except ValueError:
|
||||
main_container.content = ft.Text('Invalid article ID')
|
||||
# จัดการ Static Routes ที่เหลือ
|
||||
elif page.route in routes:
|
||||
main_container.content = routes[page.route](page)
|
||||
else:
|
||||
main_container.content = ft.Text("404 NOT FOUND")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user