import flet as ft import designer as ds import api_client class TakeTestPage(ft.Column): def __init__(self, page: ft.Page): self._page = page self._loading = ft.ProgressRing(width=ds.s(40), height=ds.s(40), color=ds.colors.secondary_light) super().__init__( alignment=ft.MainAxisAlignment.CENTER, horizontal_alignment=ft.CrossAxisAlignment.CENTER, controls=[self._loading], ) async def load(self): await self._load_polls() async def _load_polls(self): polls = await api_client.get_polls() if polls: self._render_polls(polls) else: self.controls = [ds.CastomText(text="Тестов пока нет", size=16)] self.update() def _render_polls(self, polls: list): self.controls = [ ft.Container( border_radius=ds.s(12), padding=ds.s(16), bgcolor=ds.colors.surface, content=ft.Column( spacing=ds.s(6), controls=[ ds.CastomText( text=poll.get("title", "—"), size=16, weight=ft.FontWeight.BOLD, ), ds.CastomText( text=poll.get("description") or "", size=13, ), ], ), on_click=lambda e, pid=poll["id"]: self._page.go( f"/poll/{self._page.session.store.get('url_key') or ''}/{pid}" ), ink=True, ) for poll in polls ]