diff --git a/Code/frontend/src/App.js b/Code/frontend/src/App.js
index ad6d9b80..df6c929f 100644
--- a/Code/frontend/src/App.js
+++ b/Code/frontend/src/App.js
@@ -1,200 +1,70 @@
-//
-import recipeDB from "./apis/recipeDB";
-import React, { Component } from "react";
+import React, { useState } from "react";
import Nav from "./components/Navbar.js";
import Login from "./components/Login.js";
import { doSignInWithEmailAndPassword, doCreateUserWithEmailAndPassword, doSignOut } from "./firebase/auth";
import SearchBlock from "./components/SearchBlock.js";
+import { useAuth, AuthProvider } from "./contexts/authContext/index";
-// Main component of the project
-class App extends Component {
- // constructor for the App Component
- constructor() {
- super();
+const App = () => {
+ const { currentUser, userLoggedIn } = useAuth();
+ const [showLoginModal, setShowLoginModal] = useState(false);
- this.state = {
- cuisine: "",
- //NoIngredients : 0,
- ingredients: new Set(),
- recipeList: [],
- recipeByNameList: [],
- email: "",
- flag: false,
- isLoading: false,
- isLoggedIn: false,
- isProfileView: false,
- showLoginModal: false,
- userData: {}
- };
- }
-
- handleBookMarks = () => {
- this.setState({
- isProfileView: true
- })
- }
-
- handleProfileView = () => {
- this.setState({
- isProfileView: false
- })
- }
-
- toggleLoginModal = () => {
- this.setState((prevState) => ({ showLoginModal: !prevState.showLoginModal }));
+ const toggleLoginModal = () => {
+ setShowLoginModal(prev => !prev);
};
- handleSignup = async (email, password) => {
+ const handleSignup = async (email, password) => {
try {
- const userCredential = await doCreateUserWithEmailAndPassword(email, password);
- this.setState({
- isLoggedIn: true,
- currentUser: userCredential.user,
- showLoginModal: false,
- });
+ await doCreateUserWithEmailAndPassword(email, password);
+ setShowLoginModal(false);
alert("Successfully Signed up!");
} catch (err) {
console.log(err);
alert(err.message);
}
- }
+ };
- // Handle user login
- handleLogin = async (email, password) => {
+ const handleLogin = async (email, password) => {
try {
- const userCredential = await doSignInWithEmailAndPassword(email, password);
- this.setState({
- isLoggedIn: true,
- currentUser: userCredential.user,
- showLoginModal: false,
- });
+ await doSignInWithEmailAndPassword(email, password);
+ setShowLoginModal(false);
alert("Successfully logged in!");
} catch (err) {
console.log(err);
alert(err.message);
}
- }
-
- // Function to get the user input from the Form component on Submit action
- handleSubmit = async (formDict) => {
- this.setState({
- isLoading: true
- })
- console.log(formDict)
- this.setState({
- // cuisine: cuisineInput,
- //NoIngredients: noIngredientsInput,
- ingredients: formDict["ingredient"],
- cuisine: formDict["cuisine"],
- email: formDict["email_id"],
- flag: formDict["flag"],
- });
-
- const mail = formDict["email_id"];
- const flag = formDict["flag"];
- const items = Array.from(formDict["ingredient"]);
- const cuis = formDict["cuisine"];
- this.getRecipeDetails(items, cuis, mail, flag);
- // alert(typeof(ingredientsInput["cuisine"]));
- };
-
- handleRecipesByName = (recipeName) => {
- this.setState({
- isLoading: true
- })
- recipeDB.get("/recipes/getRecipeByName", {
- params: {
- recipeName: recipeName
- }
- }).then(res => {
- console.log(res.data);
- this.setState({
- recipeByNameList: res.data.recipes,
- isLoading: false
- })
- })
- }
-
- getRecipeDetails = async (ingredient, cuis, mail, flag) => {
- try {
- const response = await recipeDB.get("/recipes", {
- params: {
- CleanedIngredients: ingredient,
- Cuisine: cuis,
- Email: mail,
- Flag: flag,
- },
- });
- this.setState({
- recipeList: response.data.recipes,
- isLoading: false
- });
- } catch (err) {
- console.log(err);
- }
- };
+ };
- // Handle logout
- handleLogout = async () => {
+ const handleLogout = async () => {
try {
await doSignOut();
- this.setState({
- isLoggedIn: false,
- showLoginModal: false,
- currentUser: null,
- });
alert("Logged out successfully");
} catch (err) {
console.log(err);
alert("Failed to log out");
}
- }
+ };
+
+ return (
+
+
+ {showLoginModal && (
+
+ )}
+
+
+ );
+};
- render() {
- return (
-
-
- {this.state.showLoginModal && (
-
- )}
-
- {/*
- <>
- {this.state.isProfileView ? (
-
- ) : (
-
-
- Search Recipe
- Search Recipe By Name
-
-
-
-
-
- {this.state.isLoading ? : }
-
-
-
-
-
-
-
- {this.state.isLoading ? : }
-
-
-
- )}
- >
- */}
-
- );
- }
-}
+const AppWithProvider = () => (
+
+
+
+);
-export default App;
+export default AppWithProvider;
\ No newline at end of file
diff --git a/Code/frontend/src/components/Navbar.js b/Code/frontend/src/components/Navbar.js
index 3d43e285..3605d958 100644
--- a/Code/frontend/src/components/Navbar.js
+++ b/Code/frontend/src/components/Navbar.js
@@ -55,7 +55,7 @@ export default function Nav(props) {
- {props.currentUser ? (
+ {props.userLoggedIn && props.currentUser ? (