Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eelkus01 committed Jun 24, 2024
1 parent d634b39 commit 7687be4
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions client/src/pages/ballotInfo/whatsOnTheBallot/candidateData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Typography from '@mui/material/Typography';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import PeopleCard from './peopleCard';


interface CandidateAttributes {
CampaignSiteLink: string | null;
District: string;
Expand Down Expand Up @@ -39,7 +40,7 @@ export default function CandidateData() {


useEffect(() => {
// Fetch data here
// Fetch candidate data from strapi
const getData = async () => {
try {
const response = await fetch(localCandidateAPI, {
Expand All @@ -65,8 +66,8 @@ export default function CandidateData() {
}, [districtNum]);


// Set the district number to the global number which was set in DistrictForm
useEffect(() => {
console.log("GLOBAL: " + globalDistrictNum);
setDistrictNum(globalDistrictNum);
}, [globalDistrictNum]);

Expand All @@ -76,35 +77,36 @@ export default function CandidateData() {
// loop through the data, match the election data and district type, then check to see if their role is already in the hashtable
// if yes, add another person to the value . If no, initialize the key with the person the valye

const sortedData: { [key: string]: Candidate[] } = {}
const roleData: { [key: string]: string } = {}
const sortedData: { [key: string]: Candidate[] } = {};
const roleData: { [key: string]: string } = {};

// const district = 'District 1'
const election = "Primary Municipal Election"
const election = "Primary Municipal Election";

// Get candidate role from strapi
const getData = async () => {
try {
const response = await fetch(localCandidateRoleAPI, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
});

if (response.ok) {
const data = (await response.json()).data
const data = (await response.json()).data;
data.forEach((role: any) => {
roleData[role.attributes.Role_Name] = role.attributes.Role_Description
roleData[role.attributes.Role_Name] = role.attributes.Role_Description;
})

setCandidateRoleData(roleData)
setCandidateRoleData(roleData);
}
} catch (e) {
console.log(e)
console.log(e);
}
}
getData()
getData();

// Add candidates to hash table
if (allCandidateData.length > 0 && districtNum) {
allCandidateData.forEach((candidateDataObject: CandidateDataObject) => {

Expand All @@ -121,21 +123,21 @@ export default function CandidateData() {
}
});
setFilteredCandidateData(sortedData);

}

console.log(sortedData)
console.log(sortedData);
}, [allCandidateData, districtNum])



useEffect(() => {
console.log(filteredCandidateData)

console.log(filteredCandidateData);
}, [filteredCandidateData])


return (
<div className='p-4 text-center w-full sm:w-3/4' style={{ paddingLeft: '24px', paddingRight: '24px' }} >

{/* Map over the filtered candidates */}
{Object.keys(filteredCandidateData).length > 0 ? (
<>
{Object.keys(filteredCandidateData).map((role, index) => (
Expand All @@ -148,6 +150,7 @@ export default function CandidateData() {
<Typography className='text-blue-700 text-lg'>{role}</Typography>
</AccordionSummary>
<AccordionDetails>

{/* Description of the role */}
<Typography className='mx-4 mb-8 text-lg'>
{candidateRoleDate[role] ? candidateRoleDate[role] : 'No description available for this role'}
Expand Down

0 comments on commit 7687be4

Please sign in to comment.