Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat(voiceSearch): add voice search widget #2316

Merged
merged 81 commits into from
Jun 4, 2019
Merged

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Apr 12, 2019

Summary

This adds a new widget, connector and component for voice search.

Usage

stories.add('default', () => (
  <WrapWithHits
    searchBox={false}
    hasPlayground={true}
    linkedStoryGroup="VoiceSearch"
  >
    <VoiceSearch searchAsYouSpeak={boolean} />
  </WrapWithHits>
)).add('fully customized', () => (
  <WrapWithHits
    searchBox={false}
    hasPlayground={true}
    linkedStoryGroup="VoiceSearch"
  >
    <VoiceSearch
      searchAsYouSpeak={searchAsYouSpeak}
      buttonComponent={ButtonComponent}
      StatusComponent={StatusComponent}
    />
  </WrapWithHits>
));

Checklist

  • component
  • connector (using connectSearchBox)
  • widget
  • tests
  • stories

@algobot
Copy link
Contributor

algobot commented Apr 12, 2019

Deploy preview for react-instantsearch ready!

Built with commit d0b843d

https://deploy-preview-2316--react-instantsearch.netlify.com

@eunjae-lee
Copy link
Contributor Author

This is a draft pull request to check if the implementation is okay for connectVoiceSearch and VoiceSearch.tsx before going further. It is not property typed. Here's what's done so far. Please let me know what you think.

VoiceSearch.tsx

This components receives props from connector like

  • isBrowserSupported
  • isListening
  • toggleListening
  • voiceListeningState
  • searchAsYouSpeak

When user clicks the button, it will execute toggleListening which triggers toggleListeneing of VoiceSearchHelper inside the connector. The function will start a recognition and according to the lifecycle, its state will change. And it will be delivered to the component via voiceListeneingState.

This component also receives these two props.

  • buttonComponent
  • statusComponent

It is to let user customise the UI like the way we provide templates in InstantSearch.js.

connectVoiceSearch

This is a tricky part. We have VoiceSearchHelper copy&pasted from InstantSearch.js. As we know, it handles SpeechRecognition api. To keep the current structure of widget, connector and component, the instance of VoiceSearchHelper should be inside the connector, so that the connector can deliver the states from the instance to the component.

To achieve this, connectVoiceSearch doesn't export createConnector(...) but a function wrapping it. So VoiceSearchHelper is instantiated inside the function.

For VoiceSearchHelper to notify its internal changes(query or state), two callbacks are being used. In the current draft, the callbacks are set in getProvidedProps which is invoked inside the constructor of the component. And when the state changes, it calls this.context.ais.widgetsManager.update(); to trigger re-render in order to deliver new voiceListeningState to the component. I'm not sure if this is the good way (or aligned in the existing convention).

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! I haven't tried it out yet, but have some code style comments

Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for the connector tests to review everything.

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just one small comment about file organisation

@Haroenv
Copy link
Contributor

Haroenv commented May 29, 2019

I can't see the custom button example

@eunjae-lee
Copy link
Contributor Author

I can't see the custom button example

Right. That's fixed at 9656c5a

@eunjae-lee eunjae-lee dismissed samouss’s stale review June 3, 2019 09:24

All the feedbacks are addressed.

@eunjae-lee eunjae-lee changed the title feat(voiceSearch): add voice search widget, connector and component feat(voiceSearch): add voice search widget and component Jun 3, 2019
@eunjae-lee eunjae-lee changed the title feat(voiceSearch): add voice search widget and component feat(voiceSearch): add voice search widget Jun 3, 2019
@samouss samouss merged commit 0e3b124 into master Jun 4, 2019
eunjae-lee pushed a commit that referenced this pull request Jun 4, 2019
### Bug Fixes

* **highlight:** allow array as "attribute" ([#2474](#2474)) ([9dc829a](9dc829a)), closes [#2461](#2461)
* **indexUtils:** allow index with dots in it ([#2350](#2350)) ([f91906f](f91906f))

### Features

* **voiceSearch:** add voice search widget ([#2316](#2316)) ([0e3b124](0e3b124))
samouss pushed a commit that referenced this pull request Jun 4, 2019
# [5.7.0](v5.6.0...v5.7.0) (2019-06-04)

### Bug Fixes

* **highlight:** allow array as "attribute" ([#2474](#2474)) ([9dc829a](9dc829a)), closes [#2461](#2461)
* **indexUtils:** allow index with dots in it ([#2350](#2350)) ([f91906f](f91906f))

### Features

* **voiceSearch:** add voice search widget ([#2316](#2316)) ([0e3b124](0e3b124))
@Haroenv Haroenv deleted the feat/voice-search branch November 20, 2019 17:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants