import React, { ReactElement, useEffect, useState, useRef, useCallback} from 'react'; import { Box, Typography, Container, Paper } from '@mui/material'; import { Route, Routes, useLocation, useNavigate } from 'react-router-dom'; import DashboardIcon from '@mui/icons-material/Dashboard'; import PersonIcon from '@mui/icons-material/Person'; import ChatIcon from '@mui/icons-material/Chat'; import HistoryIcon from '@mui/icons-material/History'; import DescriptionIcon from '@mui/icons-material/Description'; import QuestionAnswerIcon from '@mui/icons-material/QuestionAnswer'; import BarChartIcon from '@mui/icons-material/BarChart'; import SettingsIcon from '@mui/icons-material/Settings'; import SearchIcon from '@mui/icons-material/Search'; import BookmarkIcon from '@mui/icons-material/Bookmark'; import WorkIcon from '@mui/icons-material/Work'; import InfoIcon from '@mui/icons-material/Info'; import BusinessIcon from '@mui/icons-material/Business'; import { SxProps, Theme } from '@mui/material'; import { ThemeProvider } from '@mui/material/styles'; import {Header} from './Components/Header'; import { Scrollable } from '../Components/Scrollable'; import { Footer } from './Components/Footer'; import { HomePage } from './Pages/HomePage'; // import { BackstoryThemeVisualizer } from './BackstoryThemeVisualizer'; import { HomePage as ChatPage } from '../Pages/HomePage'; import { ResumeBuilderPage } from '../Pages/ResumeBuilderPage'; import { Snack, SeverityType } from '../Components/Snack'; import { Query } from '../Components/ChatQuery'; import { ConversationHandle } from '../Components/Conversation'; import { AboutPage } from './Pages/AboutPage'; import { backstoryTheme } from '../BackstoryTheme'; import '@fontsource/roboto/300.css'; import '@fontsource/roboto/400.css'; import '@fontsource/roboto/500.css'; import '@fontsource/roboto/700.css'; import { VectorVisualizerPage } from 'Pages/VectorVisualizerPage'; type NavigationLinkType = { name: string; path: string; icon?: ReactElement; label?: ReactElement; }; const DefaultNavItems : NavigationLinkType[] = [ { name: 'Chat', path: '/chat', icon: }, { name: 'Resume Builder', path: '/resume-builder', icon: }, { name: 'RAG Visualizer', path: '/rag-visualizer', icon: }, { name: 'About', path: '/about', icon: }, // { name: 'How It Works', path: '/how-it-works', icon: }, // { name: 'For Candidates', path: '/for-candidates', icon: }, // { name: 'For Employers', path: '/for-employers', icon: }, // { name: 'Pricing', path: '/pricing', icon: }, ]; const CandidateNavItems : NavigationLinkType[]= [ { name: 'Dashboard', icon: , path: '/dashboard' }, { name: 'Profile', icon: , path: '/profile' }, { name: 'Backstory', icon: , path: '/backstory' }, { name: 'Resumes', icon: , path: '/resumes' }, { name: 'Q&A Setup', icon: , path: '/qa-setup' }, { name: 'Analytics', icon: , path: '/analytics' }, { name: 'Settings', icon: , path: '/settings' }, ]; const EmployerNavItems: NavigationLinkType[] = [ { name: 'Dashboard', icon: , path: '/dashboard' }, { name: 'Search', icon: , path: '/search' }, { name: 'Saved', icon: , path: '/saved' }, { name: 'Jobs', icon: , path: '/jobs' }, { name: 'Company', icon: , path: '/company' }, { name: 'Analytics', icon: , path: '/analytics' }, { name: 'Settings', icon: , path: '/settings' }, ]; // Navigation links based on user type const getNavigationLinks = (userType: string, isLoggedIn: boolean) : NavigationLinkType[] => { if (!isLoggedIn) { return DefaultNavItems; } if (userType === 'candidate') { return CandidateNavItems; } // Employer navigation return EmployerNavItems; }; // Placeholder for page components const DashboardPage = () => Dashboard; const ProfilePage = () => Profile; const BackstoryPage = () => Backstory; const ResumesPage = () => Resumes; const QASetupPage = () => Q&A Setup; const AnalyticsPage = () => Analytics; const SettingsPage = () => Settings; const SearchPage = () => Search; const SavedPage = () => Saved; const JobsPage = () => Jobs; const CompanyPage = () => Company; // This is a placeholder for your actual user context type UserContext = { user: { type: string; name: string; avatar?: any; }; isAuthenticated: boolean; logout: () => void; }; const useUserContext = () : UserContext => { return { user: { type: 'candidate', // or 'employer' name: 'John Doe', avatar: null, }, isAuthenticated: false, logout: () => console.log('Logging out'), }; }; interface BackstoryPageContainerProps { children?: React.ReactNode; sx?: SxProps; userContext: UserContext; }; const BackstoryPageContainer = (props : BackstoryPageContainerProps) => { const { children, sx } = props; return ( {children} ); } const BackstoryApp = () => { const navigate = useNavigate(); const location = useLocation(); const userContext : UserContext = useUserContext(); const { user, isAuthenticated } = userContext; const [navigationLinks, setNavigationLinks] = useState([]); const snackRef = useRef(null); const chatRef = useRef(null); const setSnack = useCallback((message: string, severity?: SeverityType) => { snackRef.current?.setSnack(message, severity); }, [snackRef]); const submitQuery = (query: Query) => { console.log(`handleSubmitChatQuery:`, query, chatRef.current ? ' sending' : 'no handler'); chatRef.current?.submitQuery(query); navigate('/chat'); }; const [page, setPage] = useState(""); useEffect(() => { const currentRoute = location.pathname.split("/")[1] ? `/${location.pathname.split("/")[1]}` : "/"; setPage(currentRoute); }, [location.pathname]); useEffect(() => { setNavigationLinks(getNavigationLinks(user.type, isAuthenticated)); }, [user.type, isAuthenticated]); // Render appropriate routes based on user type return (
} /> } /> } /> } /> } /> } /> }/> {/* Candidate-specific routes */} {user.type === 'candidate' && ( <> } /> } /> } /> } /> )} {/* Employer-specific routes */} {user.type === 'employer' && ( <> } /> } /> } /> } /> )} {/* Common routes */} } /> } /> {/* Redirect to dashboard by default */} } /> { location.pathname === "/" &&