Skip to content

Commit

Permalink
Merge pull request #46 from BU-Spark/ballotInitJason
Browse files Browse the repository at this point in the history
Ballot init jason
  • Loading branch information
jasonjiang9142 authored Jun 25, 2024
2 parents eaf6d9b + 7bb5389 commit 2292107
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 1,033 deletions.
6 changes: 6 additions & 0 deletions client/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ export const deployedBostonMunicipalAPI = deployedStrapiURL + 'boston-municipal-
export const localCandidateAPI = localStrapiURL + 'candidates';
export const deployedCandidateAPI = deployedStrapiURL + 'candidates';

// URL for the local + deployed candidate role API
export const localCandidateRoleAPI = localStrapiURL + 'candidate-roles';
export const deployedCandidateRoleAPI = deployedStrapiURL + 'candidate-roles';

export const localBallotInitiativeAPI = localStrapiURL + 'ballot-initiatives';
export const deployedBallotInitiativeAPI = deployedStrapiURL + 'ballot-initiatives';




// Global variables and their setting functions for district number and selected election
export let globalDistrictNum: string | null = null;
Expand Down
8 changes: 3 additions & 5 deletions client/src/pages/ballotInfo/ballotInitDropDown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* Hardcoded drop down for ballot initatives. Styles the outer dropdown as well
* as the contents.
*/


import * as React from 'react';
import Accordion from '@mui/material/Accordion';
Expand Down Expand Up @@ -34,7 +32,7 @@ export default function BallotInitDropDown() {
{item.content.proponent.phone}<br />
</div>

<Card className='my-8' sx={{backgroundColor: '#f4f4f4', minWidth: 275}}>
<Card className='my-8' sx={{ backgroundColor: '#f4f4f4', minWidth: 275 }}>
<CardContent>
<Typography className='text-xl underline'>What is a vote YES?</Typography>
<ul className='list-disc list-outside text-lg pr-8 text-left pl-16 py-2'>
Expand All @@ -45,7 +43,7 @@ export default function BallotInitDropDown() {
</CardContent>
</Card>

<Card className='mt-8 mb-5' sx={{backgroundColor: '#f4f4f4', minWidth: 275 }}>
<Card className='mt-8 mb-5' sx={{ backgroundColor: '#f4f4f4', minWidth: 275 }}>
<CardContent>
<Typography className='text-xl underline'>What is a vote NO?</Typography>
<ul className='list-disc list-outside text-lg pr-8 text-left pl-16 py-2'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ElectionCheckbox: React.FC<ElectionCheckboxProps> = ({ onCheck }) => {
const fetchElectionDates = async () => {
setIsLoading(true);
try {
const response = await fetch(deployedBostonMunicipalAPI, {
const response = await fetch(localBostonMunicipalAPI, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -74,7 +74,6 @@ const ElectionCheckbox: React.FC<ElectionCheckboxProps> = ({ onCheck }) => {

// When box is checked, set the election as selected, set the global variable (in common/index.tsx), and call onCheck function
const handleCheckboxChange = (electionName: string) => {
console.log(electionName);
setSelectedElection(electionName);
setGlobalCurrElection(electionName);
onCheck(electionName);
Expand Down
68 changes: 35 additions & 33 deletions client/src/pages/ballotInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ButtonFill from "@/components/button/ButtonFill"
import * as React from 'react';
import NavBar from "@/components/nav/NavBar";
import BallotInitDropDown from "./ballotInitDropDown";
import ButtonFillEx from "@/components/button/ButtonFillEx";
import DistrictForm from "./districtForm";
import ElectionCheckbox from "./electionCheckBox/electionCheckbox";
import CandidateData from "./whatsOnTheBallot/candidateData";
import BallotInitative from "./whatsOnTheBallot/ballotInitative";


export default function BallotInfo() {
Expand All @@ -26,50 +26,52 @@ export default function BallotInfo() {

<div>
<div className="bg-oval-wrapper flex flex-col justify-center">
{/* Header */}
<div className='flex flex-col justify-center items-center p-4 text-center my-4'>
<h1 className='text-blue-700 font-bold text-6xl bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent'>Ballot Info</h1>
<h1 className='p-5 mt-2 text-blue-700 font-bold text-3xl bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent'>LEARN. PLAN.</h1>
<h1 className='font-semibold text-2xl p-5'>Explore the elections, candidates, and crucial issues personalized to your community.</h1>
</div>
{/* Header */}
<div className='flex flex-col justify-center items-center p-4 text-center my-4'>
<h1 className='text-blue-700 font-bold text-6xl bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent'>Ballot Info</h1>
<h1 className='p-5 mt-2 text-blue-700 font-bold text-3xl bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent'>LEARN. PLAN.</h1>
<h1 className='font-semibold text-2xl p-5'>Explore the elections, candidates, and crucial issues personalized to your community.</h1>
</div>


{/* Address form */}
<div className='flex flex-col justify-center items-center'>
<DistrictForm onFormSubmit={handleFormSubmit}/>
</div>
{/* Address form */}
<div className='flex flex-col justify-center items-center'>
<DistrictForm onFormSubmit={handleFormSubmit} />
</div>


{/* Election checkbox card */}
<ElectionCheckbox onCheck={handleCheck}/>
{/* Election checkbox card */}
<ElectionCheckbox onCheck={handleCheck} />


{/* What's on the Ballot dropdown */}
<div className='flex flex-col justify-center items-center py-8 px-2 my-6'>
<h1 className='font-bold text-center mx-6 my-4 text-4xl text-blue-700' style={{ fontFamily: 'Arial, sans-serif' }}><strong>What&apos;s on the Ballot?</strong></h1>

{/* Don't make instance of candidate data till form and election are done */}
{(isFormSubmitted && selectedElection) ? (
<>
<h1 className='font-semibold text-left text-3xl mt-4'>Candidates</h1>
<CandidateData />
<h1 className='font-semibold text-left text-3xl mt-4'>Ballot Initiatives</h1>
<p className="text-xl my-2">Put description here when Yawu sends it</p>
<BallotInitDropDown />
</>

) : (
<p className="text-xl font-semibold text-red-500">Please fill out the <u>address form</u> above and <u>select an election</u> to see your ballot information</p>
)}
</div>
{/* Don't make instance of candidate data till form and election are done */}
{(isFormSubmitted && selectedElection) ? (
<>
<h1 className='font-semibold text-left text-3xl mt-4'>Candidates</h1>
<CandidateData />
<h1 className='font-semibold text-left text-3xl mt-4'>Ballot Initiatives</h1>
<p className="text-xl my-2">Put description here when Yawu sends it</p>
<BallotInitative />
</>

) : (
<p className="text-xl font-semibold text-red-500">Please fill out the <u>address form</u> above and <u>select an election</u> to see your ballot information</p>
)}
</div>

{/* Footer */}
<div className='flex flex-col justify-center items-center p-4 text-center my-6'>
<h1 className='font-semibold text-lg'>You may be wondering...</h1>
<ButtonFill name='What are my Voting Options' link='/votingOptions' className='p-4 m-4 rounded-full bg-blue-700 text-white' />
<ButtonFill name='Basic Election Info' link='/upcomingElections' className='p-4 m-4 rounded-full bg-blue-700 text-white' />
</div>



{/* Footer */}
<div className='flex flex-col justify-center items-center p-4 text-center my-6'>
<h1 className='font-semibold text-lg'>You may be wondering...</h1>
<ButtonFill name='What are my Voting Options' link='/votingOptions' className='p-4 m-4 rounded-full bg-blue-700 text-white' />
<ButtonFill name='Basic Election Info' link='/upcomingElections' className='p-4 m-4 rounded-full bg-blue-700 text-white' />
</div>
</div>
</div>
)
Expand Down
145 changes: 145 additions & 0 deletions client/src/pages/ballotInfo/whatsOnTheBallot/ballotInitative.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
'use client';

import { useState, useEffect } from 'react';
import { localBallotInitiativeAPI } from '@/common';

import * as React from 'react';
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import Typography from '@mui/material/Typography';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { Card, CardContent } from '@mui/material';
import { globalDistrictNum, globalCurrElection } from '@/common';

interface Initiative {
id: number;
attributes: {
District: string;
InitiativeName: string;
ProponentEmail: string;
ElectionName: string;
ProponentName: string;
ProponentPhoneNumber: string;
WhatIsNo: string;
WhatIsYes: string;
};
}

interface Init {
District: string;
InitiativeName: string;
ProponentEmail: string;
ElectionName: string;
ProponentName: string;
ProponentPhoneNumber: string;
WhatIsNo: string;
WhatIsYes: string;
}

export default function BallotInitiative() {
const [initiative, setInitiative] = useState<Initiative[]>([]);
const [districtNum, setDistrictNum] = useState<string | null>(globalDistrictNum);
const [selectedElection, setSelectedElection] = useState<string | null>(globalCurrElection);
const [filteredData, setFilteredData] = useState<{ [key: string]: Init[] }>({});

useEffect(() => {
const getData = async () => {
try {
const res = await fetch(localBallotInitiativeAPI, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (res.ok) {
const data = (await res.json()).data;
setInitiative(data);
} else {
console.error('Failed to fetch data');
}
} catch (e) {
console.error('Error fetching data:', e);
}
};

getData();
}, []);

useEffect(() => {
setDistrictNum(globalDistrictNum);
setSelectedElection(globalCurrElection);
console.log(globalDistrictNum, globalCurrElection);

if (initiative.length > 0 && globalDistrictNum && globalCurrElection) {
const curData: { [key: string]: Init[] } = {};

initiative.forEach((item) => {
const initDistrict = item.attributes.District;
const initElection = item.attributes.ElectionName;
if ((initDistrict === globalDistrictNum || initElection === 'All Districts') && initElection === globalCurrElection?.trim()) {
if (curData[initDistrict]) {
curData[initDistrict].push(item.attributes);
} else {
curData[initDistrict] = [item.attributes];
}
}
});

console.log(curData);
setFilteredData(curData);
}
}, [globalDistrictNum, globalCurrElection, initiative]);

useEffect(() => { })

return (
<div className="p-4 text-center w-full sm:w-3/4" style={{ paddingLeft: '24px', paddingRight: '24px' }}>
{Object.keys(filteredData).length > 0 ? (
Object.entries(filteredData).map(([key, items]) => (
items.map((item, index) => (
<Accordion key={`${key}-${index}`} className="bg-white mb-3">
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls={`panel${key}-${index}-content`}
id={`panel${key}-${index}-header`}
>
<Typography className="text-blue-700 text-xl">{item.InitiativeName}</Typography>
</AccordionSummary>
<AccordionDetails>
<div className="text-lg">
<Typography className="text-lg underline">Proponent&apos;s Contact:</Typography>
{item.ProponentName}
<br />
{item.ProponentEmail}
<br />
{item.ProponentPhoneNumber}
<br />
</div>
<Card className="my-8" sx={{ backgroundColor: '#f4f4f4', minWidth: 275 }}>
<CardContent>
<Typography className="text-xl underline">What is a vote YES?</Typography>
<ul className="list-disc list-outside text-lg pr-8 text-left pl-16 py-2">
{item.WhatIsYes}
</ul>
</CardContent>
</Card>
<Card className="mt-8 mb-5" sx={{ backgroundColor: '#f4f4f4', minWidth: 275 }}>
<CardContent>
<Typography className="text-xl underline">What is a vote NO?</Typography>
<ul className="list-disc list-outside text-lg pr-8 text-left pl-16 py-2">
{item.WhatIsNo}
</ul>
</CardContent>
</Card>
</AccordionDetails>
</Accordion>
))
))
) : (
<div>There is no data about the ballot for the district and election you have selected.</div>
)}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ export default function CandidateData() {
setFilteredCandidateData(sortedData);
}

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


useEffect(() => {
console.log(filteredCandidateData);
//console.log(filteredCandidateData);
}, [filteredCandidateData])


Expand Down
Loading

0 comments on commit 2292107

Please sign in to comment.