[d7b7f00] | 1 | import styles from '../css/ProfileCss/profile-view-style.module.css';
|
---|
| 2 | import { useState, useEffect } from "react";
|
---|
| 3 | import Sidebar from './ProfileComponents/Sidebar';
|
---|
| 4 | import ProfileSection from './ProfileComponents/ProfileSection';
|
---|
| 5 | import FavoriteRecipesSection from "./ProfileComponents/FavoriteRecipesSection";
|
---|
| 6 | import MyReviewsSection from "./ProfileComponents/MyReviewsSection";
|
---|
| 7 | import OrderHistorySection from "./ProfileComponents/OrderHistorySection";
|
---|
| 8 | import { useLocation, useNavigate } from 'react-router-dom';
|
---|
| 9 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
---|
| 10 | import { faArrowLeft } from '@fortawesome/free-solid-svg-icons';
|
---|
| 11 |
|
---|
| 12 | const ProfileView = () => {
|
---|
| 13 | const location = useLocation();
|
---|
| 14 | const navigate = useNavigate();
|
---|
| 15 | const selectedFromState = location.state?.selected || 0;
|
---|
| 16 | const sidebarItems = ["Profile", "Favorite Recipes", "My Reviews", "Order History"];
|
---|
| 17 | const [selectedSideBar, setSelectedSideBar] = useState(selectedFromState);
|
---|
| 18 |
|
---|
| 19 | useEffect(() => {
|
---|
| 20 | setSelectedSideBar(selectedFromState);
|
---|
| 21 | }, [selectedFromState]);
|
---|
| 22 |
|
---|
| 23 | let heading = sidebarItems[selectedSideBar];
|
---|
| 24 |
|
---|
| 25 | const handleBackToHome = () => {
|
---|
| 26 | navigate('/');
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | return (
|
---|
| 30 | <>
|
---|
| 31 | <div className={styles.parent}>
|
---|
| 32 | <div className={styles.settingsContainer}>
|
---|
| 33 | <div className={styles.header}>
|
---|
| 34 | <div className={styles.backArrow} onClick={handleBackToHome}>
|
---|
| 35 | <FontAwesomeIcon icon={faArrowLeft} />
|
---|
| 36 | </div>
|
---|
| 37 | <div className={styles.settingsWrapper}><h2>{heading}</h2></div>
|
---|
| 38 | </div>
|
---|
| 39 | <div className={styles.contentWrapper}>
|
---|
| 40 | <Sidebar
|
---|
| 41 | items={sidebarItems}
|
---|
| 42 | selected={selectedSideBar}
|
---|
| 43 | onSelect={setSelectedSideBar}
|
---|
| 44 | />
|
---|
| 45 | <div className={styles.mainContent}>
|
---|
| 46 | {selectedSideBar === 0 && <ProfileSection/>}
|
---|
| 47 | {selectedSideBar === 1 && <FavoriteRecipesSection/>}
|
---|
| 48 | {selectedSideBar === 2 && <MyReviewsSection/>}
|
---|
| 49 | {selectedSideBar === 3 && <OrderHistorySection/>}
|
---|
| 50 | </div>
|
---|
| 51 | </div>
|
---|
| 52 | </div>
|
---|
| 53 | </div>
|
---|
| 54 | </>
|
---|
| 55 | );
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | export default ProfileView;
|
---|