Skip to content

Commit 1ec5d39

Browse files
authored
Merge pull request #30 from nusaventure/features/improve-search-places
Improve search places.
2 parents 33b3b81 + 16d33c3 commit 1ec5d39

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

Diff for: bun.lockb

0 Bytes
Binary file not shown.

Diff for: src/routes/places/index.tsx

+35-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { Button } from "@/components/ui/button";
33
import { Input } from "@/components/ui/input";
4-
import { FeaturedPlace, Place } from "@/types/places";
4+
import { Place } from "@/types/places";
55
import "mapbox-gl/dist/mapbox-gl.css";
66
import Map, { MapRef, PointLike, Source } from "react-map-gl";
77
import Layer from "react-map-gl/dist/esm/components/layer";
@@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
2727

2828
const [responsePlaces, responseTopDestinations] = await Promise.all([
2929
api<responsePlaces>(`places?search=${keyword ?? ""}`),
30-
api<{ data: Array<FeaturedPlace> }>("/places/featured"),
30+
api<responsePlaces>("/places/featured"),
3131
]);
3232

3333
return {
@@ -38,7 +38,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
3838
}
3939

4040
export function PlacesIndexRoute() {
41-
const { places, keyword } = useLoaderData() as Awaited<
41+
const { places, keyword, topDestinations } = useLoaderData() as Awaited<
4242
ReturnType<typeof loader>
4343
>;
4444

@@ -150,7 +150,11 @@ export function PlacesIndexRoute() {
150150
<aside className="w-[720px] h-screen flex flex-col">
151151
<PlacesSidebarHeader />
152152
<div className="p-6 h-[85%]">
153-
<PlaceDetailPlaceholder places={places} keyword={keyword} />
153+
<PlaceDetailPlaceholder
154+
places={places}
155+
keyword={keyword}
156+
topDestinations={topDestinations}
157+
/>
154158
</div>
155159
</aside>
156160

@@ -214,46 +218,60 @@ function PlacesSidebarHeader() {
214218
function PlaceDetailPlaceholder({
215219
places,
216220
keyword,
221+
topDestinations,
217222
}: {
218223
places: Place[];
219224
keyword: string;
225+
topDestinations: Place[];
220226
}) {
227+
const placeList = keyword !== "" ? places : topDestinations;
228+
221229
return (
222230
<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>
224234

225235
<ScrollArea className="h-[100%]">
226-
{places.map((place, index) => (
236+
{placeList.map((place, index) => (
227237
<div
228238
className="flex flex-row gap-4 mb-4 min-h-[145px] w-full"
229239
key={index}
230240
>
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>
236248

237249
<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>
239256

240257
<div className="flex flex-row gap-4 ">
241258
{place.categories.map((category, index) => (
242-
<div
259+
<Link
260+
to={`/places?q=${category.name}`}
243261
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"
245263
>
246264
<p className="font-bold text-xs text-blue-600">
247265
{category.name}
248266
</p>
249-
</div>
267+
</Link>
250268
))}
251269
</div>
252270

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]">
254272
{place.description}
255273
</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]">
257275
{place.address}
258276
</p>
259277
</div>

0 commit comments

Comments
 (0)