Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion packages/jupyter-chat/src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import SettingsIcon from '@mui/icons-material/Settings';
import { IconButton } from '@mui/material';
import { Box } from '@mui/system';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import {
ChatInput,
Expand All @@ -18,6 +18,7 @@ import {
} from './input';
import { JlThemeProvider } from './jl-theme-provider';
import { ChatMessages } from './messages';
import { WritingIndicator } from './writing-indicator';
import { AttachmentOpenerContext } from '../context';
import { IChatModel } from '../model';
import {
Expand All @@ -29,10 +30,36 @@ import { ChatArea } from '../types';

export function ChatBody(props: Chat.IChatBodyProps): JSX.Element {
const { model } = props;
const [writers, setWriters] = useState<IChatModel.IWriter[]>([]);
let { inputToolbarRegistry } = props;
if (!inputToolbarRegistry) {
inputToolbarRegistry = InputToolbarRegistry.defaultToolbarRegistry();
}

/**
* Handle the changes in the writers list.
*/
useEffect(() => {
if (!model) {
return;
}

const updateWriters = (_: IChatModel, writers: IChatModel.IWriter[]) => {
// Show all writers for now - AI generating responses will have messageID
setWriters(writers);
};

// Set initial writers state
const initialWriters = model.writers;
setWriters(initialWriters);

model.writersChanged?.connect(updateWriters);

return () => {
model?.writersChanged?.disconnect(updateWriters);
};
}, [model]);

// const horizontalPadding = props.area === 'main' ? 8 : 4;
const horizontalPadding = 4;

Expand Down Expand Up @@ -60,6 +87,13 @@ export function ChatBody(props: Chat.IChatBodyProps): JSX.Element {
area={props.area}
chatModel={model}
/>
<WritingIndicator
sx={{
paddingLeft: horizontalPadding,
paddingRight: horizontalPadding
}}
writers={writers}
/>
</AttachmentOpenerContext.Provider>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/jupyter-chat/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './input';
export * from './jl-theme-provider';
export * from './messages';
export * from './scroll-container';
export * from './writing-indicator';
27 changes: 0 additions & 27 deletions packages/jupyter-chat/src/components/input/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { IInputModel, InputModel } from '../../input-model';
import { IChatCommandRegistry } from '../../registers';
import { IAttachment, ChatArea } from '../../types';
import { IChatModel } from '../../model';
import { InputWritingIndicator } from './writing-indicator';

const INPUT_BOX_CLASS = 'jp-chat-input-container';
const INPUT_TEXTFIELD_CLASS = 'jp-chat-input-textfield';
Expand All @@ -47,7 +46,6 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element {
InputToolbarRegistry.IToolbarItem[]
>([]);
const [isFocused, setIsFocused] = useState<boolean>(false);
const [writers, setWriters] = useState<IChatModel.IWriter[]>([]);

/**
* Auto-focus the input when the component is first mounted.
Expand Down Expand Up @@ -110,30 +108,6 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element {
};
}, [toolbarRegistry]);

/**
* Handle the changes in the writers list.
*/
useEffect(() => {
if (!props.chatModel) {
return;
}

const updateWriters = (_: IChatModel, writers: IChatModel.IWriter[]) => {
// Show all writers for now - AI generating responses will have messageID
setWriters(writers);
};

// Set initial writers state
const initialWriters = props.chatModel.writers;
setWriters(initialWriters);

props.chatModel.writersChanged?.connect(updateWriters);

return () => {
props.chatModel?.writersChanged?.disconnect(updateWriters);
};
}, [props.chatModel]);

const inputExists = !!input.trim();

/**
Expand Down Expand Up @@ -340,7 +314,6 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element {
))}
</Box>
</Box>
<InputWritingIndicator writers={writers} />
</Box>
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/jupyter-chat/src/components/input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ export * from './buttons';
export * from './chat-input';
export * from './toolbar-registry';
export * from './use-chat-commands';
export * from './writing-indicator';
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Distributed under the terms of the Modified BSD License.
*/

import { Box, Typography } from '@mui/material';
import { Box, SxProps, Theme, Typography } from '@mui/material';
import React from 'react';

import { IChatModel } from '../../model';
import { IChatModel } from '../model';

/**
* Classname on the root element. Used in E2E tests.
Expand All @@ -21,6 +21,10 @@ export interface IInputWritingIndicatorProps {
* The list of users currently writing.
*/
writers: IChatModel.IWriter[];
/**
* Custom mui/material styles.
*/
sx?: SxProps<Theme>;
}

/**
Expand Down Expand Up @@ -48,9 +52,9 @@ function formatWritersText(writers: IChatModel.IWriter[]): string {
}

/**
* The input writing indicator component, displaying typing status in the chat input area.
* The writing indicator component, displaying typing status.
*/
export function InputWritingIndicator(
export function WritingIndicator(
props: IInputWritingIndicatorProps
): JSX.Element {
const { writers } = props;
Expand All @@ -62,6 +66,7 @@ export function InputWritingIndicator(
<Box
className={WRITERS_ELEMENT_CLASSNAME}
sx={{
...props.sx,
minHeight: '16px'
}}
>
Expand Down
Loading