1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
2
import { Button } from "@/components/ui/button" ;
3
3
import { Input } from "@/components/ui/input" ;
4
- import { FeaturedPlace , Place } from "@/types/places" ;
4
+ import { Place } from "@/types/places" ;
5
5
import "mapbox-gl/dist/mapbox-gl.css" ;
6
6
import Map , { MapRef , PointLike , Source } from "react-map-gl" ;
7
7
import Layer from "react-map-gl/dist/esm/components/layer" ;
@@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
27
27
28
28
const [ responsePlaces , responseTopDestinations ] = await Promise . all ( [
29
29
api < responsePlaces > ( `places?search=${ keyword ?? "" } ` ) ,
30
- api < { data : Array < FeaturedPlace > } > ( "/places/featured" ) ,
30
+ api < responsePlaces > ( "/places/featured" ) ,
31
31
] ) ;
32
32
33
33
return {
@@ -38,7 +38,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
38
38
}
39
39
40
40
export function PlacesIndexRoute ( ) {
41
- const { places, keyword } = useLoaderData ( ) as Awaited <
41
+ const { places, keyword, topDestinations } = useLoaderData ( ) as Awaited <
42
42
ReturnType < typeof loader >
43
43
> ;
44
44
@@ -150,7 +150,11 @@ export function PlacesIndexRoute() {
150
150
< aside className = "w-[720px] h-screen flex flex-col" >
151
151
< PlacesSidebarHeader />
152
152
< div className = "p-6 h-[85%]" >
153
- < PlaceDetailPlaceholder places = { places } keyword = { keyword } />
153
+ < PlaceDetailPlaceholder
154
+ places = { places }
155
+ keyword = { keyword }
156
+ topDestinations = { topDestinations }
157
+ />
154
158
</ div >
155
159
</ aside >
156
160
@@ -214,46 +218,60 @@ function PlacesSidebarHeader() {
214
218
function PlaceDetailPlaceholder ( {
215
219
places,
216
220
keyword,
221
+ topDestinations,
217
222
} : {
218
223
places : Place [ ] ;
219
224
keyword : string ;
225
+ topDestinations : Place [ ] ;
220
226
} ) {
227
+ const placeList = keyword !== "" ? places : topDestinations ;
228
+
221
229
return (
222
230
< div className = "h-[100%]" >
223
- < p className = "font-medium text-xl mb-6" > Show result of "{ keyword } "</ p >
231
+ < p className = "font-medium text-xl mb-6" >
232
+ { keyword !== "" ? `Show result of "${ keyword } "` : "Top destinations:" }
233
+ </ p >
224
234
225
235
< ScrollArea className = "h-[100%]" >
226
- { places . map ( ( place , index ) => (
236
+ { placeList . map ( ( place , index ) => (
227
237
< div
228
238
className = "flex flex-row gap-4 mb-4 min-h-[145px] w-full"
229
239
key = { index }
230
240
>
231
- < img
232
- className = "object-cover rounded-lg w-[198px] h-[145px]"
233
- src = { place . imageUrl }
234
- alt = { place . title }
235
- />
241
+ < Link to = { `/places/${ place . slug } ` } >
242
+ < img
243
+ className = "object-cover rounded-lg w-[198px] h-[145px]"
244
+ src = { place . imageUrl }
245
+ alt = { place . title }
246
+ />
247
+ </ Link >
236
248
237
249
< div className = "flex flex-col gap-2 flex-1 overflow-hidden" >
238
- < p className = "text-xl font-bold" > { place . title } </ p >
250
+ < Link
251
+ to = { `/places/${ place . slug } ` }
252
+ className = "text-xl font-bold hover:underline"
253
+ >
254
+ { place . title }
255
+ </ Link >
239
256
240
257
< div className = "flex flex-row gap-4 " >
241
258
{ place . categories . map ( ( category , index ) => (
242
- < div
259
+ < Link
260
+ to = { `/places?q=${ category . name } ` }
243
261
key = { index }
244
- className = "px-[10px] py-[5px] bg-blue-200 rounded-3xl"
262
+ className = "px-[10px] py-[5px] bg-blue-200 rounded-3xl hover:bg-blue-300 "
245
263
>
246
264
< p className = "font-bold text-xs text-blue-600" >
247
265
{ category . name }
248
266
</ p >
249
- </ div >
267
+ </ Link >
250
268
) ) }
251
269
</ div >
252
270
253
- < p className = "text-sm font-medium text-gray-500 truncate text-ellipsis" >
271
+ < p className = "text-sm font-medium text-gray-500 truncate text-ellipsis max-w-[390px] " >
254
272
{ place . description }
255
273
</ p >
256
- < p className = "text-sm font-medium text-gray-500 truncate text-ellipsis" >
274
+ < p className = "text-sm font-medium text-gray-500 truncate text-ellipsis max-w-[390px] " >
257
275
{ place . address }
258
276
</ p >
259
277
</ div >
0 commit comments