File size: 1,235 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
import { createClassNames } from '../core/utils';
import useAnswers from '../hooks/useAnswers';

const cx = createClassNames('Answers');

/* eslint-disable react/prop-types */
function DefaultAnswersComponent({ isLoading, hits }) {
  return (
    <div className={cx('', hits.length === 0 && '-empty')}>
      <div className={cx('header')}></div>
      {isLoading ? (
        <div className={cx('loader')}></div>
      ) : (
        <ul className={cx('list')}>
          {hits.map((hit, index) => (
            <li key={index} className={cx('item')}>
              {JSON.stringify(hit)}
            </li>
          ))}
        </ul>
      )}
    </div>
  );
}

export default function Answers({
  searchClient,
  queryLanguages,
  attributesForPrediction,
  nbHits = 1,
  renderDebounceTime,
  searchDebounceTime,
  answersComponent: AnswersComponent = DefaultAnswersComponent,
  ...extraParameters
}) {
  const { hits, isLoading } = useAnswers({
    searchClient,
    queryLanguages,
    attributesForPrediction,
    nbHits,
    renderDebounceTime,
    searchDebounceTime,
    ...extraParameters,
  });

  return <AnswersComponent hits={hits} isLoading={isLoading} />;
}
/* eslint-enable react/prop-types */