def past_conversations_box(self) -> None:
def conversation_display_title(full_name: str, max_length: int) -> str:
if len(full_name) <= max_length:
return full_name
else:
return full_name[: max_length - 3] + "..."
def select_past_conversation(ev: me.ClickEvent) -> Iterator[None]:
id = ev.key
state = me.state(State)
conversations_with_id = list(
filter(lambda c: c.id == id, state.past_conversations)
)
conversation = conversations_with_id[0]
state.conversation = conversation
state.in_conversation = True
yield
time.sleep(1)
yield
me.scroll_into_view(key="end_of_messages")
yield
def on_show_hide(ev: me.ClickEvent) -> None:
state.hide_past = not state.hide_past
def on_start_new_conversation(ev: me.ClickEvent) -> None:
state.in_conversation = False
state.prompt = ""
state = me.state(State)
style = (
self._styles.past_chats_hide
if state.hide_past
else self._styles.past_chats_show
)
with me.box(style=style):
with me.box(
style=self._styles.past_chats_inner,
):
with me.content_button(
on_click=on_show_hide, disabled=not state.past_conversations
):
me.icon("menu")
with me.content_button(
on_click=on_start_new_conversation,
disabled=not state.conversation.completed,
):
me.icon("rate_review")
if not state.hide_past:
for conversation in state.past_conversations:
with me.box(
key=conversation.id, # they are GUIDs so should not clash with anything other on the page
on_click=select_past_conversation,
style=self._styles.past_chats_conv,
):
me.text(
text=conversation_display_title(conversation.title, 128)
)