From e178ea32e5f4e3a1d499e542082b5a770c38a743 Mon Sep 17 00:00:00 2001 From: Vivien Hung Date: Tue, 11 Apr 2023 13:19:14 -0700 Subject: [PATCH 1/6] Add typing indicator. --- .../apps/copilot-chat-app/WebApp/package.json | 1 + .../WebApp/src/components/chat/ChatInput.tsx | 25 +- .../WebApp/src/components/chat/ChatRoom.tsx | 15 +- .../src/components/chat/TypingIndicator.tsx | 34 ++ .../chat/TypingIndicatorRenderer.tsx | 28 ++ .../apps/copilot-chat-app/WebApp/yarn.lock | 358 +++++++++++++++++- 6 files changed, 438 insertions(+), 23 deletions(-) create mode 100644 samples/apps/copilot-chat-app/WebApp/src/components/chat/TypingIndicator.tsx create mode 100644 samples/apps/copilot-chat-app/WebApp/src/components/chat/TypingIndicatorRenderer.tsx diff --git a/samples/apps/copilot-chat-app/WebApp/package.json b/samples/apps/copilot-chat-app/WebApp/package.json index c42525b8456c..ac2281778a90 100644 --- a/samples/apps/copilot-chat-app/WebApp/package.json +++ b/samples/apps/copilot-chat-app/WebApp/package.json @@ -21,6 +21,7 @@ "@azure/msal-react": "^1.5.1", "@fluentui/react-components": "^9.13.0", "@fluentui/react-icons": "^2.0.193", + "@fluentui/react-northstar": "^0.66.4", "@reduxjs/toolkit": "^1.9.1", "debug": "^4.3.4", "react": "^18.2.0", diff --git a/samples/apps/copilot-chat-app/WebApp/src/components/chat/ChatInput.tsx b/samples/apps/copilot-chat-app/WebApp/src/components/chat/ChatInput.tsx index ac664cd729ab..04dc9df24996 100644 --- a/samples/apps/copilot-chat-app/WebApp/src/components/chat/ChatInput.tsx +++ b/samples/apps/copilot-chat-app/WebApp/src/components/chat/ChatInput.tsx @@ -8,32 +8,24 @@ import { Constants } from '../../Constants'; import { AlertType } from '../../libs/models/AlertType'; import { useAppDispatch } from '../../redux/app/hooks'; import { setAlert } from '../../redux/features/app/appSlice'; +import { TypingIndicatorRenderer } from './TypingIndicatorRenderer'; const log = debug(Constants.debug.root).extend('chat-input'); const useClasses = makeStyles({ root: { display: 'flex', - flexDirection: 'row', - justifyContent: 'center', - position: 'relative', - }, - claim: { - position: 'absolute', - top: '-150px', - width: '100%', + flexDirection: 'column', + ...shorthands.margin(0, '72px'), + alignContent: 'stretch', }, - claimContent: { - ...shorthands.margin(0, 'auto'), - backgroundColor: tokens.colorNeutralBackground4, - ...shorthands.padding(tokens.spacingVerticalS, tokens.spacingHorizontalM), - ...shorthands.borderRadius(tokens.borderRadiusMedium, tokens.borderRadiusMedium, 0, 0), + typingIndicator: { + height: '28px', }, content: { ...shorthands.gap(tokens.spacingHorizontalM), display: 'flex', flexDirection: 'row', - maxWidth: '900px', width: '100%', }, input: { @@ -50,11 +42,13 @@ const useClasses = makeStyles({ }); interface ChatInputProps { + // Hardcode to single user typing. For multi-users, it should be a list of ChatUser who are typing. + isTyping?: boolean; onSubmit: (value: string) => void; } export const ChatInput: React.FC = (props) => { - const { onSubmit } = props; + const { isTyping, onSubmit } = props; const classes = useClasses(); const dispatch = useAppDispatch(); const [value, setValue] = React.useState(''); @@ -80,6 +74,7 @@ export const ChatInput: React.FC = (props) => { return (
+
{isTyping ? : null}