Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim authored Feb 14, 2023
1 parent 6955e6d commit 3dca497
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 70 deletions.
46 changes: 0 additions & 46 deletions __tests__/html/useTextBoxSubmit.true.html

This file was deleted.

3 changes: 0 additions & 3 deletions __tests__/html/useTextBoxSubmit.true.js

This file was deleted.

16 changes: 3 additions & 13 deletions packages/component/src/BasicSendBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React, { FC } from 'react';

import DictationInterims from './SendBox/DictationInterims';
import MicrophoneButton from './SendBox/MicrophoneButton';
import SendBoxComposer from './providers/internal/SendBox/SendBoxComposer';
import SendButton from './SendBox/SendButton';
import SuggestedActions from './SendBox/SuggestedActions';
import TextBox from './SendBox/TextBox';
Expand Down Expand Up @@ -53,7 +52,7 @@ type BasicSendBoxProps = {
className?: string;
};

const BasicSendBoxCore: FC<BasicSendBoxProps> = ({ className }) => {
const BasicSendBox: FC<BasicSendBoxProps> = ({ className }) => {
const [{ hideUploadButton, sendBoxButtonAlignment }] = useStyleOptions();
const [{ sendBox: sendBoxStyleSet }] = useStyleSet();
const [{ SpeechRecognition = undefined } = {}] = useWebSpeechPonyfill();
Expand Down Expand Up @@ -98,23 +97,14 @@ const BasicSendBoxCore: FC<BasicSendBoxProps> = ({ className }) => {
);
};

BasicSendBoxCore.defaultProps = {
BasicSendBox.defaultProps = {
className: ''
};

BasicSendBoxCore.propTypes = {
BasicSendBox.propTypes = {
className: PropTypes.string
};

const BasicSendBox: FC<BasicSendBoxProps> = (props: BasicSendBoxProps) => (
<SendBoxComposer>
<BasicSendBoxCore {...props} />
</SendBoxComposer>
);

BasicSendBox.defaultProps = BasicSendBoxCore.defaultProps;
BasicSendBox.propTypes = BasicSendBoxCore.propTypes;

export default BasicSendBox;

export { useSendBoxSpeechInterimsVisible };
8 changes: 6 additions & 2 deletions packages/component/src/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Dictation from './Dictation';
import downscaleImageToDataURL from './Utils/downscaleImageToDataURL';
import ErrorBox from './ErrorBox';
import mapMap from './Utils/mapMap';
import SendBoxComposer from './providers/internal/SendBox/SendBoxComposer';
import UITracker from './hooks/internal/UITracker';
import WebChatUIContext from './hooks/internal/WebChatUIContext';

Expand Down Expand Up @@ -227,8 +228,11 @@ const ComposerCore: FC<ComposerCoreProps> = ({
return (
<SayComposer ponyfill={webSpeechPonyfill}>
<WebChatUIContext.Provider value={context}>
{children}
<Dictation onError={dictationOnError} />
{/* When <SendBoxComposer> is finalized, it will be using an independent instance that lives inside <BasicSendBox>. */}
<SendBoxComposer>
{children}
<Dictation onError={dictationOnError} />
</SendBoxComposer>
</WebChatUIContext.Provider>
</SayComposer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ const TIME_TO_RESET_ERROR_MESSAGE = 50;

// This component is marked as internal because it is not fully implemented and is not ready to be consumed publicly.
// When it is done, it should provide and replace all the functionalities we did in Redux, including but not limited to:
// - Speech interims
// - Maintain text box value

// - Speech interims
// - Maintain text box value
// - Multiple <SendBoxComposer> in a single Web Chat instance
// - Web devs should be able to put an individual send box instance into an activity
// - The send box instance in the activity, should be separated from the bottommost send box
// - The valued typed inside the activity, should be separated from the value typed into the bottommost send box

// In the old days, we use Redux to keep the send box state.
// However, when web devs put 2 send box on their page, it makes things complex because both send boxes will interact with each other.
Expand Down Expand Up @@ -88,8 +93,8 @@ const SendBoxComposer = ({ children }: PropsWithChildren<{}>) => {

const submit = useCallback<ContextType['submit']>(
({ setFocus } = {}) => {
(setFocus === 'sendBox' || setFocus === 'sendBoxWithoutKeyboard') &&
focusRef.current?.(setFocus === 'sendBox' ? 'sendBox' : 'sendBoxWithoutKeyboard');
(setFocus === 'main' || setFocus === 'sendBox' || setFocus === 'sendBoxWithoutKeyboard') &&
focusRef.current?.(setFocus === 'main' || setFocus === 'sendBox' ? setFocus : 'sendBoxWithoutKeyboard');

const { current: submitError } = submitErrorRef;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type ContextType = {
submit: (options?: { setFocus?: 'sendBox' | 'sendBoxWithoutKeyboard' }) => void;
submit: (options?: { setFocus?: 'main' | 'sendBox' | 'sendBoxWithoutKeyboard' }) => void;
submitErrorMessageIdState: readonly [string];
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useSendBoxContext from './private/useContext';

type SubmitOptions = {
setFocus?: 'sendBox' | 'sendBoxWithoutKeyboard';
setFocus?: 'main' | 'sendBox' | 'sendBoxWithoutKeyboard';
};

/**
Expand Down

0 comments on commit 3dca497

Please sign in to comment.