From 6306a61e3daf39eb46560c0002f4668f1aa3dbe6 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Thu, 16 May 2024 01:15:42 +0200 Subject: [PATCH] clean up PR --- reflex/components/core/banner.py | 42 ++++++++++++++---------------- reflex/components/core/banner.pyi | 1 - reflex/components/sonner/toast.py | 2 +- reflex/components/sonner/toast.pyi | 2 +- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/reflex/components/core/banner.py b/reflex/components/core/banner.py index 71b13b8ad03..8ebbb16b35e 100644 --- a/reflex/components/core/banner.py +++ b/reflex/components/core/banner.py @@ -32,8 +32,8 @@ value=CompileVars.CONNECT_ERROR, _var_is_local=True, _var_is_string=False, -)._replace(merge_var_data=connect_error_var_data) - + _var_data=connect_error_var_data, +) connection_error: Var = Var.create_safe( value="(connectErrors.length > 0) ? connectErrors[connectErrors.length - 1].message : ''", @@ -98,20 +98,6 @@ def default_connection_error() -> list[str | Var | Component]: class ConnectionToaster(Toaster): """A connection toaster component.""" - def add_imports(self) -> dict[str, list[str | imports.ImportVar]]: - """Add the imports for the connection toaster. - - Returns: - The imports for the connection toaster. - """ - imports_ = {**Imports.EVENTS} # type: ignore - imports_["react"].append("useEffect") # type: ignore # remove when 3248 is merged - (imports_.setdefault(f"/{Dirs.STATE_PATH}", []).append("getBackendURL")) # type: ignore - imports_.setdefault("/env.json", []).append( - imports.ImportVar(tag="env", is_default=True) - ) - return imports_ # type: ignore - def add_hooks(self) -> list[str]: """Add the hooks for the connection toaster. @@ -124,8 +110,13 @@ def add_hooks(self) -> list[str]: else return ''; };""" - props = ToastProps( - description=f"Check if server is reachable at ${{getBackendURL(env.EVENT).href}}", + target_url = WebsocketTargetURL.create() + props = ToastProps( # type: ignore + description=Var.create( + f"`Check if server is reachable at ${target_url}`", + _var_is_string=False, + _var_is_local=False, + ), id="websocket-error", ) hook = Var.create( @@ -135,14 +126,19 @@ def add_hooks(self) -> list[str]: }}, [{connect_errors}]);""" ) - # can uncomment when 3248 is merged - # hook._var_data = VarData.merge( - # connect_errors._var_data, VarData(imports={"react": ["useEffect"]}) - # ) + hook._var_data = VarData.merge( # type: ignore + connect_errors._var_data, + VarData( + imports={ + "react": [imports.ImportVar(tag="useEffect")], + **target_url._get_imports(), + } + ), + ) return [ Hooks.EVENTS, util_hook, - hook, + hook, # type: ignore ] diff --git a/reflex/components/core/banner.pyi b/reflex/components/core/banner.pyi index 8381071865d..64f9761f9a1 100644 --- a/reflex/components/core/banner.pyi +++ b/reflex/components/core/banner.pyi @@ -104,7 +104,6 @@ class WebsocketTargetURL(Bare): def default_connection_error() -> list[str | Var | Component]: ... class ConnectionToaster(Toaster): - def add_imports(self) -> dict[str, list[str | imports.ImportVar]]: ... def add_hooks(self) -> list[str]: ... @overload @classmethod diff --git a/reflex/components/sonner/toast.py b/reflex/components/sonner/toast.py index d820af2da5b..422cba57209 100644 --- a/reflex/components/sonner/toast.py +++ b/reflex/components/sonner/toast.py @@ -74,7 +74,7 @@ class ToastProps(PropsBase): """Props for the toast component.""" # Toast's description, renders underneath the title. - description: Optional[str] + description: Optional[str | Var] # Whether to show the close button. close_button: Optional[bool] diff --git a/reflex/components/sonner/toast.pyi b/reflex/components/sonner/toast.pyi index 5bd6cdeb419..581462a65b8 100644 --- a/reflex/components/sonner/toast.pyi +++ b/reflex/components/sonner/toast.pyi @@ -37,7 +37,7 @@ class ToastAction(Base): def serialize_action(action: ToastAction) -> dict: ... class ToastProps(PropsBase): - description: Optional[str] + description: Optional[str | Var] close_button: Optional[bool] invert: Optional[bool] important: Optional[bool]