defhome_page(self)->None:try:state=me.state(State)withme.box(style=self._styles.root):self.past_conversations_box()ifstate.in_conversation:self.conversation_box()else:self.conversation_starter_box()exceptExceptionase:logger.error(f"home_page(): Error rendering home page: {e}")me.text(text="Error: Something went wrong, please check logs for details.")
defpast_conversations_box(self)->None:defconversation_display_title(full_name:str,max_length:int)->str:iflen(full_name)<=max_length:returnfull_nameelse:returnfull_name[:max_length-3]+"..."defselect_past_conversation(ev:me.ClickEvent)->Iterator[None]:id=ev.keystate=me.state(State)conversations_with_id=list(filter(lambdac:c.id==id,state.past_conversations))conversation=conversations_with_id[0]state.conversation=conversationstate.in_conversation=Trueyieldtime.sleep(1)yieldme.scroll_into_view(key="end_of_messages")yielddefon_show_hide(ev:me.ClickEvent)->None:state.hide_past=notstate.hide_pastdefon_start_new_conversation(ev:me.ClickEvent)->None:state.in_conversation=Falsestate.prompt=""state=me.state(State)style=(self._styles.past_chats_hideifstate.hide_pastelseself._styles.past_chats_show)withme.box(style=style):withme.box(style=self._styles.past_chats_inner,):withme.content_button(on_click=on_show_hide,disabled=notstate.past_conversations):me.icon("menu")withme.content_button(on_click=on_start_new_conversation,disabled=notstate.conversation.completed,):me.icon("rate_review")ifnotstate.hide_past:forconversationinstate.past_conversations:withme.box(key=conversation.id,# they are GUIDs so should not clash with anything other on the pageon_click=select_past_conversation,style=self._styles.past_chats_conv,):me.text(text=conversation_display_title(conversation.title,128))