Skip to content

Commit

Permalink
format: address linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tuneerroy committed Jan 28, 2024
1 parent c97c8aa commit a471c98
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
8 changes: 4 additions & 4 deletions frontend/components/analytics/AnalyticsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ const AnalyticsCardContent = ({
total += x.vote_count
})
const targetPopulationsData = data?.poll_statistics || []
const schoolVotes = {}
const yearVotes = {}
const schoolVotes: { [key: string]: number } = {}
const yearVotes: { [key: string]: number } = {}

targetPopulationsData.forEach((item) => {
if (item.breakdown && item.breakdown.SCHOOL) {
Expand All @@ -179,7 +179,7 @@ const AnalyticsCardContent = ({
}
if (item.breakdown && item.breakdown.YEAR) {
const years = item.breakdown.YEAR
Object.keys(year).forEach((year) => {
Object.keys(years).forEach((year) => {
if (yearVotes[year]) {
yearVotes[year] += years[year]
} else {
Expand All @@ -204,7 +204,7 @@ const AnalyticsCardContent = ({
display: 'flex',
justifyContent: 'center',
fontSize: '1rem',
fontWeight: '500',
fontWeight: 500,
}}
>
Coming Soon!
Expand Down
20 changes: 16 additions & 4 deletions frontend/components/analytics/PieChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ const PieChartNumberWrapper = s.div`
margin-bottom: 5px;
`

const SimplePieChart = ({ schoolData, yearData, mode, uniqueVotes }) => {
const SimplePieChart = ({
schoolData,
yearData,
mode,
uniqueVotes,
}: {
schoolData: { [key: string]: number }
yearData: { [key: string]: number }
mode: string
uniqueVotes: number
}) => {
const dataToUse = mode === 'school' ? schoolData : yearData
const COLORS = mode === 'school' ? SCHOOL_COLORS : YEAR_COLORS
const formattedData = Object.keys(dataToUse).map((school) => ({
Expand Down Expand Up @@ -46,10 +56,12 @@ const SimplePieChart = ({ schoolData, yearData, mode, uniqueVotes }) => {
outerRadius={125}
innerRadius={60}
>
{formattedData.map((entry: string, index: number) => {
{formattedData.map(({ name, value }) => {
return (
// eslint-disable-next-line react/no-array-index-key
<Cell key={`cell-${index}`} fill={COLORS[entry.name]} />
<Cell
key={`cell-${value}`}
fill={COLORS[name as keyof typeof COLORS]}
/>
)
})}
</Pie>
Expand Down
16 changes: 14 additions & 2 deletions frontend/components/analytics/VotesBreakdownComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export default function VotesBreakdownComponent({
schoolData,
yearData,
mode,
}: {
schoolData: { [key: string]: number }
yearData: { [key: string]: number }
mode: string
}) {
const schoolNames = Object.keys(schoolData)
const yearNames = Object.keys(yearData)
Expand All @@ -28,10 +32,18 @@ export default function VotesBreakdownComponent({
<div>
{mode === 'school'
? schoolNames.map((name: string) => (
<Row color={SCHOOL_COLORS[name]} text={name} key={name} />
<Row
color={SCHOOL_COLORS[name as keyof typeof SCHOOL_COLORS]}
text={name}
key={name}
/>
))
: yearNames.map((name: string) => (
<Row color={YEAR_COLORS[name]} text={name} key={name} />
<Row
color={YEAR_COLORS[name as keyof typeof YEAR_COLORS]}
text={name}
key={name}
/>
))}
</div>
)
Expand Down
9 changes: 7 additions & 2 deletions frontend/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { useEffect, useState } from 'react'
import { doApiRequest } from '@/utils/fetch'

interface OptionStatsType {
breakdown: { [key: string]: number }
breakdown: { [key: string]: { [key: string]: number } }
option: string
}

interface TimeSeriesDataType {
date: string
votes: number
}

interface AnalyticsDataType {
poll_statistics: OptionStatsType[]
time_series: number[]
time_series: TimeSeriesDataType[]
}

interface OptionDataType {
Expand Down

0 comments on commit a471c98

Please sign in to comment.