Skip to content

Commit

Permalink
clean up PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Lendemor committed May 15, 2024
1 parent 82e7155 commit 6306a61
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
42 changes: 19 additions & 23 deletions reflex/components/core/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''",
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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
]


Expand Down
1 change: 0 additions & 1 deletion reflex/components/core/banner.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion reflex/components/sonner/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion reflex/components/sonner/toast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 6306a61

Please sign in to comment.