Refactor animated Text into component
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import logging
|
||||
from asyncio import sleep
|
||||
from typing import Optional
|
||||
|
||||
from email_validator import validate_email, EmailNotValidError
|
||||
from rio import Column, Component, event, Text, TextStyle, TextInput, TextInputChangeEvent, Button
|
||||
|
||||
from src.ez_lan_manager import ConfigurationService, UserService, MailingService
|
||||
from src.ez_lan_manager.components.AnimatedText import AnimatedText
|
||||
from src.ez_lan_manager.components.MainViewContentBox import MainViewContentBox
|
||||
from src.ez_lan_manager.pages import BasePage
|
||||
|
||||
@@ -14,8 +13,6 @@ MINIMUM_PASSWORD_LENGTH = 6
|
||||
logger = logging.getLogger(__name__.split(".")[-1])
|
||||
|
||||
class RegisterPage(Component):
|
||||
display_printing: list[bool] = [False]
|
||||
|
||||
def on_pw_change(self, _: TextInputChangeEvent) -> None:
|
||||
if not (self.pw_1.text == self.pw_2.text) or len(self.pw_1.text) < MINIMUM_PASSWORD_LENGTH:
|
||||
self.pw_1.is_valid = False
|
||||
@@ -37,22 +34,22 @@ class RegisterPage(Component):
|
||||
await self.submit_button.force_refresh()
|
||||
|
||||
if len(self.user_name_input.text) < 1:
|
||||
await self.display_save_result_animation(False, optional_text="Nutzername darf nicht leer sein!")
|
||||
await self.animated_text.display_text(False, "Nutzername darf nicht leer sein!")
|
||||
self.submit_button.is_loading = False
|
||||
return
|
||||
|
||||
if not (self.pw_1.text == self.pw_2.text):
|
||||
await self.display_save_result_animation(False, optional_text="Passwörter stimmen nicht überein!")
|
||||
await self.animated_text.display_text(False, "Passwörter stimmen nicht überein!")
|
||||
self.submit_button.is_loading = False
|
||||
return
|
||||
|
||||
if len(self.pw_1.text) < MINIMUM_PASSWORD_LENGTH:
|
||||
await self.display_save_result_animation(False, optional_text=f"Passwort muss mindestens {MINIMUM_PASSWORD_LENGTH} Zeichen lang sein!")
|
||||
await self.animated_text.display_text(False, f"Passwort muss mindestens {MINIMUM_PASSWORD_LENGTH} Zeichen lang sein!")
|
||||
self.submit_button.is_loading = False
|
||||
return
|
||||
|
||||
if not self.email_input.is_valid or len(self.email_input.text) < 3:
|
||||
await self.display_save_result_animation(False, optional_text="E-Mail Adresse ungültig!")
|
||||
await self.animated_text.display_text(False, "E-Mail Adresse ungültig!")
|
||||
self.submit_button.is_loading = False
|
||||
return
|
||||
|
||||
@@ -61,7 +58,7 @@ class RegisterPage(Component):
|
||||
lan_info = self.session[ConfigurationService].get_lan_info()
|
||||
|
||||
if user_service.get_user(self.email_input.text) is not None or user_service.get_user(self.user_name_input.text) is not None:
|
||||
await self.display_save_result_animation(False, optional_text="Benutzername oder E-Mail bereits regestriert!")
|
||||
await self.animated_text.display_text(False, "Benutzername oder E-Mail bereits regestriert!")
|
||||
self.submit_button.is_loading = False
|
||||
return
|
||||
|
||||
@@ -71,7 +68,7 @@ class RegisterPage(Component):
|
||||
raise RuntimeError("User could not be created")
|
||||
except Exception as e:
|
||||
logger.error(f"Unknown error during new user registration: {e}")
|
||||
await self.display_save_result_animation(False, optional_text="Es ist ein unbekannter Fehler aufgetreten :(")
|
||||
await self.animated_text.display_text(False, "Es ist ein unbekannter Fehler aufgetreten :(")
|
||||
self.submit_button.is_loading = False
|
||||
return
|
||||
|
||||
@@ -85,36 +82,7 @@ class RegisterPage(Component):
|
||||
)
|
||||
|
||||
self.submit_button.is_loading = False
|
||||
await self.display_save_result_animation(True, optional_text="Erfolgreich registriert!")
|
||||
|
||||
async def display_save_result_animation(self, success: bool, optional_text: Optional[str] = None) -> None:
|
||||
if self.display_printing[0]:
|
||||
return
|
||||
else:
|
||||
self.display_printing[0] = True
|
||||
|
||||
self.info_text.text = ""
|
||||
if success:
|
||||
self.info_text.style = TextStyle(
|
||||
fill=self.session.theme.success_color,
|
||||
font_size=1
|
||||
)
|
||||
t = "Gespeichert!" if not optional_text else optional_text
|
||||
for c in t:
|
||||
self.info_text.text = self.info_text.text + c
|
||||
await self.info_text.force_refresh()
|
||||
await sleep(0.04)
|
||||
else:
|
||||
self.info_text.style = TextStyle(
|
||||
fill=self.session.theme.danger_color,
|
||||
font_size=1
|
||||
)
|
||||
t = "Fehler!" if not optional_text else optional_text
|
||||
for c in t:
|
||||
self.info_text.text = self.info_text.text + c
|
||||
await self.info_text.force_refresh()
|
||||
await sleep(0.04)
|
||||
self.display_printing[0] = False
|
||||
await self.animated_text.display_text(True, "Erfolgreich registriert!")
|
||||
|
||||
@event.on_populate
|
||||
async def on_populate(self) -> None:
|
||||
@@ -174,17 +142,11 @@ class RegisterPage(Component):
|
||||
color=self.session.theme.secondary_color,
|
||||
on_press=self.on_submit_button_pressed
|
||||
)
|
||||
self.info_text = Text(
|
||||
text="",
|
||||
style=TextStyle(
|
||||
fill=self.session.theme.background_color,
|
||||
font_size=1
|
||||
),
|
||||
self.animated_text = AnimatedText(
|
||||
margin_top=2,
|
||||
margin_left=1,
|
||||
margin_right=1,
|
||||
margin_bottom=2,
|
||||
wrap=True
|
||||
margin_bottom=2
|
||||
)
|
||||
return BasePage(
|
||||
content=Column(
|
||||
@@ -205,7 +167,7 @@ class RegisterPage(Component):
|
||||
self.pw_1,
|
||||
self.pw_2,
|
||||
self.submit_button,
|
||||
self.info_text
|
||||
self.animated_text
|
||||
)
|
||||
),
|
||||
align_y=0,
|
||||
|
||||
Reference in New Issue
Block a user