You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// constants.js// Swiggy API for to get Restaurant dataexportconstSWIGGY_API_URL=`https://www.swiggy.com/dapi/restaurants/list/v5?lat=12.9046136&lng=77.614948&is-seo-homepage-enabled=true&page_type=DESKTOP_WEB_LISTING`;// Swiggy API for to get Restaurant ItemexportconstMENU_API_URL=`https://www.swiggy.com/dapi/menu/pl?page-type=REGULAR_MENU&complete-menu=true&lat=12.9046136&lng=77.614948&restaurantId=`;// Restaurant Item Image CDN URL for Restaurant cardexportconstIMG_CDN_URL=`https://media-assets.swiggy.com/swiggy/image/upload/fl_lossy,f_auto,q_auto,w_300,h_300,c_fit/`;// Swiggy Restaurant PathexportconstSWIGGY_REST_API_PATH=`data?.cards[1]?.card?.card?.gridElements?.infoWithStyle?.restaurants`;// Social Media Links - URLexportconstLINKEDIN_LINK="https://www.linkedin.com/in/bharat2044/";exportconstGiTHUB_LINK="https://github.com/Bharat2044";exportconstTWITTER_LINK="https://x.com/bharat__2044/";exportconstEMAIL_LINK="mailto:[email protected]";// Github - username and repository nameexportconstGITHUB_USERNAME="Bharat2044";exportconstGITHUB_REPOSITORY_NAME="Namaste-React";// Github API for UserexportconstGITHUB_USER_API="https://api.github.com/users/";// Github API for RepositoryexportconstGITHUB_REPO_API="https://api.github.com/repos/";
// useRestaurantMenuData.jsimport{useEffect,useState}from"react";import{MENU_API_URL}from"../../../../../../public/common/constants";constuseRestaurantMenuData=(resId)=>{const[restaurantInfo,setRestaurantInfo]=useState(null);constfetchResMenusData=async()=>{try{constresponse=awaitfetch(MENU_API_URL+resId);constjson=awaitresponse.json();setRestaurantInfo(json?.data);}catch(error){console.error("Error while fetching data:",error);}};useEffect(()=>{fetchResMenusData();},[]);returnrestaurantInfo;};exportdefaultuseRestaurantMenuData;
// useOfflineStatus.jsimport{useState,useEffect}from"react";constuseOnlineStatus=()=>{const[isOnline,setIsOnline]=useState(true);// Check if Online or OfflineuseEffect(()=>{consthandleOnline=()=>{setIsOnline(true);};consthandleOffline=()=>{setIsOnline(false);};// Event Listenerswindow.addEventListener("online",handleOnline);window.addEventListener("offline",handleOffline);// Cleanup - Taught in Live Clssesreturn()=>{window.removeEventListener("online",handleOnline);window.removeEventListener("offline",handleOffline);};},[]);// return true if online, otherewise return falsereturnisOnline;};exportdefaultuseOnlineStatus;
// UserOffline.jsconstUserOffline=()=>{return(<divclassName="w-[90%] h-[calc(100vh-250px)] flex flex-col items-center justify-center gap-[20px]"><h1className="text-[#333] text-[3.5rem] font-bold text-center">
🔴 Offline!
</h1><pclassName="text-[2.5rem] text-[#444444] font-semibold text-center">
Sorry, it seems that you are currently offline. Please check your
internet connection.
</p></div>);};exportdefaultUserOffline;
// About.jsimport{Component}from"react";importburgerImagefrom"../../../../../../public/images/burger-image.png";importProfileClassfrom"./ProfileClass";importUserContextfrom"../context/UserContext";classAboutextendsComponent{constructor(props){super(props);this.state={showProfile: false,};}render(){const{ showProfile }=this.state;return(<divclassName="w-[90%] flex flex-col justify-center items-center flex-wrap gap-[40px]"><divclassName="flex flex-col justify-center items-center flex-wrap gap-[40px] transition-all ease-in-out delalay-[0.3s]">{<buttonclassName="text-white bg-[#d97919] text-[1.2rem] font-semibold py-2.5 px-5 border-none outline-none rounded-[5px] cursor-pointer hover:bg-[darkgreen] transition-all 0.3s ease-in-out"onClick={()=>{this.setState({showProfile: !showProfile});}}>{showProfile ? "Hide My Profile" : "Show My Profile"}</button>}{showProfile&&(<ProfileClassname={"Bharat Kumar"}location={"Bihar"}/>)}</div><divclassName="flex items-center justify-between flex-wrap gap-[40px] w-full"><divclassName="about-left"><h1className="text-[60px] text-[#494949] font-bold leading-[70px]"><UserContext.Consumer>{({ loggedInUser })=>{return(<div>
Hi, {loggedInUser ? loggedInUser.slice(0,20) : ""}</div>);}}</UserContext.Consumer>
Welcome to <br/> The world of <br/><spanclassName="text-white bg-[#d97919] rounded-[15px] px-[15px] py-[5px]">
Tasty & Fresh Food
</span></h1><h4className="text-[22px] mt-[10px] italic font-semibold">
"Better you will feel if you eat a Tasty
<spanclassName="text-[#d97919]">Trails</span> healthy meal"
</h4></div><div><imgsrc={burgerImage}alt="Food Image"/></div></div></div>);}}exportdefaultAbout;
// ProfileClass.jsimport{Component}from"react";importProfileUserClassfrom"./ProfileUserClass";importProfileRepoClassfrom"./ProfileRepoClass";import{GITHUB_USER_API,GITHUB_USERNAME,}from"../../../../../../public/common/constants";classprofileClassextendsComponent{constructor(props){super(props);// Call the super constructor with props// Initialize the state of the componentthis.state={userInfo: {name: "Bharat Kumar",// default valuesbio: "Java | React.js",// default valuesfollowers: 5,// default valuesavatar_url:
"https://www.dgvaishnavcollege.edu.in/dgvaishnav-c/uploads/2021/01/dummy-profile-pic.jpg",},};}asyncgetUserInfo(){try{constresponse=awaitfetch(GITHUB_USER_API+GITHUB_USERNAME);constjson=awaitresponse.json();this.setState({userInfo: json,});}catch(error){console.error("Error while fetching user data: ",error);}}componentDidMount(){// API Calls (Fetch Data)this.getUserInfo();}render(){const{ userInfo }=this.state;// object destructuring for json datareturn(<divclassName="flex justify-center items-center gap-[40px]"><divclassName="w-full overflow-hidden bg-white flex flex-col items-center justify-center gap-[20px] rounded-md p-[15px] shadow-2xl"><h1className="text-[28px] font-bold text-center text-[#1e1e1e] overflow-y-hidden">
About Me
</h1>{/* Passing props data (full json data) from parent to child */}<ProfileUserClassdata={userInfo}/></div><divclassName="w-full overflow-hidden bg-white flex flex-col items-center justify-center rounded-md p-[15px] shadow-2xl"><h1className="text-[28px] font-bold text-center text-[#1e1e1e] overflow-y-hidden">
Tasty<spanclassName="text-[darkorange]">Trails</span> App
Repository
</h1>{/* Passing props followers from parent to child */}<ProfileRepoClassfollowers={userInfo.followers}/></div></div>);}}exportdefaultprofileClass;
// ProfileUserClass.jsimport{Component}from"react";importSocialProfileClassfrom"./SocialProfileClass";import{GiTHUB_LINK}from"../../../../../../public/common/constants";classProfileUserClassextendsComponent{constructor(props){super(props);// Call the super constructor with props}render(){const{ name, avatar_url, bio }=this.props.data;// accessing full json data as props from parent class `ProfileClass`return(<divclassName="flex flex-col items-center justify-center gap-[20px] pt-0 px-[15px] pb-[10px]"><ahref={GiTHUB_LINK}target="_blank"className="flex flex-col items-center justify-center"><imgclassName="w-[180px] h-[180px] rounded-[50%] border-none cursor-pointer hover:scale-[1.02] transition-transform duration-300 ease-in-out"src={avatar_url}alt={name}title={name}/><h2className="text-xl font-bold text-[#551A8B]">{name}</h2></a><pclassName="text-[16px] text-[#575757] font-medium">{bio}</p><SocialProfileClass/></div>);}}exportdefaultProfileUserClass;
// Login.jsimport{Formik}from"formik";// import Formik from formikimport*asYupfrom"yup";// import Yup from yupimport{useNavigate}from"react-router-dom";// create a schema for validationconstschema=Yup.object().shape({email: Yup.string().required("Email is a required field").email("Invalid email format"),password: Yup.string().required("Password is a required field").min(8,"Password must be at least 8 characters"),});constLogin=()=>{constnavigate=useNavigate();functionhandleNavigate(values){// Alert the input values of the form that we filledalert(values);// setTimeout for navigate from login page to home pagesetTimeout(()=>{navigate("/");},0);}return(<>{/* Wrapping form inside formik tag and passing our schema to validationSchema prop */}<FormikvalidationSchema={schema}initialValues={{email: "",password: ""}}onSubmit={(values)=>{// call handleNavigate and pass input filed datahandleNavigate(JSON.stringify(values));}}>{({
values,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,})=>(<divclassName="flex justify-center items-center h-[100vh] w-full"><divclassName="relative z-10 bg-[#FFAF60] rounded-[10px] max-w-[380px] px-[40px] py-[25px] w-[50%]">{/* Passing handleSubmit parameter to html form onSubmit property */}<formnoValidateonSubmit={handleSubmit}><spanclassName="text-[40px] text-[#4b6cb7] mb-[25px] block text-center font-[500px]">
Login
</span>{/* Our input html with passing formik parameters like handleChange, values, handleBlur to input properties */}<inputtype="email"name="email"onChange={handleChange}onBlur={handleBlur}value={values.email}placeholder="Enter your email"className="outline-none bg-[#F2F2F2] w-full border-0 rounded-[5px] m-0 mb-[15px] p-[15px] text-[14px] focus:border-[blue]"/>{/* If validation is not passed show errors */}<pclassName="mt-0 mr-0 mb-[10px] ml-[10px] text-left text-[13px] text-[red]">{errors.email&&touched.email&&errors.email}</p>{/* input with passing formik parameters like handleChange, values, handleBlur to input properties */}<inputtype="password"name="password"onChange={handleChange}onBlur={handleBlur}value={values.password}placeholder="Enter your password"className="outline-none bg-[#F2F2F2] w-full border-0 rounded-[5px] m-0 mb-[15px] p-[15px] text-[14px] focus:border-[blue-500]"/>{/* If validation is not passed show errors */}<pclassName="mt-0 mr-0 mb-[10px] ml-[10px] text-left text-[13px] text-[red]">{errors.password&&touched.password&&errors.password}</p>{/* Click on submit button to submit the form */}<buttonclassName="uppercase outline-none bg-[#4b6cb7] text-[#FFF] text-[16px] cursor-pointer w-full border-0 rounded-md py-[15px] px-[40px] active:bg-[#395591] hover:bg-[blue] transition-all 0.3s ease-in-out"type="submit">
Login
</button></form></div></div>)}</Formik></>);};exportdefaultLogin;