Skip to content

Commit

Permalink
Fixed remaining lint issues and added coderabbit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilDahekar committed Feb 8, 2025
1 parent 810b6a8 commit 78af209
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
7 changes: 2 additions & 5 deletions components/FinancialSummary/BarChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ export default function BarChartComponent() {
const categories: string[] = getUniqueCategories();
const years: string[] = ['2023', '2024']; // Add more years as needed

// Effect hook to handle mounting state
useEffect(() => {
setMounted(true);
}, []);

// Effect hook to update windowWidth state on resize
// eslint-disable-next-line consistent-return
useEffect(() => {
setMounted(true);
if (typeof window !== 'undefined') {
const handleResize = () => {
setWindowWidth(window.innerWidth);
Expand Down
4 changes: 2 additions & 2 deletions pages/finance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SponsorshipTiers from '../components/FinancialSummary/SponsorshipTiers';
import SuccessStories from '../components/FinancialSummary/SuccessStories';
import Container from '../components/layout/Container';

// Dynamically import BarChartComponent with SSR disabled
const BarChartComponent = dynamic(() => import('../components/FinancialSummary/BarChartComponent'), { ssr: false });

/**
Expand All @@ -20,8 +19,9 @@ const BarChartComponent = dynamic(() => import('../components/FinancialSummary/B
*/
export default function FinancialSummary() {
const [mounted, setMounted] = useState(false);
const [windowWidth, setWindowWidth] = useState(0);
const [windowWidth, setWindowWidth] = useState<number>(0);

// eslint-disable-next-line consistent-return
useEffect(() => {
setMounted(true);
if (typeof window !== 'undefined') {
Expand Down
33 changes: 29 additions & 4 deletions utils/loadYearData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
export const loadYearData = (year: string) => {
import type { ExpenseItem, ExpensesLinkItem } from '@/types/FinancialSummary/BarChartComponent';
import expenses2023 from '../config/finance/2023/Expenses.json';
import expensesLink2023 from '../config/finance/2023/ExpensesLink.json';
import expenses2024 from '../config/finance/2024/Expenses.json';
import expensesLink2024 from '../config/finance/2024/ExpensesLink.json';

interface YearData {
expenses: { [key: string]: ExpenseItem[] };
links: ExpensesLinkItem[];
}

const YEAR_DATA_MAP: { [key: string]: YearData } = {
'2023': {
expenses: expenses2023,
links: expensesLink2023
},
'2024': {
expenses: expenses2024,
links: expensesLink2024
}
};

export const loadYearData = (year: string): { expensesData: { [key: string]: ExpenseItem[] }, expensesLinkData: ExpensesLinkItem[] } => {
try {
const expensesData = require(`../config/finance/${year}/Expenses.json`);
const expensesLinkData = require(`../config/finance/${year}/ExpensesLink.json`);
const yearData = YEAR_DATA_MAP[year];
if (!yearData) {
throw new Error(`No data available for year ${year}`);
}
const { expenses: expensesData, links: expensesLinkData } = yearData;
return { expensesData, expensesLinkData };
} catch (error) {
console.error(`Failed to load data for year ${year}:`, error);
return { expensesData: {}, expensesLinkData: [] };
}
};
};

0 comments on commit 78af209

Please sign in to comment.