|
1 | 1 | import React, { Component } from 'react'; |
2 | | -import './App.css'; |
3 | | -// reactivesearch components |
4 | | -import { |
5 | | - ReactiveBase, |
6 | | - CategorySearch, |
7 | | - SingleRange, |
8 | | - ResultCard |
9 | | -} from '@appbaseio/reactivesearch'; |
10 | | -// For layouts, you can use a layout system of your choice |
11 | | -import { Flex, Box } from 'reflexbox'; |
| 2 | +import { ReactiveBase, CategorySearch, SingleRange, ResultCard } from '@appbaseio/reactivesearch'; |
12 | 3 |
|
13 | 4 | class App extends Component { |
14 | | - |
15 | | - // takes one hit response from query and returns it |
16 | | - // in the ResultCard format to render UI view. |
17 | | - onData({ _source: res }) { |
18 | | - const result = { |
19 | | - image: "https://www.enterprise.com/content/dam/global-vehicle-images/cars/FORD_FOCU_2012-1.png", |
20 | | - title: res.name, |
21 | | - desc: res.brand + " " + "★".repeat(res.rating), |
22 | | - url: "#" |
23 | | - }; |
24 | | - return result; |
25 | | - } |
26 | | - |
27 | | - render() { |
28 | | - return ( |
29 | | - <ReactiveBase |
30 | | - app="car-store" |
31 | | - credentials="cf7QByt5e:d2d60548-82a9-43cc-8b40-93cbbe75c34c"> |
32 | | - <Flex column={false} className="flex-wrapper"> |
33 | | - <Flex column w={[1, 1, 1/3]} wrap> |
34 | | - <Box m={2} pt={3}> |
35 | | - <CategorySearch |
36 | | - componentId="SearchSensor" |
37 | | - dataField="name" |
38 | | - categoryField="brand.raw" |
39 | | - placeholder="Search Cars" |
40 | | - /> |
41 | | - </Box> |
42 | | - <Box m={2} pt={2}> |
43 | | - <SingleRange |
44 | | - componentId="RatingsSensor" |
45 | | - dataField="rating" |
46 | | - title="RatingsFilter" |
47 | | - data={ |
48 | | - [{ start: 4, end: 5, label: "4 stars and up" }, |
49 | | - { start: 3, end: 5, label: "3 stars and up" }, |
50 | | - { start: 2, end: 5, label: "2 stars and up" }, |
51 | | - { start: 1, end: 5, label: "> 1 stars" }] |
52 | | - } |
53 | | - defaultSelected={"4 stars and up"} |
54 | | - /> |
55 | | - </Box> |
56 | | - </Flex> |
57 | | - <Flex w={[1, 1, 2/3]} wrap> |
58 | | - <ResultCard |
59 | | - innerClass={{ |
60 | | - "resultstats": "resultstats" |
61 | | - }} |
62 | | - className="results" |
63 | | - componentId="SearchResult" |
64 | | - dataField="name" |
65 | | - title="Results" |
66 | | - from={0} |
67 | | - size={6} |
68 | | - pagination |
69 | | - onData={this.onData} |
70 | | - sortOptions={[ |
71 | | - { |
72 | | - label: "Lowest Price First", |
73 | | - dataField: "price", |
74 | | - sortBy: "asc" |
75 | | - }, |
76 | | - { |
77 | | - label: "Highest Price First", |
78 | | - dataField: "price", |
79 | | - sortBy: "desc" |
80 | | - }, |
81 | | - { |
82 | | - label: "Most rated", |
83 | | - dataField: "rating", |
84 | | - sortBy: "desc" |
85 | | - } |
86 | | - ]} |
87 | | - react={{ |
88 | | - and: ["SearchSensor", "RatingsSensor"] |
89 | | - }} |
90 | | - /> |
91 | | - </Flex> |
92 | | - </Flex> |
93 | | - </ReactiveBase> |
94 | | - ); |
95 | | - } |
| 5 | + render() { |
| 6 | + return ( |
| 7 | + <ReactiveBase |
| 8 | + app="car-store" |
| 9 | + credentials="cf7QByt5e:d2d60548-82a9-43cc-8b40-93cbbe75c34c"> |
| 10 | + <div style={{ display: "flex", "flex-direction": "row" }}> |
| 11 | + <div style={{ display: "flex", "flex-direction": "column", "width": "40%" }}> |
| 12 | + <CategorySearch |
| 13 | + componentId="searchbox" |
| 14 | + dataField="name" |
| 15 | + categoryField="brand.raw" |
| 16 | + placeholder="Search for cars" |
| 17 | + style={{ |
| 18 | + padding: "5px", |
| 19 | + "margin-top": "10px" |
| 20 | + }} |
| 21 | + /> |
| 22 | + <SingleRange |
| 23 | + componentId="ratingsfilter" |
| 24 | + title="Filter by ratings" |
| 25 | + dataField="rating" |
| 26 | + data={[ |
| 27 | + {"start": "4", "end": "5", "label": "4 stars and up"}, |
| 28 | + {"start": "3", "end": "5", "label": "3 stars and up"}, |
| 29 | + {"start": "2", "end": "5", "label": "2 stars and up"}, |
| 30 | + {"start": "1", "end": "5", "label": "see all ratings"}, |
| 31 | + ]} |
| 32 | + defaultSelected="4 stars and up" |
| 33 | + style={{ |
| 34 | + padding: "5px", |
| 35 | + "margin-top": "10px" |
| 36 | + }} |
| 37 | + /> |
| 38 | + </div> |
| 39 | + <ResultCard |
| 40 | + componentId="result" |
| 41 | + title="Results" |
| 42 | + from={0} |
| 43 | + size={6} |
| 44 | + pagination={true} |
| 45 | + react={{ |
| 46 | + and: ["searchbox", "ratingsfilter"] |
| 47 | + }} |
| 48 | + onData={({_source: res}) => { |
| 49 | + return { |
| 50 | + image: "https://www.enterprise.com/content/dam/global-vehicle-images/cars/FORD_FOCU_2012-1.png", |
| 51 | + title: res.name, |
| 52 | + desc: res.brand + " " + "★".repeat(res.rating) |
| 53 | + } |
| 54 | + }} |
| 55 | + style={{ |
| 56 | + "width": "60%", |
| 57 | + "text-align": "center" |
| 58 | + }} |
| 59 | + /> |
| 60 | + </div> |
| 61 | + </ReactiveBase> |
| 62 | + ); |
| 63 | + } |
96 | 64 | } |
97 | 65 |
|
98 | 66 | export default App; |
0 commit comments