Skip to content

Commit

Permalink
Allow closing chat and improve chat creation
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Mar 19, 2024
1 parent e95e88d commit 2f86ab8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
26 changes: 15 additions & 11 deletions packages/collaboration-extension/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,22 @@ export const chat: JupyterFrontEndPlugin<ChatPanel> = {
execute: async args => {
let filepath = (args.filepath as string) ?? '';
if (!filepath) {
let name = args.name ?? '';
if (!args.name) {
name =
(
await InputDialog.getText({
label: 'Name',
placeholder: 'untitled',
title: 'Name of the chat'
})
).value ?? '';
let name: string | null = (args.name as string) ?? null;
if (!name) {
name = (
await InputDialog.getText({
label: 'Name',
placeholder: 'untitled',
title: 'Name of the chat'
})
).value;
}
if (name) {
// no-op if the dialog has been cancelled
// fill the filepath if the dialog has been validated with content
// otherwise create a new untitled chat (empty filepath)
if (name === null) {
return;
} else if (name) {
filepath = `${name}${chatFileType.extensions[0]}`;
}
}
Expand Down
18 changes: 12 additions & 6 deletions packages/docprovider/src/chat/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import * as React from 'react';

import { CollaborativeChatModel } from './model';

const SECTION_CLASS = 'jp-collaborativeChat-section';
const TOOLBAR_CLASS = 'jp-collaborativeChat-toolbar';
const SIDEPANEL_CLASS = 'jp-collab-chat-sidepanel';
const ADD_BUTTON_CLASS = 'jp-collab-chat-add';
const OPEN_SELECT_CLASS = 'jp-collab-chat-open';
const SECTION_CLASS = 'jp-collab-chat-section';
const TOOLBAR_CLASS = 'jp-collab-chat-toolbar';

/**
* DocumentWidget: widget that represents the view or editor for a file type.
Expand Down Expand Up @@ -59,23 +62,25 @@ export class ChatPanel extends SidePanel {
*/
constructor(options: ChatPanel.IOptions) {
super(options);

this.addClass(SIDEPANEL_CLASS);
this._commands = options.commands;
this._rmRegistry = options.rmRegistry;
this._themeManager = options.themeManager;

const { commands, filebrowser } = options;
const addChat = new CommandToolbarButton({
commands,
commands: this._commands,
id: ChatPanel.CommandIDs.createChat,
icon: addIcon
});
addChat.addClass(ADD_BUTTON_CLASS);
this.toolbar.addItem('createChat', addChat);

const { filebrowser } = options;
const openChat = new ChatSelect({
filebrowser,
handleChange: this._chatSelected.bind(this)
});
openChat.addClass(OPEN_SELECT_CLASS);
this.toolbar.addItem('openChat', openChat);

const content = this.content as AccordionPanel;
Expand Down Expand Up @@ -203,7 +208,8 @@ class ChatSection extends PanelWithToolbar {
icon: closeIcon,
className: 'jp-mod-styled',
onClick: () => {
console.log('should close the chat');
this.model.dispose();
this.dispose();
}
});
this.toolbar.addItem('collaborativeChat-close', closeButton);
Expand Down

0 comments on commit 2f86ab8

Please sign in to comment.