From 5fed56ba76e3a26262eb1477434bbacfd0b51403 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sat, 7 Jun 2025 09:39:00 -0700 Subject: [PATCH] Scrolling in sub pages is working correctly --- .../src/components/ui/CandidatePicker.tsx | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 frontend/src/components/ui/CandidatePicker.tsx diff --git a/frontend/src/components/ui/CandidatePicker.tsx b/frontend/src/components/ui/CandidatePicker.tsx new file mode 100644 index 0000000..1a895f0 --- /dev/null +++ b/frontend/src/components/ui/CandidatePicker.tsx @@ -0,0 +1,84 @@ +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 { BackstoryElementProps } from 'components/BackstoryTab'; +import { CandidateInfo } from 'components/CandidateInfo'; +import { Candidate } from "types/types"; +import { useAuth } from 'hooks/AuthContext'; +import { useSelectedCandidate } from 'hooks/GlobalContext'; + +interface CandidatePickerProps extends BackstoryElementProps { + onSelect?: (candidate: Candidate) => void +}; + +const CandidatePicker = (props: CandidatePickerProps) => { + const { onSelect } = props; + const { apiClient, user } = useAuth(); + const { selectedCandidate, setSelectedCandidate } = useSelectedCandidate(); + const navigate = useNavigate(); + const { setSnack } = props; + const [candidates, setCandidates] = useState(null); + + useEffect(() => { + if (candidates !== null) { + return; + } + const getCandidates = async () => { + try { + const results = await apiClient.getCandidates(); + const candidates: Candidate[] = results.data; + 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; + }); + setCandidates(candidates); + } catch (err) { + setSnack("" + err); + } + }; + + getCandidates(); + }, [candidates, setSnack]); + + return ( + + {user?.isAdmin && + + Not seeing a candidate you like? + + + } + + {candidates?.map((u, i) => + { onSelect ? onSelect(u) : setSelectedCandidate(u); }} + sx={{ cursor: "pointer" }}> + {selectedCandidate?.id === u.id && + + } + {selectedCandidate?.id !== u.id && + + } + + )} + + + ); +}; + +export { + CandidatePicker +}; \ No newline at end of file