Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mcpServers": {
"next-devtools": {
"command": "npx",
"args": ["-y", "next-devtools-mcp@latest"]
}
}
}
73 changes: 49 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"immutability-helper": "^3.1.1",
"jschardet": "^3.1.4",
"lodash": "^4.17.23",
"loglevel": "^1.9.2",
"lru-cache": "^11.2.6",
"moment": "^2.30.1",
"next": "^16.1.6",
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/currencies/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import { fetchRates } from '../../../utils/eurofx';
import logger from '../../../utils/logger';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function GET(_request: NextRequest) {
Expand All @@ -9,7 +10,7 @@ export async function GET(_request: NextRequest) {

return NextResponse.json(currencies);
} catch (error) {
console.error('Error fetching currencies:', error);
logger.error('Error fetching currencies:', error);
return NextResponse.json(
{ error: 'Failed to fetch currencies' },
{ status: 500 }
Expand Down
5 changes: 3 additions & 2 deletions src/app/api/currencyRates/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NextRequest, NextResponse } from 'next/server';
import { fetchRates } from '../../../utils/eurofx';
import logger from '../../../utils/logger';

export async function GET(request: NextRequest) {
try {
const url = new URL(request.url);
const currencyParams = url.searchParams.getAll('currencies');

const options: { historical: boolean; currencies?: string[] } = { historical: true };
if (currencyParams.length > 0) {
options.currencies = currencyParams;
Expand All @@ -22,7 +23,7 @@ export async function GET(request: NextRequest) {

return NextResponse.json(ratesObject);
} catch (error) {
console.error('Error fetching currency rates:', error);
logger.error('Error fetching currency rates:', error);
return NextResponse.json(
{ error: 'Failed to fetch currency rates' },
{ status: 500 }
Expand Down
17 changes: 4 additions & 13 deletions src/components/Charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type AppDispatch, Transaction, Account, Category } from '../types/redux
import dynamic from 'next/dynamic';
import moment, { Moment } from 'moment';
import { nest } from 'd3-collection';
import { TransactionGroup } from '../types/app';
import { type TransactionGroup, type CategoryExpense } from '../types/app';
import { sum } from 'd3-array';
import { createSelector } from 'reselect';
import { uncategorized } from '../data/categories';
Expand All @@ -18,15 +18,6 @@ import AmountSumBar from './charts/AmountSumBar';
import IncomeExpensesLine from './charts/IncomeExpensesLine';
import Loading from './shared/Loading';

interface CategoryExpense {
key: string;
value: {
amount: number;
transactions: Transaction[];
category: Category;
};
}

const CategoryExpenses = dynamic(() => import('./charts/CategoryExpenses'), {
loading: () => <Loading />
});
Expand Down Expand Up @@ -190,15 +181,15 @@ const getSortedCategoryExpenses = createSelector(
[getIncomeAndExpenses],
(incomeAndExpenses: Transaction[][]): CategoryExpense[] => {
const expenses = incomeAndExpenses[1];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (nest() as any)
return (nest<Transaction>()
.key((d: Transaction) => (d.category as unknown as Category).id)
// @ts-expect-error d3-collection types: .key() this-return doesn't track .rollup() generic
.rollup((transactions: Transaction[]) => ({
transactions,
category: transactions[0].category as unknown as Category,
amount: Math.abs(sum(transactions, (d: Transaction) => d.amount))
}))
.entries(expenses)
.entries(expenses) as unknown as CategoryExpense[])
.sort((a: CategoryExpense, b: CategoryExpense) => b.value.amount - a.value.amount);
}
);
Expand Down
16 changes: 15 additions & 1 deletion src/components/Intro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,21 @@ describe('Intro Component', () => {
accounts: {
data: []
},
edit: {},
edit: {
isCategoryGuessing: false,
isParsing: false,
isFetchingCurrencies: false,
isFetchingCurrencyRates: false,
dateSelect: {},
transactionList: {
page: 1,
pageSize: 50,
sortKey: 'date',
sortAscending: false,
filterCategories: new Set<string>()
},
charts: {}
},
search: {
transactions: {
text: '',
Expand Down
10 changes: 4 additions & 6 deletions src/components/Transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useState, useRef } from 'react';
import moment, { Moment } from 'moment';
import { useSelector, useDispatch } from 'react-redux';
import { type AppDispatch, type Transaction, type Category } from '../types/redux';
import type { TransactionGroup } from '../types/app';
import type { TransactionGroup, DisplayTransaction, DisplayTransactionGroup } from '../types/app';
import Link from 'next/link';
import { createSearchAction } from 'redux-search';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand Down Expand Up @@ -37,9 +37,8 @@ export default function Transactions() {
return obj;
}, {});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let transactionsData: any[] = state.transactions.data
.map((t: Transaction) => {
let transactionsData: DisplayTransaction[] = state.transactions.data
.map((t: Transaction): DisplayTransaction => {
return {
categoryGuess: (t.category.guess && categoriesObj[t.category.guess]) || null,
categoryConfirmed: (t.category.confirmed && categoriesObj[t.category.confirmed]) || null,
Expand All @@ -55,8 +54,7 @@ export default function Transactions() {

// Create an ID -> transactions mapping for easier tooltip'ing.
const transactionGroupsObj = Object.entries(state.transactions.groups || {})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.reduce((obj: Record<string, { groupId: string; linkedTransactions: any[] }>, [groupId, group]: [string, TransactionGroup]) => {
.reduce((obj: Record<string, DisplayTransactionGroup>, [groupId, group]: [string, TransactionGroup]) => {
obj[group.primaryId] = {
groupId,
linkedTransactions: group.linkedIds.map((id: string) => transactionsData[reverseTransactionLookup[id]])
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/AmountCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatNumber } from '../../util';

interface Account {
name: string;
currency: string;
currency?: string;
}

interface Amounts {
Expand Down
7 changes: 4 additions & 3 deletions src/components/charts/AmountSumBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { sum, ascending } from 'd3-array';
import color from '../../data/color';
import { formatNumber } from '../../util';
import { Transaction } from '../../types/redux';
import { type NestEntry } from '../../types/app';

interface Props {
transactions: Transaction[];
Expand All @@ -23,9 +24,9 @@ export default function AmountSumBar({ transactions }: Props) {
const data = nest<Transaction>()
.key((d: Transaction) => d.date.substring(0, 7))
.sortKeys(ascending)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.rollup((a: Transaction[]) => sum(a, (d: Transaction) => d.amount) as any)
.entries(transactions);
// @ts-expect-error d3-collection types: .key() this-return doesn't track .rollup() generic
.rollup((a: Transaction[]) => sum(a, (d: Transaction) => d.amount))
.entries(transactions) as unknown as NestEntry<number>[];

return (
<div className="chart">
Expand Down
16 changes: 2 additions & 14 deletions src/components/charts/CategoryExpenses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@ import CategorySelect from '../shared/CategorySelect';
import CategoryTreeMap from './CategoryTreeMap';
import CategoryLine from './CategoryLine';
import { Moment } from 'moment';
import { Transaction, Category } from '../../types/redux';

interface CategoryOption {
label: string;
value: string;
}

interface CategoryExpense {
value: {
amount: number;
category: Category;
transactions: Transaction[];
};
}
import { Category } from '../../types/redux';
import { type CategoryOption, type CategoryExpense } from '../../types/app';

interface Props {
handleCategoryChange: (categoryIds: string[]) => void;
Expand Down
11 changes: 2 additions & 9 deletions src/components/charts/CategoryLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ import React from 'react';
import { schemeCategory10 } from 'd3-scale-chromatic';
import { Moment } from 'moment';
import CustomLineChart from '../shared/CustomLineChart';
import { Transaction, Category } from '../../types/redux';

interface CategoryExpense {
value: {
amount: number;
category: Category;
transactions: Transaction[];
};
}
import { Transaction } from '../../types/redux';
import { type CategoryExpense } from '../../types/app';

interface Props {
sortedCategoryExpenses: CategoryExpense[];
Expand Down
9 changes: 1 addition & 8 deletions src/components/charts/CategoryTreeMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ import {
} from 'recharts';
import color from '../../data/color';
import { formatNumber } from '../../util';
import { Category } from '../../types/redux';

interface CategoryExpense {
value: {
amount: number;
category: Category;
};
}
import { type CategoryExpense } from '../../types/app';

interface Props {
sortedCategoryExpenses: CategoryExpense[];
Expand Down
Loading