Skip to content

Commit

Permalink
Fix ESLint and selectVoice
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Aug 22, 2019
1 parent 7aea86b commit 26e3e29
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 52 deletions.
168 changes: 157 additions & 11 deletions packages/bundle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"prop-types": "^15.7.2",
"sanitize-html": "^1.19.0",
"url-search-params-polyfill": "^5.0.0",
"web-speech-cognitive-services": "4.0.1-master.d9fc5d3",
"web-speech-cognitive-services": "4.0.1-master.2143983",
"whatwg-fetch": "^3.0.0"
},
"devDependencies": {
Expand Down
53 changes: 30 additions & 23 deletions packages/component/src/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { connect, Provider } from 'react-redux';
import { css } from 'glamor';
import PropTypes from 'prop-types';
import React, { useEffect, useMemo } from 'react';
import React, { useCallback, useEffect, useMemo } from 'react';

import {
clearSuggestedActions,
Expand Down Expand Up @@ -152,6 +152,7 @@ const Composer = ({
referenceGrammarID,
renderMarkdown,
scrollToEnd,
selectVoice,
sendBoxRef,
sendTimeout,
sendTyping,
Expand All @@ -163,18 +164,18 @@ const Composer = ({
username,
webSpeechPonyfillFactory
}) => {
const patchedGrammars = useMemo(() => grammars || []);
const patchedGrammars = useMemo(() => grammars || [], [grammars]);
const patchedSendTypingIndicator = useMemo(() => {
if (typeof sendTyping === 'undefined') {
return sendTypingIndicator;
} else {
// TODO: [P3] Take this deprecation code out when releasing on or after January 13 2020
console.warn(
'Web Chat: "sendTyping" has been renamed to "sendTypingIndicator". Please use "sendTypingIndicator" instead. This deprecation migration will be removed on or after January 13 2020.'
);

return sendTyping;
}

// TODO: [P3] Take this deprecation code out when releasing on or after January 13 2020
console.warn(
'Web Chat: "sendTyping" has been renamed to "sendTypingIndicator". Please use "sendTypingIndicator" instead. This deprecation migration will be removed on or after January 13 2020.'
);

return sendTyping;
}, [sendTyping, sendTypingIndicator]);

const patchedStyleOptions = useMemo(
Expand Down Expand Up @@ -209,9 +210,9 @@ const Composer = ({
dispatch
]);

const selectVoice = useCallback(
(selectVoice, language) => selectVoice || defaultSelectVoice.bind(null, { language })
);
const patchedSelectVoice = useCallback(selectVoice || defaultSelectVoice.bind(null, { language: locale }), [
selectVoice
]);

const focusSendBoxContext = useMemo(() => createFocusSendBoxContext({ sendBoxRef }), [sendBoxRef]);

Expand All @@ -221,7 +222,7 @@ const Composer = ({
]);

const hoistedDispatchers = useMemo(
() => mapMap(DISPATCHERS, dispatcher => (...args) => dispatch(dispatcher.apply(this, args))),
() => mapMap(DISPATCHERS, dispatcher => (...args) => dispatch(dispatcher(...args))),
[dispatch]
);

Expand Down Expand Up @@ -252,7 +253,7 @@ const Composer = ({
groupTimestamp,
renderMarkdown,
scrollToEnd,
selectVoice,
selectVoice: patchedSelectVoice,
sendBoxRef,
sendTimeout,
sendTypingIndicator: patchedSendTypingIndicator,
Expand All @@ -269,17 +270,17 @@ const Composer = ({
directLine,
disabled,
focusSendBoxContext,
grammars,
groupTimestamp,
hoistedDispatchers,
patchedGrammars,
patchedSelectVoice,
patchedSendTypingIndicator,
patchedStyleOptions,
patchedStyleSet,
renderMarkdown,
scrollToEnd,
selectVoice,
sendBoxRef,
sendTimeout,
sendTypingIndicator,
styleOptions,
styleSet,
userID,
username,
webSpeechPonyfill
Expand Down Expand Up @@ -336,8 +337,8 @@ export default ConnectedComposerWithStore;

Composer.defaultProps = {
activityRenderer: undefined,
adaptiveCardHostConfig: undefined,
attachmentRenderer: undefined,
botAvatarInitials: undefined,
cardActionMiddleware: undefined,
children: undefined,
disabled: false,
Expand All @@ -347,20 +348,22 @@ Composer.defaultProps = {
referenceGrammarID: '',
renderMarkdown: text => text,
selectVoice: undefined,
sendBoxRef: undefined,
sendTimeout: 20000,
sendTyping: undefined,
sendTypingIndicator: false,
store: undefined,
styleOptions: {},
styleSet: undefined,
userAvatarInitials: undefined,
userID: '',
username: '',
webSpeechPonyfillFactory: undefined
};

Composer.propTypes = {
activityRenderer: PropTypes.func,
adaptiveCardHostConfig: PropTypes.any,
attachmentRenderer: PropTypes.func,
botAvatarInitials: PropTypes.string,
cardActionMiddleware: PropTypes.func,
children: PropTypes.any,
directLine: PropTypes.shape({
Expand All @@ -385,11 +388,15 @@ Composer.propTypes = {
renderMarkdown: PropTypes.func,
scrollToEnd: PropTypes.func.isRequired,
selectVoice: PropTypes.func,
sendBoxRef: PropTypes.shape({
current: PropTypes.any
}),
sendTimeout: PropTypes.number,
sendTyping: PropTypes.bool,
sendTypingIndicator: PropTypes.bool,
store: PropTypes.any,
styleOptions: PropTypes.any,
styleSet: PropTypes.any,
userAvatarInitials: PropTypes.string,
userID: PropTypes.string,
username: PropTypes.string,
webSpeechPonyfillFactory: PropTypes.func
Expand Down
2 changes: 2 additions & 0 deletions packages/component/src/defaultSelectVoice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @jest-environment node
*/

/* global global */

import selectVoice from './defaultSelectVoice';

const VOICES = [
Expand Down
Loading

0 comments on commit 26e3e29

Please sign in to comment.