From 1cf97de29eaee711be4d64c87e961f7626fc47aa Mon Sep 17 00:00:00 2001 From: Elijah Date: Tue, 17 Sep 2024 15:12:35 +0000 Subject: [PATCH 01/10] Support for reflex v0.6.0 --- clock/clock/clock.py | 11 ++++++----- clock/requirements.txt | 1 + .../customer_data_app/backend/backend.py | 6 +++--- dalle/dalle/dalle.py | 2 +- github-stats/github_stats/github_stats.py | 2 +- gpt/gpt/gpt.py | 2 +- lorem-stream/lorem_stream/lorem_stream.py | 7 ++++--- lorem-stream/requirements.txt | 1 + quiz/quiz/results.py | 3 ++- quiz/requirements.txt | 1 + sales/sales/backend/backend.py | 6 +++--- snakegame/snakegame/snakegame.py | 5 +++-- 12 files changed, 27 insertions(+), 20 deletions(-) diff --git a/clock/clock/clock.py b/clock/clock/clock.py index aebad6f3..35ed786f 100644 --- a/clock/clock/clock.py +++ b/clock/clock/clock.py @@ -5,6 +5,7 @@ from typing import Any import reflex as rx +import reflex_chakra as rc from reflex.components.radix.themes import theme import pytz @@ -47,7 +48,7 @@ class State(rx.State): # The last updated timestamp _now: datetime = datetime.fromtimestamp(0) - @rx.cached_var + @rx.var(cache=True) def valid_zone(self) -> str: """Get the current time zone. @@ -60,7 +61,7 @@ def valid_zone(self) -> str: return DEFAULT_ZONE return self.zone - @rx.cached_var + @rx.var(cache=True) def time_info(self) -> dict[str, Any]: """Get the current time info. @@ -126,7 +127,7 @@ def clock_hand(rotation: str, color: str, length: str) -> rx.Component: Returns: A clock hand component. """ - return rx.chakra.divider( + return rx.divider( transform=rotation, width=f"{length}em", position="absolute", @@ -139,9 +140,9 @@ def clock_hand(rotation: str, color: str, length: str) -> rx.Component: def analog_clock() -> rx.Component: """Create the analog clock.""" - return rx.chakra.circle( + return rc.circle( # The inner circle. - rx.chakra.circle( + rc.circle( width="1em", height="1em", border_width="thick", diff --git a/clock/requirements.txt b/clock/requirements.txt index 6616cd0c..b80e4bbf 100644 --- a/clock/requirements.txt +++ b/clock/requirements.txt @@ -1,2 +1,3 @@ reflex>=0.4.0 pytz==2022.7.1 +reflex-chakra>=0.60a7 diff --git a/customer_data_app/customer_data_app/backend/backend.py b/customer_data_app/customer_data_app/backend/backend.py index 401808a0..85190919 100644 --- a/customer_data_app/customer_data_app/backend/backend.py +++ b/customer_data_app/customer_data_app/backend/backend.py @@ -145,7 +145,7 @@ def add_customer_to_db(self, form_data: dict): session.add(Customer(**self.current_user)) session.commit() self.load_entries() - return rx.toast.info(f"User {self.current_user['name']} has been added.", variant="outline", position="bottom-right") + return rx.toast.info(f"User {self.current_user['name']} has been added.", position="bottom-right") def update_customer_to_db(self, form_data: dict): @@ -160,7 +160,7 @@ def update_customer_to_db(self, form_data: dict): session.add(customer) session.commit() self.load_entries() - return rx.toast.info(f"User {self.current_user['name']} has been modified.", variant="outline", position="bottom-right") + return rx.toast.info(f"User {self.current_user['name']} has been modified.", position="bottom-right") def delete_customer(self, id: int): @@ -170,7 +170,7 @@ def delete_customer(self, id: int): session.delete(customer) session.commit() self.load_entries() - return rx.toast.info(f"User {customer.name} has been deleted.", variant="outline", position="bottom-right") + return rx.toast.info(f"User {customer.name} has been deleted.", position="bottom-right") @rx.var diff --git a/dalle/dalle/dalle.py b/dalle/dalle/dalle.py index cd07f7e8..6e323568 100644 --- a/dalle/dalle/dalle.py +++ b/dalle/dalle/dalle.py @@ -68,7 +68,7 @@ def index(): rx.divider(), rx.cond( State.image_processing, - rx.chakra.circular_progress(is_indeterminate=True), + rx.spinner(), rx.cond( State.image_made, rx.image( diff --git a/github-stats/github_stats/github_stats.py b/github-stats/github_stats/github_stats.py index 3acb30ca..6b83bdc2 100644 --- a/github-stats/github_stats/github_stats.py +++ b/github-stats/github_stats/github_stats.py @@ -85,7 +85,7 @@ def add_user(self): self._save_selected_users() return State.fetch_missing_stats - @rx.cached_var + @rx.var(cache=True) def data_pretty(self) -> str: return json.dumps(self.user_stats, indent=2) diff --git a/gpt/gpt/gpt.py b/gpt/gpt/gpt.py index 0b2ae332..42e14eb7 100644 --- a/gpt/gpt/gpt.py +++ b/gpt/gpt/gpt.py @@ -153,7 +153,7 @@ def result_view() -> rx.Component: rx.text(State.prompt), rx.cond( State.loading, - rx.chakra.spinner(), + rx.spinner(), ), justify="between", ), diff --git a/lorem-stream/lorem_stream/lorem_stream.py b/lorem-stream/lorem_stream/lorem_stream.py index b9d06f3a..d30a8f2f 100644 --- a/lorem-stream/lorem_stream/lorem_stream.py +++ b/lorem-stream/lorem_stream/lorem_stream.py @@ -4,6 +4,7 @@ from lorem_text import lorem import reflex as rx +import reflex_chakra as rc ITERATIONS_RANGE = (7, 12) @@ -62,8 +63,8 @@ def kill(self, task_id: int): def render_task(task_id: int) -> rx.Component: return rx.vstack( rx.hstack( - rx.chakra.circular_progress( - rx.chakra.circular_progress_label(task_id), + rc.circular_progress( + rc.circular_progress_label(task_id), value=LoremState.progress[task_id], max_=LoremState.end_at[task_id], is_indeterminate=LoremState.progress[task_id] < 1, @@ -87,7 +88,7 @@ def render_task(task_id: int) -> rx.Component: def index() -> rx.Component: return rx.vstack( rx.button("➕ New Task", on_click=LoremState.stream_text(-1)), - rx.chakra.flex( + rx.flex( rx.foreach(LoremState.task_ids, render_task), flex_wrap="wrap", width="100%", diff --git a/lorem-stream/requirements.txt b/lorem-stream/requirements.txt index 924f84a9..1714a004 100644 --- a/lorem-stream/requirements.txt +++ b/lorem-stream/requirements.txt @@ -1,2 +1,3 @@ reflex>=0.4.8 lorem_text>=2.1 +reflex-chakra>=0.6.0a7 diff --git a/quiz/quiz/results.py b/quiz/quiz/results.py index 5ccde69c..37a554d6 100644 --- a/quiz/quiz/results.py +++ b/quiz/quiz/results.py @@ -1,4 +1,5 @@ import reflex as rx +import reflex_chakra as rc from .styles import base_style as answer_style from .styles import page_background @@ -31,7 +32,7 @@ def centered_item(item): rx.text("Below are the results of the quiz."), rx.divider(), centered_item( - rx.chakra.circular_progress( + rc.circular_progress( label=State.percent_score, value=State.score, size="3em" ) ), diff --git a/quiz/requirements.txt b/quiz/requirements.txt index a7536334..5c0d3e85 100644 --- a/quiz/requirements.txt +++ b/quiz/requirements.txt @@ -1 +1,2 @@ reflex>=0.5.0 +reflex-chakra>=0.6.0a7 \ No newline at end of file diff --git a/sales/sales/backend/backend.py b/sales/sales/backend/backend.py index f713812f..ca5444a9 100644 --- a/sales/sales/backend/backend.py +++ b/sales/sales/backend/backend.py @@ -125,7 +125,7 @@ def add_customer_to_db(self, form_data: dict): session.add(Customer(**self.current_user)) session.commit() self.load_entries() - return rx.toast.info(f"User {self.current_user['customer_name']} has been added.", variant="outline", position="bottom-right") + return rx.toast.info(f"User {self.current_user['customer_name']} has been added.", position="bottom-right") def update_customer_to_db(self, form_data: dict): self.current_user.update(form_data) @@ -139,7 +139,7 @@ def update_customer_to_db(self, form_data: dict): session.add(customer) session.commit() self.load_entries() - return rx.toast.info(f"User {self.current_user['customer_name']} has been modified.", variant="outline", position="bottom-right") + return rx.toast.info(f"User {self.current_user['customer_name']} has been modified.", position="bottom-right") def delete_customer(self, id: int): """Delete a customer from the database.""" @@ -149,7 +149,7 @@ def delete_customer(self, id: int): session.delete(customer) session.commit() self.load_entries() - return rx.toast.info(f"User {customer.customer_name} has been deleted.", variant="outline", position="bottom-right") + return rx.toast.info(f"User {customer.customer_name} has been deleted.", position="bottom-right") @rx.background async def call_openai(self): diff --git a/snakegame/snakegame/snakegame.py b/snakegame/snakegame/snakegame.py index 07a06db0..d7cc2c64 100644 --- a/snakegame/snakegame/snakegame.py +++ b/snakegame/snakegame/snakegame.py @@ -4,6 +4,7 @@ import reflex as rx from reflex.utils.imports import ImportDict, ImportVar +from reflex.ivars.base import LiteralVar N = 19 # There is a N*N grid for ground of snake COLOR_NONE = "#EEEEEE" @@ -221,7 +222,7 @@ def _get_hooks(self) -> str | None: }) """ % ( self.keys, - rx.utils.format.format_event_chain(self.event_triggers["on_key_down"]), + str(LiteralVar.create(self.event_triggers["on_key_down"])), ) def get_event_triggers(self) -> Dict[str, Any]: @@ -236,7 +237,7 @@ def render(self) -> str: def colored_box(color, index): """One square of the game grid.""" - return rx.chakra.box( + return rx.box( background_color=color, width="1em", height="1em", border="1px solid white" ) From be0265643a8a98b7916bddd9d58bd9d0a2857ff8 Mon Sep 17 00:00:00 2001 From: Elijah Date: Tue, 17 Sep 2024 15:26:09 +0000 Subject: [PATCH 02/10] fix requirements for clock --- clock/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clock/requirements.txt b/clock/requirements.txt index b80e4bbf..1ccb79b2 100644 --- a/clock/requirements.txt +++ b/clock/requirements.txt @@ -1,3 +1,3 @@ reflex>=0.4.0 pytz==2022.7.1 -reflex-chakra>=0.60a7 +reflex-chakra>=0.6.0a7 From 62ea73b6c4a569ee6cd4ab1bc8a46a9b97efea30 Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 18 Sep 2024 08:59:35 +0000 Subject: [PATCH 03/10] more fixes --- data_visualisation/data_visualisation/data_visualisation.py | 2 +- nba/nba/views/table.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data_visualisation/data_visualisation/data_visualisation.py b/data_visualisation/data_visualisation/data_visualisation.py index cc773a0f..b181d1aa 100644 --- a/data_visualisation/data_visualisation/data_visualisation.py +++ b/data_visualisation/data_visualisation/data_visualisation.py @@ -285,7 +285,7 @@ def navbar(): rx.spacer(), add_item_ui(), rx.avatar(fallback="TG", size="4"), - rx.color_mode.button(rx.color_mode.icon(), size="3", float="right"), + rx.color_mode.button(), position="fixed", width="100%", top="0px", diff --git a/nba/nba/views/table.py b/nba/nba/views/table.py index bb67844b..c6a26618 100644 --- a/nba/nba/views/table.py +++ b/nba/nba/views/table.py @@ -78,4 +78,4 @@ def table() -> rx.Component: search=True, sort=True, resizable=True, - ), + ) From 0986982d9426d56533244ed9b9f72927bc4b68ae Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 18 Sep 2024 09:37:29 +0000 Subject: [PATCH 04/10] fix requirements --- clock/requirements.txt | 2 +- github-stats/requirements.txt | 2 +- snakegame/requirements.txt | 2 +- snakegame/snakegame/snakegame.py | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clock/requirements.txt b/clock/requirements.txt index 1ccb79b2..0972f409 100644 --- a/clock/requirements.txt +++ b/clock/requirements.txt @@ -1,3 +1,3 @@ -reflex>=0.4.0 +reflex>=0.6.0a2 pytz==2022.7.1 reflex-chakra>=0.6.0a7 diff --git a/github-stats/requirements.txt b/github-stats/requirements.txt index d4deee8a..b62b1fd7 100644 --- a/github-stats/requirements.txt +++ b/github-stats/requirements.txt @@ -1 +1 @@ -reflex>=0.4.0 +reflex>=0.6.0a2 diff --git a/snakegame/requirements.txt b/snakegame/requirements.txt index d4deee8a..b62b1fd7 100644 --- a/snakegame/requirements.txt +++ b/snakegame/requirements.txt @@ -1 +1 @@ -reflex>=0.4.0 +reflex>=0.6.0a2 diff --git a/snakegame/snakegame/snakegame.py b/snakegame/snakegame/snakegame.py index d7cc2c64..dcc2e406 100644 --- a/snakegame/snakegame/snakegame.py +++ b/snakegame/snakegame/snakegame.py @@ -4,7 +4,6 @@ import reflex as rx from reflex.utils.imports import ImportDict, ImportVar -from reflex.ivars.base import LiteralVar N = 19 # There is a N*N grid for ground of snake COLOR_NONE = "#EEEEEE" @@ -222,7 +221,7 @@ def _get_hooks(self) -> str | None: }) """ % ( self.keys, - str(LiteralVar.create(self.event_triggers["on_key_down"])), + str(rx.vars.LiteralVar.create(self.event_triggers["on_key_down"])), ) def get_event_triggers(self) -> Dict[str, Any]: From 154e559eabd0d16d1debcb16271e7007811ba91b Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 18 Sep 2024 09:49:22 +0000 Subject: [PATCH 05/10] use base requirements for breaking changes --- clock/requirements.txt | 2 +- github-stats/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clock/requirements.txt b/clock/requirements.txt index 0972f409..43d8eeda 100644 --- a/clock/requirements.txt +++ b/clock/requirements.txt @@ -1,3 +1,3 @@ -reflex>=0.6.0a2 +reflex>=0.5.6 pytz==2022.7.1 reflex-chakra>=0.6.0a7 diff --git a/github-stats/requirements.txt b/github-stats/requirements.txt index b62b1fd7..c4e39d0c 100644 --- a/github-stats/requirements.txt +++ b/github-stats/requirements.txt @@ -1 +1 @@ -reflex>=0.6.0a2 +reflex>=0.5.6 From ff37aa8707484c8a1ce55fbf1bad906a2cf6221c Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Fri, 20 Sep 2024 13:52:17 -0700 Subject: [PATCH 06/10] Update form-designer example for 0.6.0 --- form-designer/form_designer/form_designer.py | 12 +++++------- form-designer/form_designer/pages/response.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/form-designer/form_designer/form_designer.py b/form-designer/form_designer/form_designer.py index 3a7b7585..a188b7db 100644 --- a/form-designer/form_designer/form_designer.py +++ b/form-designer/form_designer/form_designer.py @@ -1,3 +1,4 @@ +import contextlib import reflex as rx import reflex_local_auth @@ -20,16 +21,13 @@ responses_title, ) - -# Add these dynamic route vars early, so they can be referenced in the titles. -if "form_id" not in rx.State.__fields__: - rx.State.add_var("form_id", str, "") -if "field_id" not in rx.State.__fields__: - rx.State.add_var("field_id", str, "") - app = rx.App(theme=rx.theme(accent_color="blue")) app.add_page(home_page, route="/", title=constants.TITLE) +# Adding a dummy route to register the dynamic route vars. +with contextlib.suppress(ValueError): + app.add_page(lambda: rx.fragment(on_click=False), route="/_dummy/[form_id]/[field_id]") + # Authentication via reflex-local-auth app.add_page( reflex_local_auth.pages.login_page, diff --git a/form-designer/form_designer/pages/response.py b/form-designer/form_designer/pages/response.py index 9a1fb342..56d4aff0 100644 --- a/form-designer/form_designer/pages/response.py +++ b/form-designer/form_designer/pages/response.py @@ -34,7 +34,7 @@ def delete_response(self, id: int): def response_content(response: Response): return rx.vstack( - rx.moment(value=response.ts), + rx.moment(response.ts), rx.foreach( response.field_values, lambda fv: rx.vstack( From 34ba506de2d8fd36fd39b8551ac7de90378cab19 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Tue, 24 Sep 2024 13:53:50 -0700 Subject: [PATCH 07/10] snakegame: fix keyboard controls --- snakegame/.gitignore | 1 + snakegame/snakegame/snakegame.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/snakegame/.gitignore b/snakegame/.gitignore index 575e5381..e4170665 100644 --- a/snakegame/.gitignore +++ b/snakegame/.gitignore @@ -2,4 +2,5 @@ *.py[cod] .web __pycache__/ +assets/external/ reflex.db diff --git a/snakegame/snakegame/snakegame.py b/snakegame/snakegame/snakegame.py index dcc2e406..0835c828 100644 --- a/snakegame/snakegame/snakegame.py +++ b/snakegame/snakegame/snakegame.py @@ -210,9 +210,10 @@ def _get_imports(self) -> ImportDict: def _get_hooks(self) -> str | None: return """ useEffect(() => { - const handle_key = (_e0) => { - if (%s.includes(_e0.key)) - %s + const handle_key = (event) => { + if (%s.includes(event.key)) { + %s(event) + } } document.addEventListener("keydown", handle_key, false); return () => { @@ -221,7 +222,7 @@ def _get_hooks(self) -> str | None: }) """ % ( self.keys, - str(rx.vars.LiteralVar.create(self.event_triggers["on_key_down"])), + rx.Var.create(self.event_triggers["on_key_down"]), ) def get_event_triggers(self) -> Dict[str, Any]: From 56dbac1c0dcaece8cb50295721f0290f3cfd05a0 Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 25 Sep 2024 15:53:13 +0000 Subject: [PATCH 08/10] update snake game requirement --- snakegame/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snakegame/requirements.txt b/snakegame/requirements.txt index b62b1fd7..9cd7c052 100644 --- a/snakegame/requirements.txt +++ b/snakegame/requirements.txt @@ -1 +1 @@ -reflex>=0.6.0a2 +reflex>=0.6.0 From f4086c6c30da2d28a52672ddffe59a59f42ee059 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 25 Sep 2024 12:10:59 -0700 Subject: [PATCH 09/10] always get backend state since it now lives on disk and doesnt update automatically --- counter/tests/test_counter.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/counter/tests/test_counter.py b/counter/tests/test_counter.py index 69c013a2..0f19e824 100644 --- a/counter/tests/test_counter.py +++ b/counter/tests/test_counter.py @@ -33,8 +33,10 @@ def _poll_token(): state_name = counter_app.get_state_name("State") full_state_name = counter_app.get_full_state_name("State") - root_state = await counter_app.get_state(f"{token}_{full_state_name}") - backend_state = root_state.substates[state_name] + + async def _get_backend_state(): + root_state = await counter_app.get_state(f"{token}_{full_state_name}") + return root_state.substates[state_name] count = driver.find_element(By.TAG_NAME, "h1") assert counter_app.poll_for_content(count) == "0" @@ -45,17 +47,17 @@ def _poll_token(): decrement.click() assert counter_app.poll_for_content(count, exp_not_equal="0") == "-1" - assert backend_state.count == -1 + assert (await _get_backend_state()).count == -1 increment.click() assert counter_app.poll_for_content(count, exp_not_equal="-1") == "0" increment.click() assert counter_app.poll_for_content(count, exp_not_equal="0") == "1" - assert backend_state.count == 1 + assert (await _get_backend_state()).count == 1 randomize.click() random_count = counter_app.poll_for_content(count, exp_not_equal="1") - assert backend_state.count == int(random_count) + assert (await _get_backend_state()).count == int(random_count) decrement.click() dec_value = str(int(random_count) - 1) assert counter_app.poll_for_content(count, exp_not_equal=random_count) == dec_value From 6a592c9bc35e477c37db6d8c289bd6ece50ccdee Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 25 Sep 2024 14:59:37 -0700 Subject: [PATCH 10/10] form_designer: only create the app once per session avoid recompiling the app after its already been compiled: the Var system gets mad when encountering StatefulComponent in the tree. --- form-designer/tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/form-designer/tests/conftest.py b/form-designer/tests/conftest.py index 793a583a..84fdf8cd 100644 --- a/form-designer/tests/conftest.py +++ b/form-designer/tests/conftest.py @@ -9,7 +9,7 @@ from reflex_local_auth import LocalUser -@pytest.fixture(scope="module") +@pytest.fixture(scope="session") def form_designer_app(): with AppHarness.create(root=Path(__file__).parent.parent) as harness: yield harness