diff --git a/app/search/components/SearchSideBar.tsx b/app/search/components/SearchSideBar.tsx index fe749ad..892c0dc 100644 --- a/app/search/components/SearchSideBar.tsx +++ b/app/search/components/SearchSideBar.tsx @@ -1,33 +1,80 @@ -export default function SearchSideBar() { +import { Cuisine, Location, PRICE } from "@prisma/client"; +import Link from "next/link"; + +export default async function SearchSideBar({ + locations, + cuisines, + searchParams +}: { + locations: Location[]; + cuisines: Cuisine[]; + searchParams: {city?: string, location?: string, cuisine?: string, price: PRICE} +}) { + console.log("cuisines: ", cuisines); + console.log("locations: ", locations); + + const priceStyle = "border w-full text-reg font-light p-2 text-center" + const prices = [ + {label: "$", price: PRICE.CHEAP, className: `${priceStyle} rounded-l`}, + {label: "$$", price: PRICE.REGULAR, className: `${priceStyle} `}, + {label: "$$$", price: PRICE.EXPENSIVE, className: `${priceStyle} rounded-r`} + ]; + return (
-
+

Region

-

Toronto

-

Ottawa

-

Montreal

-

Hamilton

-

Kingston

-

Niagara

+ {locations.map((location, index) => ( + + {location.name} + + ))}
-
+

Cuisine

-

Mexican

-

Italian

-

Chinese

+ {cuisines.map((cuisine, index) => ( + + {cuisine.name} + + ))}

Price

- - - + { + prices.map(({price, label, className}) => ( + + {label} + + )) + }
diff --git a/app/search/page.tsx b/app/search/page.tsx index 2dd194d..9d964b4 100644 --- a/app/search/page.tsx +++ b/app/search/page.tsx @@ -1,11 +1,11 @@ -import { PrismaClient, Restaurant } from "@prisma/client"; +import { PRICE, PrismaClient } from "@prisma/client"; import Header from "../components/Header"; import RestaurantCard from "./components/RestaurantCard"; import SearchSideBar from "./components/SearchSideBar"; const prisma = new PrismaClient(); -const fetchRestaurantsByCity = (city: string | undefined) => { +const fetchRestaurants = (searchParams: {city?: string, location?: string, cuisine?: string, price?: PRICE} | undefined) => { const select = { id: true, name: true, @@ -16,29 +16,48 @@ const fetchRestaurantsByCity = (city: string | undefined) => { slug: true } - if (!city) return prisma.restaurant.findMany({select}); + if (!searchParams) return prisma.restaurant.findMany({select}); return prisma.restaurant.findMany({ where: { location: { name: { - equals: city.toLowerCase() + equals: searchParams.city ? searchParams.city.toLowerCase() : undefined } + }, + cuisine: { + name: { + equals: searchParams.cuisine ? searchParams.cuisine : undefined + } + }, + price: { + equals: searchParams.price ? searchParams.price : undefined } }, select }) - } -export default async function Search({searchParams}: {searchParams: {city: string}}) { - const restaurants = await fetchRestaurantsByCity(searchParams.city) - console.log(restaurants) +const fetchLocations = () => { + return prisma.location.findMany({select: {name: true}}) +} + +const fetchCuisines = () => { + return prisma.cuisine.findMany({select: {name: true}}) +} + +export default async function Search({searchParams}: {searchParams: {city?: string, location?: string, cuisine?: string, price?: PRICE}}) { + const restaurants = await fetchRestaurants(searchParams) + const cuisines = await fetchCuisines() + const locations = await fetchLocations() + + // console.log(restaurants) return ( <>
- + {/* @ts-expect-error Server Component */} +
{ restaurants.length