mirror of
https://github.com/rio-labs/rio.git
synced 2026-02-08 23:00:39 -06:00
Update affected functions to accommodate force_refresh() changes
This commit is contained in:
@@ -98,8 +98,8 @@ class DefaultRootComponent(component.Component):
|
||||
"""
|
||||
|
||||
@rio.event.on_page_change
|
||||
async def _on_page_change(self) -> None:
|
||||
await self.force_refresh()
|
||||
def _on_page_change(self) -> None:
|
||||
self.force_refresh()
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
# Special case: If the app only has a single page, don't spawn any
|
||||
|
||||
@@ -95,8 +95,8 @@ class SwitcherBar(FundamentalComponent, t.Generic[T]):
|
||||
# Make sure the navigation bar is updated, even if the user navigates
|
||||
# to another page by another means than the navbar itself.
|
||||
@rio.event.on_page_change
|
||||
async def _on_page_change(self) -> None:
|
||||
await self.force_refresh()
|
||||
def _on_page_change(self) -> None:
|
||||
self.force_refresh()
|
||||
|
||||
def on_change(self, event: rio.SwitcherBarChangeEvent) -> None:
|
||||
# The user has selected a new value. Navigate to the corresponding
|
||||
|
||||
@@ -33,10 +33,10 @@ class ProjectPage(rio.Component):
|
||||
class ProjectComponent(rio.Component):
|
||||
project: RioProjectConfig
|
||||
|
||||
async def _on_change_app_type(self, event: rio.DropdownChangeEvent) -> None:
|
||||
def _on_change_app_type(self, event: rio.DropdownChangeEvent) -> None:
|
||||
self.project.app_type = event.value
|
||||
self.project.write()
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
project_name = self.project.project_directory.name.strip().capitalize()
|
||||
|
||||
@@ -12,7 +12,7 @@ CURRENTLY_PROFILING = False
|
||||
|
||||
|
||||
class RioDeveloperPage(rio.Component):
|
||||
async def _on_start_profiling(self) -> None:
|
||||
def _on_start_profiling(self) -> None:
|
||||
global PROFILER, CURRENTLY_PROFILING
|
||||
assert not CURRENTLY_PROFILING
|
||||
|
||||
@@ -25,9 +25,9 @@ class RioDeveloperPage(rio.Component):
|
||||
CURRENTLY_PROFILING = True
|
||||
|
||||
# Update the UI to reflect the change
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
async def _on_stop_profiling(self) -> None:
|
||||
def _on_stop_profiling(self) -> None:
|
||||
global PROFILER, CURRENTLY_PROFILING
|
||||
assert PROFILER is not None
|
||||
assert CURRENTLY_PROFILING
|
||||
@@ -37,7 +37,7 @@ class RioDeveloperPage(rio.Component):
|
||||
CURRENTLY_PROFILING = False
|
||||
|
||||
# Update the UI to reflect the change
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
async def _on_save_profile(self) -> None:
|
||||
assert PROFILER is not None
|
||||
|
||||
@@ -46,11 +46,11 @@ class SampleIconsGrid(rio.Component):
|
||||
"""
|
||||
await self.call_event_handler(self.on_select_icon, icon_name)
|
||||
|
||||
async def _on_randomize(self) -> None:
|
||||
def _on_randomize(self) -> None:
|
||||
global DISPLAYED_ICON_NAMES
|
||||
DISPLAYED_ICON_NAMES = list(find_icons_to_display())
|
||||
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
# Build a flat list of all icons
|
||||
|
||||
@@ -308,10 +308,10 @@ def on_window_size_change(
|
||||
```python
|
||||
class WindowSizeDisplay(rio.Component):
|
||||
@rio.event.on_window_size_change
|
||||
async def on_window_size_change(self):
|
||||
await self.force_refresh()
|
||||
def on_window_size_change(self) -> None:
|
||||
self.force_refresh()
|
||||
|
||||
def build(self):
|
||||
def build(self) -> rio.Component:
|
||||
width = self.session.window_width
|
||||
height = self.session.window_height
|
||||
return rio.Text(f"The window size is {width:.1f}x{height:.1f}")
|
||||
|
||||
@@ -79,7 +79,7 @@ class ChatPage(rio.Component):
|
||||
|
||||
# Indicate to the user that the app is doing something
|
||||
self.is_loading = True
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
# Generate a response
|
||||
try:
|
||||
|
||||
@@ -24,11 +24,11 @@ class Navbar(rio.Component):
|
||||
# Instead, we can use Rio's `on_page_change` event to trigger a rebuild of
|
||||
# the navbar when the page changes.
|
||||
@rio.event.on_page_change
|
||||
async def on_page_change(self) -> None:
|
||||
def on_page_change(self) -> None:
|
||||
# Rio comes with a function specifically for this. Whenever Rio is
|
||||
# unable to detect a change automatically, use this function to force a
|
||||
# refresh.
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
async def on_logout(self) -> None:
|
||||
user_session = self.session[data_models.UserSession]
|
||||
|
||||
@@ -58,7 +58,7 @@ class LoginPage(rio.Component):
|
||||
try:
|
||||
# Inform the user that something is happening
|
||||
self._currently_logging_in = True
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
# Try to find a user with this name
|
||||
pers = self.session[persistence.Persistence]
|
||||
|
||||
@@ -98,14 +98,14 @@ class Navbar(rio.Component):
|
||||
# Instead, we can use Rio's `on_page_change` event to trigger a rebuild of
|
||||
# the navbar when the page changes.
|
||||
@rio.event.on_page_change
|
||||
async def on_page_change(self) -> None:
|
||||
def on_page_change(self) -> None:
|
||||
"""
|
||||
Trigger a rebuild of the navbar when the page changes.
|
||||
"""
|
||||
# Rio comes with a function specifically for this. Whenever Rio is
|
||||
# unable to detect a change automatically, use this function to force a
|
||||
# refresh.
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
def _get_active_url_fragment(self) -> str | None:
|
||||
"""
|
||||
|
||||
@@ -35,7 +35,7 @@ class TodoItemComponent(rio.Component):
|
||||
# Rio doesn't know that we modified the TodoItem, so it won't
|
||||
# automatically rebuild this component. We have to manually trigger a
|
||||
# rebuild.
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
return rio.Card(
|
||||
|
||||
@@ -24,30 +24,30 @@ class TodoListPage(rio.Component):
|
||||
an input form that lets the user create a new `TodoItem`.
|
||||
"""
|
||||
|
||||
async def _add_new_todo_item(self, todo_item: TodoItem) -> None:
|
||||
def _add_new_todo_item(self, todo_item: TodoItem) -> None:
|
||||
# Append the new item to the list
|
||||
settings = self.session[TodoAppSettings]
|
||||
settings.todo_items.append(todo_item)
|
||||
|
||||
# Save the settings and rebuild this component
|
||||
await self._on_settings_changed()
|
||||
self._on_settings_changed()
|
||||
|
||||
async def _delete_todo_item(self, todo_item: TodoItem) -> None:
|
||||
def _delete_todo_item(self, todo_item: TodoItem) -> None:
|
||||
# Remove the item from the list
|
||||
settings = self.session[TodoAppSettings]
|
||||
settings.todo_items.remove(todo_item)
|
||||
|
||||
# Save the settings and rebuild this component
|
||||
await self._on_settings_changed()
|
||||
self._on_settings_changed()
|
||||
|
||||
async def _on_settings_changed(self) -> None:
|
||||
def _on_settings_changed(self) -> None:
|
||||
# Re-attach the settings to save them
|
||||
self.session.attach(self.session[TodoAppSettings])
|
||||
|
||||
# Rio doesn't know that this component needs to be rebuilt, since it
|
||||
# doesn't have any properties that have changed. We'll tell rio to
|
||||
# rebuild it by calling `self.force_refresh()`.
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
settings = self.session[TodoAppSettings]
|
||||
|
||||
@@ -57,13 +57,13 @@ class BenchmarkComponent(rio.Component):
|
||||
self.child_factory(),
|
||||
)
|
||||
|
||||
async def _change(self):
|
||||
async def _change(self) -> None:
|
||||
try:
|
||||
self.child_factory = next(self._child_factory_iter)
|
||||
except StopIteration:
|
||||
self.session.close()
|
||||
else:
|
||||
await self.force_refresh()
|
||||
self.force_refresh()
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user