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

Commit 55e4191

Browse files
Eunjae LeeHaroenvshortcuts
authored
feat(answers): add EXPERIMENTAL_Answers widget (#2996)
* feat(answers): add widget [WIP] * make queryLanguages required * add extraParameters * Update packages/react-instantsearch-dom/src/widgets/Answers.js Co-authored-by: Haroen Viaene <hello@haroen.me> * set user agent in answers query * fix the parameters * bundle up effects as useAnswers * update the default component * expose useAnswers * spread extraParameters * add prefix to the useAnswers hook * do not show list on loading * debounce search calls * throw error when react version doesn't support hooks * error handling * Update packages/react-instantsearch-dom/src/widgets/Answers.js Co-authored-by: Clément Vannicatte <20689156+shortcuts@users.noreply.github.com> * add test cases * use fake client * Update packages/react-instantsearch-dom/src/widgets/__tests__/Answers.js Co-authored-by: Clément Vannicatte <20689156+shortcuts@users.noreply.github.com> * update types of debounce and debounceAsync * Update packages/react-instantsearch-dom/src/hooks/useAnswers.js Co-authored-by: Clément Vannicatte <20689156+shortcuts@users.noreply.github.com> * remove Boolean() function * fix type error * clean debounce functions * expose debounce time options * update test not to use waitFor * update bundlesize * throw error early if findAnswers doesn't exist * clean up the code * remove unnecessary catch * fix(types): fix type errors regarding SpeechRecognition (#3005) * fix(types): fix type errors regarding SpeechRecognition * Apply suggestions from code review Co-authored-by: Haroen Viaene <hello@haroen.me> Co-authored-by: Haroen Viaene <hello@haroen.me> * extract runAllMicroTasks to test/utils * change wait time * provide initial values in useAnswers * remove unnecessary parameter * remove the user agent workaround Co-authored-by: Haroen Viaene <hello@haroen.me> Co-authored-by: Clément Vannicatte <20689156+shortcuts@users.noreply.github.com>
1 parent 4f978e6 commit 55e4191

File tree

25 files changed

+676
-86
lines changed

25 files changed

+676
-86
lines changed

.codesandbox/ci.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"packages": ["packages/*"],
3+
"buildCommand": "lerna run build --scope react-* --ignore *-maps --ignore *-native",
34
"sandboxes": [
45
"github/algolia/create-instantsearch-app/tree/templates/react-instantsearch",
56
"github/algolia/doc-code-samples/tree/master/React InstantSearch/routing-basic"

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"website:build": "yarn build && yarn webpack --config website/webpack.config.js"
3333
},
3434
"devDependencies": {
35-
"@algolia/client-search": "4.0.0-beta.15",
35+
"@algolia/client-search": "4.8.2",
3636
"@babel/cli": "7.4.4",
3737
"@babel/core": "7.4.5",
3838
"@babel/plugin-proposal-class-properties": "7.4.4",
@@ -48,7 +48,7 @@
4848
"@storybook/addons": "5.0.11",
4949
"@storybook/react": "5.0.11",
5050
"@storybook/theming": "5.0.11",
51-
"@testing-library/react": "9.1.0",
51+
"@testing-library/react": "11.2.3",
5252
"@types/classnames": "^2.2.7",
5353
"@types/enzyme": "^3.1.15",
5454
"@types/enzyme-adapter-react-16": "^1.0.3",
@@ -72,7 +72,7 @@
7272
"@wdio/selenium-standalone-service": "5.16.10",
7373
"@wdio/spec-reporter": "5.16.11",
7474
"@wdio/static-server-service": "5.16.10",
75-
"algoliasearch": "4.0.0-beta.15",
75+
"algoliasearch": "4.8.2",
7676
"argos-cli": "0.1.3",
7777
"babel-eslint": "10.0.2",
7878
"babel-jest": "24.9.0",
@@ -127,7 +127,7 @@
127127
"rollup-plugin-replace": "2.2.0",
128128
"rollup-plugin-uglify": "6.0.3",
129129
"style-loader": "1.0.0",
130-
"typescript": "3.5.3",
130+
"typescript": "3.8.3",
131131
"webpack": "4.40.2",
132132
"webpack-cli": "3.3.7"
133133
},
@@ -150,7 +150,7 @@
150150
},
151151
{
152152
"path": "packages/react-instantsearch-dom/dist/umd/ReactInstantSearchDOM.min.js",
153-
"maxSize": "37.05 kB"
153+
"maxSize": "38.00 kB"
154154
},
155155
{
156156
"path": "packages/react-instantsearch-dom-maps/dist/umd/ReactInstantSearchDOMMaps.min.js",

packages/react-instantsearch-core/src/core/__tests__/createInstantSearchManager.derived.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import createInstantSearchManager from '../createInstantSearchManager';
2-
3-
const runAllMicroTasks = () => new Promise(setImmediate);
2+
import { runAllMicroTasks } from '../../../../../test/utils';
43

54
const createSearchClient = () => ({
65
search: jest.fn(requests =>

packages/react-instantsearch-core/src/core/__tests__/createInstantSearchManager.error.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import createInstantSearchManager from '../createInstantSearchManager';
2-
3-
const runAllMicroTasks = () => new Promise(setImmediate);
2+
import { runAllMicroTasks } from '../../../../../test/utils';
43

54
const createSearchClient = () => ({
65
search: jest.fn(),

packages/react-instantsearch-core/src/core/__tests__/createInstantSearchManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Enzyme, { mount } from 'enzyme';
44
import algoliasearch from 'algoliasearch/lite';
55
import { SearchResults } from 'algoliasearch-helper';
66
import createInstantSearchManager from '../createInstantSearchManager';
7+
import { runAllMicroTasks } from '../../../../../test/utils';
78
import {
89
InstantSearch,
910
Index,
@@ -15,7 +16,6 @@ Enzyme.configure({ adapter: new Adapter() });
1516

1617
jest.useFakeTimers();
1718

18-
const runAllMicroTasks = () => new Promise(setImmediate);
1919
const runOnlyNextMicroTask = () => Promise.resolve();
2020

2121
const createSearchClient = () => ({

packages/react-instantsearch-core/src/core/__tests__/createInstantSearchManager.result.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import createInstantSearchManager from '../createInstantSearchManager';
2-
3-
const runAllMicroTasks = () => new Promise(setImmediate);
2+
import { runAllMicroTasks } from '../../../../../test/utils';
43

54
const createSearchClient = () => ({
65
search: jest.fn(() =>

packages/react-instantsearch-core/src/core/context.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ export type InstantSearchContext = {
1313
mainTargetedIndex: string;
1414
};
1515

16-
export const {
17-
Consumer: InstantSearchConsumer,
18-
Provider: InstantSearchProvider,
19-
} = createContext<InstantSearchContext>({
16+
export const instantSearchContext = createContext<InstantSearchContext>({
2017
onInternalStateUpdate: () => undefined,
2118
createHrefForState: () => '#',
2219
onSearchForFacetValues: () => undefined,
@@ -27,6 +24,11 @@ export const {
2724
mainTargetedIndex: '',
2825
});
2926

27+
export const {
28+
Consumer: InstantSearchConsumer,
29+
Provider: InstantSearchProvider,
30+
} = instantSearchContext;
31+
3032
export type IndexContext =
3133
| {
3234
targetedIndex: string;

packages/react-instantsearch-core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// Core
22
export { default as createConnector } from './core/createConnector';
3+
export {
4+
instantSearchContext,
5+
InstantSearchConsumer,
6+
InstantSearchProvider,
7+
} from './core/context';
38

49
// Utils
510
export { HIGHLIGHT_TAGS } from './core/highlight';

packages/react-instantsearch-dom-maps/src/__tests__/GoogleMapsLoader.jsdom.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Enzyme, { shallow } from 'enzyme';
33
import Adapter from 'enzyme-adapter-react-16';
44
import injectScript from 'scriptjs';
55
import GoogleMapsLoader from '../GoogleMapsLoader';
6+
import { runAllMicroTasks } from '../../../../test/utils';
67

78
Enzyme.configure({ adapter: new Adapter() });
89

@@ -13,8 +14,6 @@ describe('GoogleMapsLoader', () => {
1314
apiKey: 'API_KEY',
1415
};
1516

16-
const runAllMicroTasks = () => new Promise(resolve => setImmediate(resolve));
17-
1817
it('expect to call Google Maps API', () => {
1918
const children = jest.fn(x => x);
2019

packages/react-instantsearch-dom/src/components/VoiceSearch.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import createVoiceSearchHelper, {
55
VoiceSearchHelper,
66
VoiceListeningState,
77
Status,
8+
SpeechRecognitionErrorCode,
89
} from '../lib/voiceSearchHelper';
910
const cx = createClassNames('VoiceSearch');
1011

0 commit comments

Comments
 (0)