Skip to content

Commit

Permalink
Better initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienLelaquais committed Aug 2, 2024
1 parent 48b544f commit f04ea8f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions doc/gui/examples/controls/chat-discuss.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def send(state, _: str, payload: dict):
state.messages = messages


def on_init(state):
# Copy the global variables users and messages to this user's state
state.users = users
state.messages = messages


def on_navigate(state, path: str):
# Navigate to the 'register' page if the user is not registered
if path == "discuss" and state.username == "":
Expand All @@ -61,8 +67,6 @@ def register(state):


register_page = """
<|toggle|theme|>
Please enter your user name:
<|{username}|input|>
Expand All @@ -71,8 +75,6 @@ def register(state):
"""

discuss_page = """
<|toggle|theme|>
<|### Let's discuss, {username}|text|mode=markdown|>
<|{messages}|chat|users={users}|sender_id={username}|on_action=send|>
Expand Down

0 comments on commit f04ea8f

Please sign in to comment.