From 6c80395e2ce4e38bd0198f5e905eb66268855a61 Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Mon, 15 Apr 2024 10:01:32 +0200 Subject: [PATCH] Fix the chat select initialization --- .../src/widget.tsx | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/jupyterlab-collaborative-chat/src/widget.tsx b/packages/jupyterlab-collaborative-chat/src/widget.tsx index 022b431..a1c7828 100644 --- a/packages/jupyterlab-collaborative-chat/src/widget.tsx +++ b/packages/jupyterlab-collaborative-chat/src/widget.tsx @@ -26,6 +26,7 @@ import React, { useState } from 'react'; import { CollaborativeChatModel } from './model'; import { CommandIDs } from './token'; import { ISignal, Signal } from '@lumino/signaling'; +import { Message } from '@lumino/messaging'; const MAIN_PANEL_CLASS = 'jp-collab-chat_main-panel'; const SIDEPANEL_CLASS = 'jp-collab-chat-sidepanel'; @@ -88,16 +89,15 @@ export class ChatPanel extends SidePanel { addChat.addClass(ADD_BUTTON_CLASS); this.toolbar.addItem('createChat', addChat); - const openChat = ReactWidget.create( + this._openChat = ReactWidget.create( ); - this.updateChatNames(); - openChat.addClass(OPEN_SELECT_CLASS); - this.toolbar.addItem('openChat', openChat); + this._openChat.addClass(OPEN_SELECT_CLASS); + this.toolbar.addItem('openChat', this._openChat); const content = this.content as AccordionPanel; content.expansionToggled.connect(this._onExpansionToggled, this); @@ -138,7 +138,7 @@ export class ChatPanel extends SidePanel { this.addWidget(new ChatSection({ widget, name })); } - updateChatNames = async () => { + updateChatNames = async (): Promise => { this._drive .get('.') .then(model => { @@ -150,6 +150,14 @@ export class ChatPanel extends SidePanel { .catch(e => console.error('Error getting the chat files from drive', e)); }; + /** + * A message handler invoked on an `'after-show'` message. + */ + protected onAfterShow(msg: Message): void { + // Wait for the component to be rendered. + this._openChat.renderPromise?.then(() => this.updateChatNames()); + } + /** * Handle `change` events for the HTMLSelect component. */ @@ -194,6 +202,7 @@ export class ChatPanel extends SidePanel { private _commands: CommandRegistry; private _config: IConfig = {}; private _drive: ICollaborativeDrive; + private _openChat: ReactWidget; private _rmRegistry: IRenderMimeRegistry; private _themeManager: IThemeManager | null; } @@ -286,6 +295,7 @@ function ChatSelect({ }: ChatSelectProps): JSX.Element { const [chatNames, setChatNames] = useState([]); + // Update the chat list. chatNamesChanged.connect((_, chatNames) => { setChatNames(chatNames); });