-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Aromiii/searchRecipes
Search recipes
- Loading branch information
Showing
3 changed files
with
84 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,97 @@ | ||
import React, {useState} from 'react'; | ||
import React, {useEffect, useState} from 'react'; | ||
import Link from "next/link"; | ||
import {IoAdd, IoFastFoodOutline} from "react-icons/io5"; | ||
import {IoAdd, IoFastFoodOutline, IoFilterOutline} from "react-icons/io5"; | ||
import {CgProfile} from "react-icons/cg"; | ||
import {FaGalacticRepublic} from "react-icons/fa"; | ||
import {FaGalacticRepublic, FaBars} from "react-icons/fa"; | ||
import {signInWithGoogle} from "../config/firebase"; | ||
import {getAuth, onAuthStateChanged} from "firebase/auth"; | ||
import {useRouter} from "next/router"; | ||
|
||
const Dropdown = () => { | ||
//TODO when hovering on hamburger menu or the options menu shows otherwise not | ||
//TODO rewrite as sliding bar that goes top of navbar | ||
return <div className="absolute top-14 left-3 bg-gray-500 p-2 border-2 rounded-lg border-gray-600"> | ||
<Link href="/"> | ||
<a> | ||
<div className="flex gap-2 p-1"> | ||
<FaGalacticRepublic size="35"/> | ||
<p>Main page</p> | ||
</div> | ||
</a> | ||
</Link> | ||
<Link href="/recipes"> | ||
<a> | ||
<div className="flex gap-2 p-1"> | ||
<IoFastFoodOutline size="35"/> | ||
<p>Recipes</p> | ||
</div> | ||
</a> | ||
</Link> | ||
</div>; | ||
} | ||
|
||
const RecipeSearchBar = () => { | ||
return <div className="mx-auto flex"> | ||
<IoFilterOutline size="35"/> | ||
<input type="text" | ||
placeholder=" Search recipes..." | ||
className="text-xl rounded-3xl bg-gray-300 text p-1 mx-3"/> | ||
<Link href="/recipes/addnew" passHref> | ||
<a> | ||
<IoAdd size="35"/> | ||
</a> | ||
</Link> | ||
</div>; | ||
} | ||
|
||
const NavBar = () => { | ||
const [profilePic, setProfilePic] = useState<string | null>(null) | ||
const [recipeNav, setRecipeNav] = useState(false) | ||
const route = useRouter() | ||
|
||
const auth = getAuth(); | ||
onAuthStateChanged(auth, (user) => { | ||
if (user) { | ||
setProfilePic(user.photoURL) | ||
} else { | ||
setProfilePic(null) | ||
} | ||
}); | ||
console.log(route.pathname) | ||
useEffect(() => { | ||
onAuthStateChanged(auth, (user) => { | ||
if (user) { | ||
setProfilePic(user.photoURL) | ||
} else { | ||
setProfilePic(null) | ||
} | ||
}) | ||
}, [auth]) | ||
|
||
return ( | ||
<nav> | ||
<ul className="navbar_bg"> | ||
<li className="navbarListItem"> | ||
<Link href="/" passHref> | ||
<a> | ||
<FaGalacticRepublic size="35"/> | ||
</a> | ||
</Link> | ||
</li> | ||
<li className="navbarListItem"> | ||
<Link href="/recipes" passHref> | ||
<a> | ||
<IoFastFoodOutline size="35"/> | ||
</a> | ||
</Link> | ||
</li> | ||
<li className="navbarListItem"> | ||
<Link href="/recipes/addnew" passHref> | ||
<a> | ||
<IoAdd size="35"/> | ||
</a> | ||
</Link> | ||
</li> | ||
<li className="navbarListItem"> | ||
{profilePic === null ? ( | ||
<button type="button" onClick={signInWithGoogle}> | ||
<CgProfile size="35"/> | ||
</button> | ||
) : ( | ||
<Link href="/profile" passHref> | ||
<a> | ||
<img src={localStorage.getItem("profilePic")!} className="rounded-3xl"/> | ||
</a> | ||
</Link> | ||
)} | ||
</li> | ||
</ul> | ||
</nav> | ||
<nav> | ||
<ul className="text-3xl bg-gray-500 flex p-2 list-none place-items-center gap-9 h-16"> | ||
<li className="navbarListItem"> | ||
<button className="navbarListItem" onClick={() => setRecipeNav(!recipeNav)}> | ||
<FaBars size="35"/> | ||
{recipeNav && <Dropdown/>} | ||
</button> | ||
</li> | ||
<li className="mx-auto flex"> | ||
{route.pathname == "/recipes" ? ( | ||
<RecipeSearchBar/> | ||
) : ( | ||
<div className="font-bold">Food-helper</div> | ||
)} | ||
</li> | ||
<li className="navbarListItem"> | ||
{profilePic === null ? ( | ||
<button type="button" onClick={signInWithGoogle}> | ||
<CgProfile size="35"/> | ||
</button> | ||
) : ( | ||
<Link href="/profile" passHref> | ||
<a> | ||
<img src={localStorage.getItem("profilePic")!} className="rounded-3xl"/> | ||
</a> | ||
</Link> | ||
)} | ||
</li> | ||
</ul> | ||
|
||
</nav> | ||
) | ||
} | ||
export default NavBar; | ||
|
||
/* | ||
<li className="navbarListItem"> | ||
<Link href="/menu"> | ||
me | ||
</Link> | ||
</li> | ||
<li className="navbarListItem"> | ||
<Link href="/shopping-list"> | ||
sl | ||
</Link> | ||
</li>*/ | ||
export default NavBar; |
This file contains 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
This file contains 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
5d85aab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
food-helper – ./
food-helper-git-main-aromiii.vercel.app
food-helper-rho.vercel.app
food-helper-aromiii.vercel.app