-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.tsx
235 lines (231 loc) · 7.1 KB
/
index.tsx
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import {
AtomicBreadbox,
AtomicColorFacet,
AtomicDidYouMean,
AtomicFacet,
AtomicFacetManager,
AtomicLayoutSection,
AtomicLoadMoreResults,
AtomicNoResults,
AtomicNumericFacet,
AtomicNumericRange,
AtomicQueryError,
AtomicQuerySummary,
AtomicRatingFacet,
AtomicRatingRangeFacet,
AtomicRefineToggle,
AtomicSearchBox,
AtomicSearchInterface,
AtomicSearchLayout,
AtomicSortDropdown,
AtomicSortExpression,
AtomicTimeframe,
AtomicTimeframeFacet,
buildSearchEngine,
AtomicFormatCurrency,
AtomicResultBadge,
AtomicResultFieldsList,
AtomicResultImage,
AtomicResultDate,
AtomicResultLink,
AtomicResultList,
AtomicResultMultiValueText,
AtomicResultNumber,
AtomicResultPrintableUri,
AtomicResultRating,
AtomicResultSectionBadges,
AtomicResultSectionBottomMetadata,
AtomicResultSectionEmphasized,
AtomicResultSectionExcerpt,
AtomicResultSectionTitle,
AtomicResultSectionTitleMetadata,
AtomicResultSectionVisual,
AtomicResultText,
AtomicText,
Result,
getOrganizationEndpoints,
} from '@coveo/atomic-react';
import type {NextPage} from 'next';
import dynamic from 'next/dynamic';
import {useMemo} from 'react';
const SearchPage: NextPage = () => {
const engine = useMemo(
() =>
buildSearchEngine({
configuration: {
accessToken: 'xxc23ce82a-3733-496e-b37e-9736168c4fd9',
organizationId: 'electronicscoveodemocomo0n2fu8v',
organizationEndpoints: getOrganizationEndpoints(
'electronicscoveodemocomo0n2fu8v'
),
search: {
pipeline: 'UI_KIT_E2E',
searchHub: 'UI_KIT_E2E',
},
},
}),
[]
);
return (
<AtomicSearchInterface
engine={engine}
fieldsToInclude={[
'cat_platform',
'cat_condition',
'cat_categories',
'cat_review_count',
'cat_color',
]}
>
<AtomicSearchLayout>
<AtomicLayoutSection section="search">
<AtomicSearchBox />
</AtomicLayoutSection>
<AtomicLayoutSection section="facets">
<AtomicFacetManager>
<AtomicFacet field="source" label="Source" />
<AtomicFacet field="objecttype" label="Type" />
<AtomicNumericFacet
field="cat_review_count"
label="Amount of reviews"
displayValuesAs="link"
>
<AtomicNumericRange start={0} end={150} label="Few" />
<AtomicNumericRange
start={150}
end={650}
label="A moderate amount"
/>
<AtomicNumericRange start={650} end={9999999999} label="A lot" />
</AtomicNumericFacet>
<AtomicColorFacet
field="cat_color"
label="Color"
numberOfValues={6}
sortCriteria="occurrences"
/>
<AtomicNumericFacet
field="ec_price"
label="Cost"
withInput="integer"
>
<AtomicFormatCurrency currency="USD" />
</AtomicNumericFacet>
<AtomicTimeframeFacet withDatePicker label="Listed within">
<AtomicTimeframe unit="hour" />
<AtomicTimeframe unit="day" />
<AtomicTimeframe unit="week" />
<AtomicTimeframe unit="month" />
<AtomicTimeframe unit="quarter" />
<AtomicTimeframe unit="year" />
<AtomicTimeframe unit="year" amount={10} period="next" />
</AtomicTimeframeFacet>
<AtomicRatingFacet
field="ec_rating"
label="Rating"
numberOfIntervals={5}
/>
<AtomicRatingRangeFacet
field="ec_rating"
label="Rating Range"
numberOfIntervals={5}
facetId="ec_rating_range"
/>
</AtomicFacetManager>
</AtomicLayoutSection>
<AtomicLayoutSection section="main">
<AtomicLayoutSection section="status">
<AtomicBreadbox />
<AtomicQuerySummary />
<AtomicRefineToggle />
<AtomicSortDropdown>
<AtomicSortExpression label="relevance" expression="relevancy" />
<AtomicSortExpression
label="Price (low to high)"
expression="ec_price ascending"
/>
<AtomicSortExpression
label="Price (high to low)"
expression="ec_price descending"
/>
</AtomicSortDropdown>
<AtomicDidYouMean />
</AtomicLayoutSection>
<AtomicLayoutSection section="results">
<AtomicResultList
display="list"
imageSize="large"
template={MyTemplate}
/>
<AtomicQueryError />
<AtomicNoResults />
</AtomicLayoutSection>
<AtomicLayoutSection section="pagination">
<AtomicLoadMoreResults />
</AtomicLayoutSection>
</AtomicLayoutSection>
</AtomicSearchLayout>
</AtomicSearchInterface>
);
};
function MyTemplate(result: Result) {
return (
<>
<AtomicResultSectionBadges>
<AtomicResultBadge field="ec_brand" />
</AtomicResultSectionBadges>
<AtomicResultSectionVisual>
<AtomicResultImage field="ec_images" />
</AtomicResultSectionVisual>
<AtomicResultSectionTitle>
<AtomicResultLink />
</AtomicResultSectionTitle>
<AtomicResultSectionTitleMetadata>
<AtomicResultRating field="ec_rating" />
<AtomicResultPrintableUri maxNumberOfParts={3} />
</AtomicResultSectionTitleMetadata>
<AtomicResultSectionEmphasized>
<AtomicResultNumber field="ec_price">
<AtomicFormatCurrency currency="USD" />
</AtomicResultNumber>
</AtomicResultSectionEmphasized>
<AtomicResultSectionExcerpt>
<AtomicResultText field="ec_shortdesc" />
</AtomicResultSectionExcerpt>
<AtomicResultSectionBottomMetadata>
<AtomicResultFieldsList>
<>
<AtomicResultDate format="ddd MMM D YYYY" />
{result.raw.cat_platform && (
<>
<span className="field-label">
<AtomicText value="Platform" />
</span>
<AtomicResultText field="cat_platform" />
</>
)}
{result.raw.cat_condition && (
<>
<span className="field-label">
<AtomicText value="Condition" />
</span>
<AtomicResultText field="cat_condition" />
</>
)}
{result.raw.cat_categories && (
<>
<span className="field-label">
<AtomicText value="Tags" />
</span>
<AtomicResultMultiValueText field="cat_categories" />
</>
)}
</>
</AtomicResultFieldsList>
</AtomicResultSectionBottomMetadata>
</>
);
}
export default dynamic(() => Promise.resolve(SearchPage), {
ssr: false,
});