Last active
May 17, 2020 01:20
-
-
Save ryanbelke/88355972c142cf2e496dc4510c1c8308 to your computer and use it in GitHub Desktop.
dish rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* /pages/restaurants.js */ | |
| import { useQuery } from "@apollo/react-hooks"; | |
| import { useRouter } from "next/router"; | |
| import { gql } from "apollo-boost"; | |
| import { | |
| Button, | |
| Card, | |
| CardBody, | |
| CardImg, | |
| CardText, | |
| CardTitle, | |
| Col, | |
| Row, | |
| } from "reactstrap"; | |
| const GET_RESTAURANT_DISHES = gql` | |
| query($id: ID!) { | |
| restaurant(id: $id) { | |
| id | |
| name | |
| dishes { | |
| id | |
| name | |
| description | |
| price | |
| image { | |
| url | |
| } | |
| } | |
| } | |
| } | |
| `; | |
| function Restaurants(props) { | |
| const router = useRouter(); | |
| const { loading, error, data } = useQuery(GET_RESTAURANT_DISHES, { | |
| variables: { id: router.query.id }, | |
| }); | |
| if (error) return "Error Loading Dishes"; | |
| if (loading) return <h1>Loading ...</h1>; | |
| if (data.restaurant) { | |
| const { restaurant } = data; | |
| return ( | |
| <> | |
| <h1>{restaurant.name}</h1> | |
| <Row> | |
| {restaurant.dishes.map((res) => ( | |
| <Col xs="6" sm="4" style={{ padding: 0 }} key={res.id}> | |
| <Card style={{ margin: "0 10px" }}> | |
| <CardImg | |
| top={true} | |
| style={{ height: 250 }} | |
| src={`${process.env.NEXT_PUBLIC_API_URL}${res.image.url}`} | |
| /> | |
| <CardBody> | |
| <CardTitle>{res.name}</CardTitle> | |
| <CardText>{res.description}</CardText> | |
| </CardBody> | |
| <div className="card-footer"> | |
| <Button outline color="primary"> | |
| + Add To Cart | |
| </Button> | |
| <style jsx> | |
| {` | |
| a { | |
| color: white; | |
| } | |
| a:link { | |
| text-decoration: none; | |
| color: white; | |
| } | |
| .container-fluid { | |
| margin-bottom: 30px; | |
| } | |
| .btn-outline-primary { | |
| color: #007bff !important; | |
| } | |
| a:hover { | |
| color: white !important; | |
| } | |
| `} | |
| </style> | |
| </div> | |
| </Card> | |
| </Col> | |
| ))} | |
| </Row> | |
| </> | |
| ); | |
| } | |
| return <h1>Add Dishes</h1>; | |
| } | |
| export default Restaurants; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment