Added Layout and UserProfile

This commit is contained in:
2025-11-10 21:19:38 +01:00
parent a547b2b882
commit d302261d07
12 changed files with 249 additions and 87 deletions

View File

@@ -0,0 +1,46 @@
from fasthtml.components import *
from myfasthtml.controls.helpers import Ids, mk
from myfasthtml.core.instances import SingleInstance
from myfasthtml.core.utils import get_user_info
from myfasthtml.icons.material import dark_mode_filled, person_outline_sharp
from myfasthtml.icons.material_p1 import light_mode_filled, alternate_email_filled
class UserProfile(SingleInstance):
def __init__(self, session):
super().__init__(session, Ids.UserProfile)
def render(self):
user_info = get_user_info(self._session)
return Div(
Div(user_info['username'],
tabindex="0",
role="button",
cls="btn btn-xs"),
Div(
Div(mk.icon(person_outline_sharp, cls="mr-1"), user_info['username'], cls="flex m-1"),
Div(mk.icon(alternate_email_filled, cls="mr-1"), user_info['email'], cls="flex m-1"),
Div(mk.icon(dark_mode_filled, cls="mr-1"), self.mk_dark_mode(), cls="flex m-1"),
Div(A("Logout", cls="btn btn-xs mr-1", href="/logout"), cls="flex justify-center items-center"),
tabindex="-1",
cls="dropdown-content menu w-52 rounded-box bg-base-300 shadow-xl"
),
cls="dropdown dropdown-end"
)
@staticmethod
def mk_dark_mode():
return Label(
Input(type="checkbox",
name='theme',
aria_label='Dark',
value='dark',
cls='theme-controller'),
light_mode_filled,
dark_mode_filled,
cls="toggle text-base-content"
)
def __ft__(self):
return self.render()