|
1 | 1 | import ReactDOM from 'react-dom/client'; |
2 | | - |
| 2 | +import { useState } from 'react'; |
3 | 3 | import { ReactiveBase, SearchBox, ReactiveList, ResultCard } from '@appbaseio/reactivesearch'; |
4 | 4 |
|
5 | 5 | import './index.css'; |
6 | 6 |
|
7 | | -const Main = () => ( |
8 | | - <ReactiveBase |
9 | | - app="movies-demo-app" |
10 | | - url="https://a03a1cb71321:75b6603d-9456-4a5a-af6b-a487b309eb61@appbase-demo-ansible-abxiydt-arc.searchbase.io" |
11 | | - > |
12 | | - <div className="row"> |
13 | | - <div className="col"> |
14 | | - <SearchBox |
15 | | - title="SearchBox" |
16 | | - dataField={['original_title', 'original_title.search']} |
17 | | - componentId="MoviesSensor" |
18 | | - showVoiceSearch |
19 | | - autosuggest={false} |
20 | | - /> |
21 | | - </div> |
| 7 | +const Main = () => { |
| 8 | + const [value, setValue] = useState(''); |
22 | 9 |
|
23 | | - <div className="col"> |
24 | | - <ReactiveList |
25 | | - componentId="SearchResult" |
26 | | - dataField="original_title" |
27 | | - size={10} |
28 | | - className="result-list-container" |
29 | | - pagination |
30 | | - react={{ |
31 | | - and: 'MoviesSensor', |
32 | | - }} |
33 | | - render={({ data }) => ( |
34 | | - <ReactiveList.ResultCardsWrapper> |
35 | | - {data.map((item) => ( |
36 | | - <ResultCard id={item._id} key={item._id}> |
37 | | - <ResultCard.Image src={item.poster_path} /> |
38 | | - <ResultCard.Title> |
39 | | - <div |
40 | | - className="book-title" |
| 10 | + return ( |
| 11 | + <ReactiveBase |
| 12 | + app="movies-demo-app" |
| 13 | + url="https://a03a1cb71321:75b6603d-9456-4a5a-af6b-a487b309eb61@appbase-demo-ansible-abxiydt-arc.searchbase.io" |
| 14 | + > |
| 15 | + <div className="row"> |
| 16 | + <div className="col"> |
| 17 | + <SearchBox |
| 18 | + title="SearchBox" |
| 19 | + dataField={['original_title', 'original_title.search']} |
| 20 | + componentId="MoviesSensor" |
| 21 | + showVoiceSearch |
| 22 | + showFocusShortcutsIcon={false} |
| 23 | + value={value} |
| 24 | + onChange={(value) => { |
| 25 | + setValue(value); |
| 26 | + }} |
| 27 | + render={({ |
| 28 | + loading, |
| 29 | + error, |
| 30 | + data, |
| 31 | + value, |
| 32 | + downshiftProps: { isOpen, getItemProps }, |
| 33 | + }) => { |
| 34 | + if (loading) { |
| 35 | + return <div>Fetching Suggestions.</div>; |
| 36 | + } |
| 37 | + if (error) { |
| 38 | + return ( |
| 39 | + <div> |
| 40 | + Something went wrong! Error details {JSON.stringify(error)} |
| 41 | + </div> |
| 42 | + ); |
| 43 | + } |
| 44 | + return isOpen && Boolean(value.length) ? ( |
| 45 | + <div className="pill-wrapper"> |
| 46 | + {data.map((suggestion, index) => ( |
| 47 | + <button |
| 48 | + className="pill-btn" |
| 49 | + key={suggestion.value} |
| 50 | + title={suggestion.value} |
| 51 | + {...getItemProps({ item: suggestion })} |
41 | 52 | dangerouslySetInnerHTML={{ |
42 | | - __html: item.original_title, |
| 53 | + __html: suggestion.value, |
43 | 54 | }} |
44 | | - /> |
45 | | - </ResultCard.Title> |
| 55 | + ></button> |
| 56 | + ))} |
| 57 | + </div> |
| 58 | + ) : null; |
| 59 | + }} |
| 60 | + /> |
| 61 | + <br /> |
| 62 | + <ReactiveList |
| 63 | + componentId="SearchResult" |
| 64 | + dataField="original_title" |
| 65 | + size={10} |
| 66 | + className="result-list-container" |
| 67 | + pagination |
| 68 | + react={{ |
| 69 | + and: 'MoviesSensor', |
| 70 | + }} |
| 71 | + render={({ data }) => ( |
| 72 | + <ReactiveList.ResultCardsWrapper> |
| 73 | + {data.map((item) => ( |
| 74 | + <ResultCard id={item._id} key={item._id}> |
| 75 | + <ResultCard.Image src={item.poster_path} /> |
| 76 | + <ResultCard.Title> |
| 77 | + <div |
| 78 | + className="book-title" |
| 79 | + dangerouslySetInnerHTML={{ |
| 80 | + __html: item.original_title, |
| 81 | + }} |
| 82 | + /> |
| 83 | + </ResultCard.Title> |
46 | 84 |
|
47 | | - <ResultCard.Description> |
48 | | - <div className="flex column justify-space-between"> |
49 | | - <div> |
50 | | - <div title={item.overview}> |
51 | | - <span className="authors-list"> |
52 | | - {item.overview} |
53 | | - </span> |
54 | | - </div> |
55 | | - <div className="ratings-list flex align-center"> |
56 | | - <span> |
57 | | - {item.genres.map((_) => ( |
58 | | - <span> ∙ {_}</span> |
59 | | - ))} |
60 | | - </span> |
| 85 | + <ResultCard.Description> |
| 86 | + <div className="flex column justify-space-between"> |
| 87 | + <div> |
| 88 | + <div title={item.overview}> |
| 89 | + <span className="authors-list"> |
| 90 | + {item.overview} |
| 91 | + </span> |
| 92 | + </div> |
| 93 | + <div className="ratings-list flex align-center"> |
| 94 | + <span> |
| 95 | + {item.genres.map((_) => ( |
| 96 | + <span> ∙ {_}</span> |
| 97 | + ))} |
| 98 | + </span> |
| 99 | + </div> |
61 | 100 | </div> |
62 | 101 | </div> |
63 | | - </div> |
64 | | - </ResultCard.Description> |
65 | | - </ResultCard> |
66 | | - ))} |
67 | | - </ReactiveList.ResultCardsWrapper> |
68 | | - )} |
69 | | - /> |
| 102 | + </ResultCard.Description> |
| 103 | + </ResultCard> |
| 104 | + ))} |
| 105 | + </ReactiveList.ResultCardsWrapper> |
| 106 | + )} |
| 107 | + /> |
| 108 | + </div> |
70 | 109 | </div> |
71 | | - </div> |
72 | | - </ReactiveBase> |
73 | | -); |
| 110 | + </ReactiveBase> |
| 111 | + ); |
| 112 | +}; |
74 | 113 | const root = ReactDOM.createRoot(document.getElementById('root')); |
75 | 114 | root.render(<Main />); |
0 commit comments