import React, { useEffect, useState } from 'react'; import { useNavigate } from "react-router-dom"; import Button from '@mui/material/Button'; import Box from '@mui/material/Box'; import { BackstoryPageProps } from '../components/BackstoryTab'; import { CandidateInfo } from 'components/CandidateInfo'; import { connectionBase } from '../utils/Global'; import { Candidate } from "../types/types"; const CandidateListingPage = (props: BackstoryPageProps) => { const navigate = useNavigate(); const { sessionId, setSnack } = props; const [candidates, setCandidates] = useState(undefined); useEffect(() => { if (candidates !== undefined) { return; } const fetchCandidates = async () => { try { let response; response = await fetch(`${connectionBase}/api/u/${sessionId}`, { credentials: 'include', }); if (!response.ok) { throw new Error('Session not found'); } const candidates: Candidate[] = await response.json(); candidates.sort((a, b) => { let result = a.lastName.localeCompare(b.lastName); if (result === 0) { result = a.firstName.localeCompare(b.firstName); } if (result === 0) { result = a.username.localeCompare(b.username); } return result; }); console.log(candidates); setCandidates(candidates); } catch (err) { setSnack("" + err); } }; fetchCandidates(); }, [candidates, sessionId, setSnack]); return ( Not seeing a candidate you like? {candidates?.map((u, i) => ) : void => { navigate(`/u/${u.username}`) }} sx={{ cursor: "pointer" }} > )} ); }; export { CandidateListingPage };