Skip to content

Improve search places. #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
52 changes: 35 additions & 17 deletions src/routes/places/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { FeaturedPlace, Place } from "@/types/places";
import { Place } from "@/types/places";
import "mapbox-gl/dist/mapbox-gl.css";
import Map, { MapRef, PointLike, Source } from "react-map-gl";
import Layer from "react-map-gl/dist/esm/components/layer";
Expand All @@ -27,7 +27,7 @@ export async function loader({ request }: LoaderFunctionArgs) {

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

return {
Expand All @@ -38,7 +38,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
}

export function PlacesIndexRoute() {
const { places, keyword } = useLoaderData() as Awaited<
const { places, keyword, topDestinations } = useLoaderData() as Awaited<
ReturnType<typeof loader>
>;

Expand Down Expand Up @@ -150,7 +150,11 @@ export function PlacesIndexRoute() {
<aside className="w-[720px] h-screen flex flex-col">
<PlacesSidebarHeader />
<div className="p-6 h-[85%]">
<PlaceDetailPlaceholder places={places} keyword={keyword} />
<PlaceDetailPlaceholder
places={places}
keyword={keyword}
topDestinations={topDestinations}
/>
</div>
</aside>

Expand Down Expand Up @@ -214,46 +218,60 @@ function PlacesSidebarHeader() {
function PlaceDetailPlaceholder({
places,
keyword,
topDestinations,
}: {
places: Place[];
keyword: string;
topDestinations: Place[];
}) {
const placeList = keyword !== "" ? places : topDestinations;

return (
<div className="h-[100%]">
<p className="font-medium text-xl mb-6">Show result of "{keyword}"</p>
<p className="font-medium text-xl mb-6">
{keyword !== "" ? `Show result of "${keyword}"` : "Top destinations:"}
</p>

<ScrollArea className="h-[100%]">
{places.map((place, index) => (
{placeList.map((place, index) => (
<div
className="flex flex-row gap-4 mb-4 min-h-[145px] w-full"
key={index}
>
<img
className="object-cover rounded-lg w-[198px] h-[145px]"
src={place.imageUrl}
alt={place.title}
/>
<Link to={`/places/${place.slug}`}>
<img
className="object-cover rounded-lg w-[198px] h-[145px]"
src={place.imageUrl}
alt={place.title}
/>
</Link>

<div className="flex flex-col gap-2 flex-1 overflow-hidden">
<p className="text-xl font-bold">{place.title}</p>
<Link
to={`/places/${place.slug}`}
className="text-xl font-bold hover:underline"
>
{place.title}
</Link>

<div className="flex flex-row gap-4 ">
{place.categories.map((category, index) => (
<div
<Link
to={`/places?q=${category.name}`}
key={index}
className="px-[10px] py-[5px] bg-blue-200 rounded-3xl"
className="px-[10px] py-[5px] bg-blue-200 rounded-3xl hover:bg-blue-300"
>
<p className="font-bold text-xs text-blue-600">
{category.name}
</p>
</div>
</Link>
))}
</div>

<p className="text-sm font-medium text-gray-500 truncate text-ellipsis">
<p className="text-sm font-medium text-gray-500 truncate text-ellipsis max-w-[390px]">
{place.description}
</p>
<p className="text-sm font-medium text-gray-500 truncate text-ellipsis">
<p className="text-sm font-medium text-gray-500 truncate text-ellipsis max-w-[390px]">
{place.address}
</p>
</div>
Expand Down