@@ -33,6 +33,21 @@ import { StoreCart } from "@/components/ui/marketcomponents/stores/storecart";
33
33
import { MARKET } from "@/utils/constants" ;
34
34
import LiveLogsContext from "@/utils/contexts/LiveLogsContext" ;
35
35
36
+
37
+
38
+ import { VR_GALAXY_DATA , THE_BOOMIN_BOX_DATA , MACROCENTER_DATA } from "@/utils/constants" ;
39
+ import { useToast } from "@/components/ui/use-toast" ;
40
+
41
+
42
+ const badgesText = [
43
+ "Accessories" ,
44
+ "Gifts for devs" ,
45
+ "Popular shops" ,
46
+ "Best sellers" ,
47
+ "Newest" ,
48
+ "Top deals" ,
49
+ ] ;
50
+
36
51
export default function Marketplace ( ) {
37
52
const [ headerLabel , setHeaderLabel ] = useState < string > ( "" ) ;
38
53
const [ products , setProducts ] = useState < InventoryItem [ ] > ( [ ] ) ;
@@ -42,16 +57,17 @@ export default function Marketplace() {
42
57
const { isLoggedIn } = useContext ( LoginContext ) ;
43
58
const { logLDMetricSent } = useContext ( LiveLogsContext ) ;
44
59
60
+
61
+ const { toast } = useToast ( ) ;
62
+
45
63
{
46
64
/* Step 1 code block */
47
65
}
48
66
49
67
const LDClient = useLDClient ( ) ;
50
68
const { storeAttentionCallout } = useFlags ( ) ;
51
-
52
- {
53
- /* Step 1 code block */
54
- }
69
+ const releaseNewSearchEngine = useFlags ( ) [ "release-new-search-engine" ] ?. includes ( "new-search-engine" ) ;
70
+
55
71
56
72
const [ cart , setCart ] = useState < InventoryItem [ ] > ( [ ] ) ;
57
73
@@ -66,197 +82,28 @@ export default function Marketplace() {
66
82
logLDMetricSent ( "item-accessed" ) ;
67
83
} ;
68
84
69
- useEffect ( ( ) => {
70
- const data : InventoryItem [ ] = [
71
- {
72
- id : 1 ,
73
- vendor : "vrgalaxy" ,
74
- item : "VR Headset - Advanced Model" ,
75
- cost : "499.99" ,
76
- } ,
77
- {
78
- id : 2 ,
79
- vendor : "vrgalaxy" ,
80
- item : "Wireless VR Controllers (Pair)" ,
81
- cost : "119.99" ,
82
- } ,
83
- {
84
- id : 3 ,
85
- vendor : "vrgalaxy" ,
86
- item : "VR Treadmill for Immersive Movement" ,
87
- cost : "899.99" ,
88
- } ,
89
- {
90
- id : 4 ,
91
- vendor : "vrgalaxy" ,
92
- item : "Haptic Feedback Gloves" ,
93
- cost : "259.99" ,
94
- } ,
95
- {
96
- id : 5 ,
97
- vendor : "vrgalaxy" ,
98
- item : "Virtual Reality Game - Space Adventure" ,
99
- cost : "59.99" ,
100
- } ,
101
- {
102
- id : 6 ,
103
- vendor : "vrgalaxy" ,
104
- item : "VR Headset Cleaning Kit" ,
105
- cost : "29.99" ,
106
- } ,
107
- {
108
- id : 7 ,
109
- vendor : "vrgalaxy" ,
110
- item : "360° VR Camera" ,
111
- cost : "349.99" ,
112
- } ,
113
- {
114
- id : 8 ,
115
- vendor : "vrgalaxy" ,
116
- item : "Virtual Reality Development Software" ,
117
- cost : "199.99" ,
118
- } ,
119
- {
120
- id : 9 ,
121
- vendor : "vrgalaxy" ,
122
- item : "Adjustable VR Headset Stand" ,
123
- cost : "39.99" ,
124
- } ,
125
- {
126
- id : 10 ,
127
- vendor : "vrgalaxy" ,
128
- item : "Virtual Reality Experience Ticket - Underwater World" ,
129
- cost : "14.99" ,
130
- } ,
131
- {
132
- id : 11 ,
133
- vendor : "macrocenter" ,
134
- item : "High-Performance Graphics Card - 8GB" ,
135
- cost : "699.99" ,
136
- } ,
137
- {
138
- id : 12 ,
139
- vendor : "macrocenter" ,
140
- item : "Gaming Motherboard - RGB Lighting" ,
141
- cost : "259.99" ,
142
- } ,
143
- {
144
- id : 13 ,
145
- vendor : "macrocenter" ,
146
- item : "Solid State Drive (SSD) - 1TB" ,
147
- cost : "129.99" ,
148
- } ,
149
- {
150
- id : 14 ,
151
- vendor : "macrocenter" ,
152
- item : "DDR4 RAM - 16GB Kit (2x8GB)" ,
153
- cost : "89.99" ,
154
- } ,
155
- {
156
- id : 15 ,
157
- vendor : "macrocenter" ,
158
- item : "Modular Power Supply - 750W" ,
159
- cost : "119.99" ,
160
- } ,
161
- {
162
- id : 16 ,
163
- vendor : "macrocenter" ,
164
- item : "CPU Cooler - Liquid Cooling System" ,
165
- cost : "139.99" ,
166
- } ,
167
- {
168
- id : 17 ,
169
- vendor : "macrocenter" ,
170
- item : "Full-Tower PC Case - Tempered Glass" ,
171
- cost : "199.99" ,
172
- } ,
173
- {
174
- id : 18 ,
175
- vendor : "macrocenter" ,
176
- item : "Wireless Gaming Keyboard and Mouse Combo" ,
177
- cost : "99.99" ,
178
- } ,
179
- {
180
- id : 19 ,
181
- vendor : "macrocenter" ,
182
- item : "27-inch Gaming Monitor - 144Hz" ,
183
- cost : "329.99" ,
184
- } ,
185
- {
186
- id : 20 ,
187
- vendor : "macrocenter" ,
188
- item : "Internal Sound Card - 7.1 Surround" ,
189
- cost : "79.99" ,
190
- } ,
191
- {
192
- id : 21 ,
193
- vendor : "boominbox" ,
194
- item : "VR Headset - Advanced Model" ,
195
- cost : "499.99" ,
196
- } ,
197
- {
198
- id : 22 ,
199
- vendor : "boominbox" ,
200
- item : "Bluetooth Noise-Canceling Headphones" ,
201
- cost : "299.99" ,
202
- } ,
203
- {
204
- id : 23 ,
205
- vendor : "boominbox" ,
206
- item : "Wireless Earbuds - Waterproof Edition" ,
207
- cost : "159.99" ,
208
- } ,
209
- {
210
- id : 24 ,
211
- vendor : "boominbox" ,
212
- item : "High-Fidelity Turntable" ,
213
- cost : "349.99" ,
214
- } ,
215
- {
216
- id : 25 ,
217
- vendor : "boominbox" ,
218
- item : "Portable Bluetooth Speaker - Rugged Design" ,
219
- cost : "119.99" ,
220
- } ,
221
- {
222
- id : 26 ,
223
- vendor : "boominbox" ,
224
- item : "Studio Monitor Speakers (Pair)" ,
225
- cost : "499.99" ,
226
- } ,
227
- {
228
- id : 27 ,
229
- vendor : "boominbox" ,
230
- item : "Multi-Channel Home Theater System" ,
231
- cost : "999.99" ,
232
- } ,
233
- {
234
- id : 28 ,
235
- vendor : "boominbox" ,
236
- item : "Digital Audio Interface - Pro Series" ,
237
- cost : "229.99" ,
238
- } ,
239
- {
240
- id : 29 ,
241
- vendor : "boominbox" ,
242
- item : "Smart Home Sound System with Voice Control" ,
243
- cost : "399.99" ,
244
- } ,
245
- {
246
- id : 30 ,
247
- vendor : "boominbox" ,
248
- item : "Professional DJ Mixer" ,
249
- cost : "699.99" ,
250
- } ,
251
- ] ;
252
- setProducts ( data ) ;
253
- } , [ ] ) ;
254
85
255
86
useEffect ( ( ) => {
256
87
setHeaderLabel ( storeAttentionCallout ) ;
257
88
} , [ storeAttentionCallout ] ) ;
258
89
259
90
const handleOnSelect = ( item : InventoryItem ) => {
91
+ let openShoppingCart : HTMLElement = document ?. querySelector (
92
+ ".shopping-cart-trigger"
93
+ ) as HTMLElement ;
94
+ if ( openShoppingCart && releaseNewSearchEngine ) openShoppingCart . click ( ) ;
95
+
96
+ if ( releaseNewSearchEngine ) {
97
+ addToCart ( item ) ;
98
+ LDClient ?. track ( "search-engine-add-to-cart" , LDClient . getContext ( ) ) ;
99
+ toast ( {
100
+ title : `${ item . item } has been added to your cart!` ,
101
+ wrapperStyle : "bg-gradient-experimentation text-white !text-medium font-bold font-sohne" ,
102
+ } ) ;
103
+
104
+ return ;
105
+ }
106
+
260
107
if ( item . vendor === "vrgalaxy" ) {
261
108
setOpenVRGalaxy ( true ) ;
262
109
}
@@ -270,9 +117,14 @@ export default function Marketplace() {
270
117
271
118
const formatResult = ( item : InventoryItem ) => {
272
119
return (
273
- < >
274
- < span style = { { display : "block" , textAlign : "left" } } > { item . item } </ span >
275
- </ >
120
+ < div className = "flex justify-between gap-x-5 cursor-pointer items-center mr-4" >
121
+ < span className = "w-full truncate" > { item . item } </ span >
122
+ { releaseNewSearchEngine ? (
123
+ < Button className = "rounded-none bg-gradient-experimentation font-sohne hover:brightness-[120%] h-auto" >
124
+ Add To Cart
125
+ </ Button >
126
+ ) : null }
127
+ </ div >
276
128
) ;
277
129
} ;
278
130
@@ -352,8 +204,8 @@ export default function Marketplace() {
352
204
</ >
353
205
</ NavWrapper >
354
206
355
- < section className = { `flex h-full bg-ldblack pb-20 text-white flex-col font-roboto` } >
356
- < section className = "relative h-2/3 py-28 bg-gradient-experimentation-black grid items-center justify-center" >
207
+ < main className = { `flex h-full bg-ldblack pb-20 text-white flex-col font-roboto` } >
208
+ < header className = "relative h-2/3 py-28 bg-gradient-experimentation-black grid items-center justify-center" >
357
209
< img src = "elipse.png" className = "absolute right-0 top-0" />
358
210
< img src = "union.png" className = "absolute left-0 bottom-0" />
359
211
< div className = "flex flex-col text-center px-4 sm:mx-auto items-center " >
@@ -362,37 +214,39 @@ export default function Marketplace() {
362
214
</ h1 >
363
215
< div className = "w-full sm:w-3/4 lg:w-1/2" >
364
216
< ReactSearchAutocomplete
365
- items = { products }
217
+ items = { [ ... VR_GALAXY_DATA , ... THE_BOOMIN_BOX_DATA , ... MACROCENTER_DATA ] }
366
218
onSelect = { handleOnSelect }
367
219
autoFocus
368
220
formatResult = { formatResult }
369
- fuseOptions = { { keys : [ "item" ] } }
221
+ fuseOptions = { {
222
+ shouldSort : true ,
223
+ threshold : releaseNewSearchEngine ? 0.3 : 0.6 , // 0.3 more precise, 0.6 less
224
+ location : 0 ,
225
+ distance : 100 ,
226
+ minMatchCharLength : 1 ,
227
+ keys : [ "item" ] ,
228
+ } }
370
229
resultStringKeyName = "item"
371
230
placeholder = "Browse a Galaxy of Storefronts"
231
+ styling = { { } }
232
+ showClear = { true }
233
+ className = "z-10"
372
234
/>
373
235
</ div >
374
236
< div className = "mt-4 sm:mt-6 gap-x-2 gap-y-4 sm:gap-y-0 grid grid-cols-3 sm:flex sm:grid-cols-0 " >
375
- < Badge className = "text-lg border-2 bg-transparent border-gray-500 text-ldlightgray" >
376
- Accessories
377
- </ Badge >
378
- < Badge className = "text-lg border-2 bg-transparent border-gray-500 text-ldlightgray" >
379
- Gifts for devs
380
- </ Badge >
381
- < Badge className = "text-lg border-2 bg-transparent border-gray-500 text-ldlightgray" >
382
- Popular shops
383
- </ Badge >
384
- < Badge className = "text-lg border-2 bg-transparent border-gray-500 text-ldlightgray" >
385
- Best sellers
386
- </ Badge >
387
- < Badge className = "text-lg border-2 bg-transparent border-gray-500 text-ldlightgray" >
388
- Newest
389
- </ Badge >
390
- < Badge className = "text-lg border-2 bg-transparent border-gray-500 text-ldlightgray" >
391
- Top deals
392
- </ Badge >
237
+ { badgesText . map ( ( badgeText , index ) => {
238
+ return (
239
+ < Badge
240
+ className = "text-lg border-2 bg-transparent border-gray-500 text-ldlightgray justify-center"
241
+ key = { index }
242
+ >
243
+ { badgeText }
244
+ </ Badge >
245
+ ) ;
246
+ } ) }
393
247
</ div >
394
248
</ div >
395
- </ section >
249
+ </ header >
396
250
397
251
< section className = "mx-8 sm:mx-12 xl:mx-auto pt-14 flex flex-col gap-y-10 px-10" >
398
252
< section >
@@ -485,7 +339,7 @@ export default function Marketplace() {
485
339
</ div >
486
340
</ section >
487
341
</ section >
488
- </ section >
342
+ </ main >
489
343
</ motion . main >
490
344
)
491
345
</ AnimatePresence >
0 commit comments