Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(voiceSearch): add connector and widget #3601

Merged
merged 121 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
6aa7de0
WIP: add voice search
Mar 13, 2019
da35340
feat(voiceSearch): fix css
Mar 13, 2019
9472b70
feat(voiceSearch): expose errorCode to templaes
Mar 13, 2019
83c625f
feat(voiceSearch): fix confusing message on story
Mar 13, 2019
ef1f3e1
feat(voiceSearch): rename isStarted to isListening
Mar 14, 2019
75597c7
feat(voiceSearch): move WebSpeech-related code to a separate file und…
Mar 18, 2019
38a57de
feat(voiceSearch): fix bug
Mar 18, 2019
09c7f3d
feat(voiceSearch): move helper-related logic from component to connector
Mar 19, 2019
ea7d01b
feat(voiceSearch): rename status
Mar 19, 2019
d6f4989
feat(voiceSearch): change default button text
Mar 19, 2019
2ab63f9
feat(voiceSearch): not to pullute global scope
Mar 20, 2019
f863f30
feat(voiceSearch): disable button if on unsupported browser
Mar 20, 2019
8c92a5d
feat(voiceSearch): add option to hideOnUnsupportedBrowser
Mar 20, 2019
1a5110c
feat(voiceSearch): remove unnecessary constructor
Mar 20, 2019
8c2de80
feat(voiceSearch): remove ref and use event.currentTarget
Mar 20, 2019
dca6887
chore(voiceSearch): use typeof for undefined
Mar 20, 2019
b286d42
feat(voiceSearch): simplify render function
Mar 22, 2019
af4fd92
feat(voiceSearch): remove transcript template
Mar 26, 2019
a73ff12
feat(voiceSearch): searchAsYouSpeak: false
Mar 26, 2019
42ab379
fix(voiceSearch): display interimResults correctly even when not in s…
Mar 26, 2019
28a711c
chore(voiceSearch): remove hideOnUnsupportedBrowser
Mar 26, 2019
36192a3
chore(featVoice): merge statuses and add new one
Mar 26, 2019
fb478b6
fix(voiceSearch): fix isListening
Mar 26, 2019
b746d5b
feat(voiceSearch): add default status template
Mar 26, 2019
68c5fda
chore(voiceSearch): conditional button icon
Mar 27, 2019
7e3d3e4
test(voiceSearch): add tests
Mar 27, 2019
deba4fb
Merge branch 'develop' into poc/voice-search
Mar 28, 2019
7e96e06
Merge branch 'develop' into poc/voice-search
Mar 28, 2019
53adea5
chore(voiceSearch): change to TypeScript
Mar 29, 2019
39e7f64
chore(storybook): make searchOptions optional
Mar 29, 2019
b52b938
chore(voiceSearch): change to TypeScript
Mar 29, 2019
d87269c
chore(voiceSearch): update style for a test story
Mar 29, 2019
607d0c8
chore(voiceSearch): fix TS warning
Mar 29, 2019
3b10e95
chore(voiceSearch): remove unused comments
Mar 29, 2019
9a0566f
chore(voiceSeach): fix lint errors
Apr 1, 2019
1f21b5b
feat(voiceSearch): add isSupportedBrowser to templates
Apr 1, 2019
2756960
test(voiceSearch): add test for VoiceSearchHelper
Apr 2, 2019
9f27ba4
test(voiceSearch): remove unnecessary exclamation mark
Apr 2, 2019
0432889
chore(voiceSearch): function renamed for consistency
Apr 2, 2019
e5b3d00
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 2, 2019
1a62fef
Update src/components/VoiceSearch/VoiceSearch.tsx
francoischalifour Apr 2, 2019
e0eda85
chore(voiceSearch): use named parameter
Apr 2, 2019
4fc015c
chore(voiceSearch): rename function for consistency
Apr 2, 2019
7685a54
chore(voiceSearch): pass boolean variable instead of function returni…
Apr 2, 2019
6fc8962
chore(voiceSearch): remove propTypes + fix list warning
Apr 2, 2019
d32d063
test(voiceSearch): remove unnecessary story and add desc to the defau…
Apr 2, 2019
4af5873
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 4, 2019
fb55d59
type(voiceSearch): add type to SpeechRecognition
Apr 4, 2019
50d6d9b
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 4, 2019
7554114
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 4, 2019
a3a38c6
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 4, 2019
ceac4aa
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 4, 2019
0c0b797
Merge branches 'poc/voice-search' and 'poc/voice-search' of github.co…
Apr 4, 2019
c08d3c6
Merge branch 'develop' into poc/voice-search
Haroenv Apr 4, 2019
72ac723
type(voiceSearch): make Template generic
Apr 4, 2019
65e5972
Update src/connectors/voice-search/connectVoiceSearch.ts
francoischalifour Apr 4, 2019
1535a69
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 4, 2019
fcac2ee
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 4, 2019
4ac0ff7
Update src/connectors/voice-search/connectVoiceSearch.ts
francoischalifour Apr 4, 2019
8734a54
chore(voiceSearch): remove rootTagName
Apr 4, 2019
e4f036c
refactor(voiceSearch): make renderer simpler
Apr 4, 2019
16d3664
Merge branch 'poc/voice-search' of github.com:algolia/instantsearch.j…
Apr 4, 2019
58967d8
chore(voiceSearch): add styles for story
Apr 8, 2019
fbe87fa
Update src/components/VoiceSearch/__tests__/VoiceSearch-test.js
francoischalifour Apr 8, 2019
0b7b7f8
feat(voiceSearch): add connectVoiceSearch to connectors/index
Apr 8, 2019
e3f1e40
test(voiceSearch): remove unused test case
Apr 8, 2019
7d25a64
test(voiceSearch): more strict checking
Apr 8, 2019
dd996b5
test(voiceSearch): more strict checking
Apr 8, 2019
6d927f2
test(voiceSearch): rename
Apr 8, 2019
6574aaa
test(voiceSearch): remove snapshot matching and put actual object to …
Apr 8, 2019
ba42357
type(voiceSearch): better TS support + tests in TS
Apr 8, 2019
55e2b07
chore(voiceSearch): make searchAsYouSpeak required at component level
Apr 8, 2019
7367126
test(voiceSearch): clean up & split a test into many
Apr 8, 2019
151efb6
test(voiceSearch): add test for unmountFn
Apr 8, 2019
055254f
type(voiceSearch): add types to VoiceSearchHelper
Apr 8, 2019
3a3c333
fix(voiceSearch): default value of transcript is undefined, not an em…
Apr 8, 2019
c865000
fix(voiceSearch): provide searchAsYouSpeak directly to voiceSearchHelper
Apr 8, 2019
ad2ccd9
type(voiceSearch): make cssClasses and templates from VoiceSearchWidg…
Apr 8, 2019
8a697dc
fix(voiceSearch): null check
Apr 8, 2019
e5ac59e
chore(voiceSearch): change order of listeners
Apr 8, 2019
e9a7c50
type(voiceSearch): import widget directly from source to get proper d…
Apr 8, 2019
8da96c3
feat(voiceSearch): add getWidgetState, getWidgetSearchParameters for …
Apr 8, 2019
94f3a30
type(voiceSearch): rename class to avoid type error
Apr 9, 2019
c05430d
fix(voiceSearch): ignore toggleListening if it's not supported browser
Apr 9, 2019
f8add7b
chore(voiceSearch): rename isSupportedBrowser to isBrowserSupported
Apr 9, 2019
27e0260
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 9, 2019
6654eed
Update src/lib/voiceSearchHelper/index.ts
francoischalifour Apr 9, 2019
a932247
chore(voiceSearch): update css version to 7.3.0
Apr 9, 2019
6b68088
chore(voiceSearch): remove unused style from story
Apr 9, 2019
8b0d44e
type(voiceSearch): fix typing error
Apr 9, 2019
667ef01
type(voiceSearch): fix lint error
Apr 12, 2019
8f522b8
Update .storybook/preview-head.html
francoischalifour Apr 12, 2019
460fe5f
Merge branch 'develop' into poc/voice-search
Apr 15, 2019
088007b
Merge branch 'develop' into poc/voice-search
Apr 15, 2019
ee6e4e7
type(voiceSearch): fix types in test
Apr 15, 2019
2d6cdfa
type(voiceSearch): change type in order to store query properly
Apr 15, 2019
987e62a
type(voiceSearch): fix typing errors
Apr 15, 2019
16851b7
test(voiceSearch): update test
Apr 15, 2019
9601510
Merge branch 'develop' into poc/voice-search
eunjae-lee Apr 16, 2019
36df3ec
chore(voiceSearch): prettify svg
Apr 16, 2019
0975865
Merge branch 'poc/voice-search' of github.com:algolia/instantsearch.j…
Apr 16, 2019
fe5be97
fix(voiceSearch): add extra description on title on unsupported browser
Apr 16, 2019
28b3f2b
chore(voiceSearch): simplify svg
Apr 16, 2019
bf69113
test(voiceSearch): modify story with custom style
Apr 16, 2019
588908b
chore(voiceSearch): replace if-else with ternary operator
Apr 17, 2019
4d6a6dd
chore(voiceSearch): replace ternary operator with if
Apr 17, 2019
d361279
Merge branch 'develop' into poc/voice-search
Apr 17, 2019
63fcde1
chore(voiceSearch): increase bundlesize limit
Apr 18, 2019
e265877
Merge branch 'develop' into poc/voice-search
eunjae-lee Apr 18, 2019
a27c948
Revert "chore(voiceSearch): increase bundlesize limit"
Apr 18, 2019
fe0423a
Update src/connectors/voice-search/__tests__/connectVoiceSearch-test.js
francoischalifour Apr 23, 2019
79a8b10
Update src/connectors/voice-search/__tests__/connectVoiceSearch-test.js
francoischalifour Apr 23, 2019
7fc2bbf
Update src/connectors/voice-search/__tests__/connectVoiceSearch-test.js
francoischalifour Apr 23, 2019
6701b25
test(voiceSearch): improve tests
Apr 23, 2019
f673637
Merge branch 'poc/voice-search' of github.com:algolia/instantsearch.j…
Apr 23, 2019
93e7cdf
test(voiceSearch): improve tests
Apr 23, 2019
4d4f9d1
Merge branch 'develop' into poc/voice-search
eunjae-lee Apr 23, 2019
0e69200
chore(voiceSearch): clean up imports
Apr 23, 2019
0787b7e
Merge branch 'develop' into poc/voice-search
eunjae-lee Apr 24, 2019
d75cecb
type(voiceSearch): fix lint errors
Apr 24, 2019
71a17e3
Merge branch 'develop' into poc/voice-search
eunjae-lee Apr 29, 2019
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
2 changes: 1 addition & 1 deletion .storybook/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const withHits = (
instantsearch: any;
search: any;
}) => void,
searchOptions: any
searchOptions?: any
) => () => {
const {
appId = 'latency',
Expand Down
80 changes: 80 additions & 0 deletions src/components/VoiceSearch/VoiceSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'preact-compat';
import Template from '../Template/Template';

import {
VoiceSearchCSSClasses,
VoiceSearchTemplates,
} from '../../widgets/voice-search/voice-search';

import {
VoiceListeningState,
ToggleListening,
} from '../../lib/voiceSearchHelper';

export type VoiceSearchProps = {
cssClasses: VoiceSearchCSSClasses;
isBrowserSupported: boolean;
isListening: boolean;
toggleListening: ToggleListening;
voiceListeningState: VoiceListeningState;
templates: VoiceSearchTemplates;
};

const VoiceSearch = ({
cssClasses,
isBrowserSupported,
isListening,
toggleListening,
voiceListeningState,
templates,
}: VoiceSearchProps): React.ReactNode => {
const handleClick = (event: React.MouseEvent<HTMLElement>): void => {
event.currentTarget.blur();
toggleListening();
};

const { status, transcript, isSpeechFinal, errorCode } = voiceListeningState;
return (
<div className={cssClasses.root}>
<Template
templateKey="buttonText"
rootTagName="button"
rootProps={{
className: cssClasses.button,
type: 'button',
title: `Search by voice${
isBrowserSupported ? '' : ' (not supported on this browser)'
}`,
onClick: handleClick,
disabled: !isBrowserSupported,
}}
data={{
status,
errorCode,
isListening,
transcript,
isSpeechFinal,
isBrowserSupported,
}}
templates={templates}
/>
<Template
templateKey="status"
rootProps={{
className: cssClasses.status,
}}
data={{
status,
errorCode,
isListening,
transcript,
isSpeechFinal,
isBrowserSupported,
}}
templates={templates}
/>
</div>
);
};

export default VoiceSearch;
102 changes: 102 additions & 0 deletions src/components/VoiceSearch/__tests__/VoiceSearch-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React from 'react';
import { mount } from 'enzyme';
import VoiceSearch, { VoiceSearchProps } from '../VoiceSearch';

const defaultProps: VoiceSearchProps = {
cssClasses: {
root: 'root',
button: 'button',
status: 'status',
},
isBrowserSupported: true,
isListening: false,
toggleListening: () => {},
voiceListeningState: {
status: 'initial',
},
templates: {
buttonText: 'button',
status: 'status',
},
};

describe('VoiceSearch', () => {
describe('button', () => {
it('call toggleListening when button is clicked', () => {
const props = {
...defaultProps,
toggleListening: jest.fn(),
};
const wrapper = mount(<VoiceSearch {...props} />);
wrapper.find('button').simulate('click');
expect(props.toggleListening).toHaveBeenCalledTimes(1);
});
});

describe('Rendering', () => {
it('with default props', () => {
expect(mount(<VoiceSearch {...defaultProps} />)).toMatchSnapshot();
});

it('button disabled in unsupported browser', () => {
const props = {
...defaultProps,
isBrowserSupported: false,
};
const wrapper = mount(<VoiceSearch {...props} />);
expect(wrapper.find('button').props().disabled).toBe(true);
});

it('with custom template for buttonText (1)', () => {
const props = {
...defaultProps,
isListening: true,
templates: {
buttonText: ({ isListening }) => (isListening ? 'Stop' : 'Start'),
status: ``,
},
};
const wrapper = mount(<VoiceSearch {...props} />);
expect(wrapper.find('button').text()).toBe('Stop');
});

it('with custom template for buttonText (2)', () => {
const props = {
...defaultProps,
isListening: false,
templates: {
buttonText: ({ isListening }) => (isListening ? 'Stop' : 'Start'),
status: ``,
},
};
const wrapper = mount(<VoiceSearch {...props} />);
expect(wrapper.find('button').text()).toBe('Start');
});

it('with custom template for status', () => {
const props = {
...defaultProps,
isListening: true,
voiceListeningState: {
status: 'recognizing',
transcript: 'Hello',
isSpeechFinal: false,
errorCode: undefined,
},
templates: {
buttonText: ``,
status: `
<p>status: {{status}}</p>
<p>errorCode: {{errorCode}}</p>
<p>isListening: {{isListening}}</p>
<p>transcript: {{transcript}}</p>
<p>isSpeechFinal: {{isSpeechFinal}}</p>
<p>isBrowserSupported: {{isBrowserSupported}}</p>
`,
},
};
const wrapper = mount(<VoiceSearch {...props} />);
expect(wrapper.find('.status')).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`VoiceSearch Rendering with custom template for status 1`] = `
<div
className="status"
dangerouslySetInnerHTML={
Object {
"__html": "<p>status: recognizing</p> <p>errorCode: </p> <p>isListening: true</p> <p>transcript: Hello</p> <p>isSpeechFinal: false</p> <p>isBrowserSupported: true</p>",
}
}
/>
`;

exports[`VoiceSearch Rendering with default props 1`] = `
<div
className="root"
>
<button
className="button"
dangerouslySetInnerHTML={
Object {
"__html": "button",
}
}
disabled={false}
onClick={[Function]}
title="Search by voice"
type="button"
/>
<div
className="status"
dangerouslySetInnerHTML={
Object {
"__html": "status",
}
}
/>
</div>
`;
3 changes: 3 additions & 0 deletions src/connectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ export {
default as connectAutocomplete,
} from './autocomplete/connectAutocomplete';
export { default as connectQueryRules } from './query-rules/connectQueryRules';
export {
default as connectVoiceSearch,
} from './voice-search/connectVoiceSearch';
Loading