From 88d00295999f37196016a7d27fb74c6920e0e0d6 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 6f377be..231b25b 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 SIDEPANEL_CLASS = 'jp-collab-chat-sidepanel'; const ADD_BUTTON_CLASS = 'jp-collab-chat-add'; @@ -86,16 +87,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); @@ -136,7 +136,7 @@ export class ChatPanel extends SidePanel { this.addWidget(new ChatSection({ widget, name })); } - updateChatNames = async () => { + updateChatNames = async (): Promise => { this._drive .get('.') .then(model => { @@ -148,6 +148,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. */ @@ -192,6 +200,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; } @@ -284,6 +293,7 @@ function ChatSelect({ }: ChatSelectProps): JSX.Element { const [chatNames, setChatNames] = useState([]); + // Update the chat list. chatNamesChanged.connect((_, chatNames) => { setChatNames(chatNames); });