diff --git a/.example.env b/.example.env index 7543eb4..c903dfa 100644 --- a/.example.env +++ b/.example.env @@ -1,3 +1,4 @@ +NEXT_PUBLIC_SPOONACULAR_API_KEY = # spoonacular apiKey NEXT_PUBLIC_FIREBASE_API_KEY = # firebase config apiKey NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN = # firebase config authDomain NEXT_PUBLIC_FIREBASE_PROJECT_ID = # firebase config projectId diff --git a/next.config.mjs b/next.config.mjs index 4678774..32aa002 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,8 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + images: { + domains: ["img.spoonacular.com"], + }, +}; export default nextConfig; diff --git a/package-lock.json b/package-lock.json index fa7f3e8..58d2e48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@emotion/styled": "^11.13.0", "@mui/icons-material": "^5.16.5", "@mui/material": "^5.16.5", + "axios": "^1.7.3", "dotenv": "^16.4.5", "firebase": "^10.12.4", "next": "14.2.5", @@ -2011,6 +2012,11 @@ "integrity": "sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -2035,6 +2041,16 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", + "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.1.1.tgz", @@ -2235,6 +2251,17 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2425,6 +2452,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -3297,6 +3332,25 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -3322,6 +3376,19 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -4326,6 +4393,25 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -4794,6 +4880,11 @@ "node": ">=12.0.0" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/package.json b/package.json index 80abd55..4d71520 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@emotion/styled": "^11.13.0", "@mui/icons-material": "^5.16.5", "@mui/material": "^5.16.5", + "axios": "^1.7.3", "dotenv": "^16.4.5", "firebase": "^10.12.4", "next": "14.2.5", diff --git a/src/app/components/RecipeDialog.tsx b/src/app/components/RecipeDialog.tsx new file mode 100644 index 0000000..ddc12aa --- /dev/null +++ b/src/app/components/RecipeDialog.tsx @@ -0,0 +1,224 @@ +import { Close } from "@mui/icons-material"; +import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; +import FavoriteIcon from "@mui/icons-material/Favorite"; +import ShareIcon from "@mui/icons-material/Share"; +import { Box, DialogContentText, DialogTitle, Stack } from "@mui/material"; +import Avatar from "@mui/material/Avatar"; +import Card from "@mui/material/Card"; +import CardActions from "@mui/material/CardActions"; +import CardContent from "@mui/material/CardContent"; +import CardHeader from "@mui/material/CardHeader"; +import CardMedia from "@mui/material/CardMedia"; +import Collapse from "@mui/material/Collapse"; +import IconButton, { IconButtonProps } from "@mui/material/IconButton"; +import Typography from "@mui/material/Typography"; +import { red } from "@mui/material/colors"; +import { styled } from "@mui/material/styles"; +import axios from "axios"; +import Image from "next/image"; +import * as React from "react"; + +type Props = { + pantryData: any; + setRecipeCard: any; +}; + +const RecipeDialog = ({ pantryData, setRecipeCard }: Props) => { + const [recipes, setRecipes] = React.useState([]); + + const fetchRecipes = async () => { + const ingredients = pantryData + .map((item: { name: string }): string => item.name) + .join(", "); + const response = await axios.get( + `https://api.spoonacular.com/recipes/findByIngredients?ingredients=${ingredients}&number=5&apiKey=${process.env.NEXT_PUBLIC_SPOONACULAR_API_KEY}` + ); + console.log("🚀 ~ fetchRecipes ~ response.data:", response.data); + setRecipes(response.data); + }; + + React.useEffect(() => { + fetchRecipes(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( + +
{ + setRecipeCard(false); + }} + style={{ + position: "absolute", + top: 20, + right: 10, + cursor: "pointer", + padding: "5px", + }} + > + +
+ + Recommended Recipes + + + {recipes && + recipes.map((recipe: { id: number }): any => ( + + ))} + +
+ ); +}; + +export default RecipeDialog; + +interface ExpandMoreProps extends IconButtonProps { + expand: boolean; +} + +const ExpandMore = styled((props: ExpandMoreProps) => { + const { expand, ...other } = props; + return ; +})(({ theme, expand }) => ({ + transform: !expand ? "rotate(0deg)" : "rotate(180deg)", + marginLeft: "auto", + transition: theme.transitions.create("transform", { + duration: theme.transitions.duration.shortest, + }), +})); + +type RecipeProps = { + recipe: any; +}; + +const RecipeCard = ({ recipe }: RecipeProps) => { + const [expanded, setExpanded] = React.useState(false); + + const handleExpandClick = () => { + setExpanded(!expanded); + }; + + return ( + + + {recipe.title.substring(0, 1)} + + } + title={{recipe.title}} + subheader={`Likes: ${recipe.likes}`} + /> + + + + Available Ingredients: {recipe.usedIngredients.length} + + + Missing Ingredients: {recipe.missedIngredients.length} + + + + + + + + + + + + + + + + + Required Ingredients: + + + Missing Ingredients: + + + {recipe && + recipe.missedIngredients.map( + (missed: { name: string; original: string, image: string }): any => { + return ( + + {missed.name} + + {missed.original} + + + ); + } + )} + + + Available Ingredients: + + + {recipe && + recipe.usedIngredients.map( + (used: { name: string; original: string, image: string }): any => { + return ( + + {used.name} + + {used.original} + + + ); + } + )} + + + + + ); +}; diff --git a/src/app/page.tsx b/src/app/page.tsx index 47d8485..25ffd1d 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -33,6 +33,7 @@ import { } from "firebase/firestore"; import { useEffect, useState } from "react"; import { theme } from "../theme"; +import RecipeDialog from "./components/RecipeDialog"; export default function Home() { const [name, setName] = useState(""); @@ -41,6 +42,7 @@ export default function Home() { const [open, setOpen] = useState(false); const [searchTerm, setSearchTerm] = useState(""); const [updateData, setUpdateData] = useState(false); + const [recipeCard, setRecipeCard] = useState(false); useEffect(() => { fetchCollection(); @@ -91,9 +93,10 @@ export default function Home() {
- + Search @@ -119,6 +122,16 @@ export default function Home() { > Add new item + {pantryData.length > 0 && ( + + )}
{open && ( )} + {recipeCard === true && ( + + + + )} - + {item.name} {item.quantity} - - - + + + + - - - ))} diff --git a/src/theme.ts b/src/theme.ts index 514f884..834be35 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -29,6 +29,10 @@ export const theme = createTheme({ fontSize: "1.5rem", color: "#D6BD98", }, + h5: { + fontSize: "1rem", + color: "wheat" + }, body1: { fontSize: "1.10rem", fontWeight: 400,