restaurants are ready
This commit is contained in:
parent
0ba05b6434
commit
cbd1104a43
@ -19,8 +19,8 @@ export default function SearchBar() {
|
|||||||
<button
|
<button
|
||||||
className="rounded bg-red-600 px-9 py-2 text-white"
|
className="rounded bg-red-600 px-9 py-2 text-white"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (location === "banana") return;
|
if (location === "") return;
|
||||||
router.push("/search");
|
router.push(`/search?city=${location}`);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Let's go
|
Let's go
|
||||||
|
|||||||
@ -1,29 +1,41 @@
|
|||||||
|
import { Cuisine, PRICE, Location } from "@prisma/client";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import Price from "../../components/Price";
|
||||||
|
|
||||||
export default function RestaurantCard() {
|
interface Restaurant {
|
||||||
|
cuisine: Cuisine;
|
||||||
|
name: string;
|
||||||
|
location: Location;
|
||||||
|
id: number;
|
||||||
|
price: PRICE;
|
||||||
|
main_image: string;
|
||||||
|
slug: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RestaurantCard({restaurant}: {restaurant: Restaurant;} ) {
|
||||||
return (
|
return (
|
||||||
<div className="border-b flex pb-5">
|
<div className="border-b flex pb-5">
|
||||||
<Link href="/restaurant/milestones">
|
<Link href="/restaurant/milestones">
|
||||||
<img
|
<img
|
||||||
src="https://images.otstatic.com/prod1/49153814/2/medium.jpg"
|
src={restaurant.main_image}
|
||||||
alt=""
|
alt=""
|
||||||
className="w-44 rounded"
|
className="w-44 rounded"
|
||||||
/>
|
/>
|
||||||
<div className="pl-5">
|
<div className="pl-5">
|
||||||
<h2 className="text-3xl">Aiāna Restaurant Collective</h2>
|
<h2 className="text-3xl">{restaurant.name}</h2>
|
||||||
<div className="flex items-start">
|
<div className="flex items-start">
|
||||||
<div className="flex mb-2">*****</div>
|
<div className="flex mb-2">*****</div>
|
||||||
<p className="ml-2 text-sm">Awesome</p>
|
<p className="ml-2 text-sm">Awesome</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-9">
|
<div className="mb-9">
|
||||||
<div className="font-light flex text-reg">
|
<div className="font-light flex text-reg">
|
||||||
<p className="mr-4">$$$</p>
|
<Price price={restaurant.price} />
|
||||||
<p className="mr-4">Mexican</p>
|
<p className="mr-4">{restaurant.cuisine.name}</p>
|
||||||
<p className="mr-4">Ottawa</p>
|
<p className="mr-4">{restaurant.location.name}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-red-600">
|
<div className="text-red-600">
|
||||||
<a href="">View more information</a>
|
<Link href={`/restaurant/${restaurant.slug}`}>View more information</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@ -1,15 +1,52 @@
|
|||||||
|
import { PrismaClient, Restaurant } from "@prisma/client";
|
||||||
import Header from "../components/Header";
|
import Header from "../components/Header";
|
||||||
import RestaurantCard from "./components/RestaurantCard";
|
import RestaurantCard from "./components/RestaurantCard";
|
||||||
import SearchSideBar from "./components/SearchSideBar";
|
import SearchSideBar from "./components/SearchSideBar";
|
||||||
|
|
||||||
export default function Search() {
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
const fetchRestaurantsByCity = (city: string | undefined) => {
|
||||||
|
const select = {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
main_image: true,
|
||||||
|
price: true,
|
||||||
|
cuisine: true,
|
||||||
|
location: true,
|
||||||
|
slug: true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!city) return prisma.restaurant.findMany({select});
|
||||||
|
|
||||||
|
return prisma.restaurant.findMany({
|
||||||
|
where: {
|
||||||
|
location: {
|
||||||
|
name: {
|
||||||
|
equals: city.toLowerCase()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
select
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function Search({searchParams}: {searchParams: {city: string}}) {
|
||||||
|
const restaurants = await fetchRestaurantsByCity(searchParams.city)
|
||||||
|
console.log(restaurants)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header />
|
<Header />
|
||||||
<div className="flex py-4 m-auto w-2/3 justify-between items-start">
|
<div className="flex py-4 m-auto w-2/3 justify-between items-start">
|
||||||
<SearchSideBar />
|
<SearchSideBar />
|
||||||
<div className="w-5/6">
|
<div className="w-5/6">
|
||||||
<RestaurantCard />
|
{
|
||||||
|
restaurants.length
|
||||||
|
? restaurants.map(restaurant => {
|
||||||
|
return <RestaurantCard restaurant={restaurant}/>
|
||||||
|
})
|
||||||
|
: <p>No restaurants</p>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user