Skip to content

Commit 8978f7e

Browse files
authored
Add mcp server, adjust types, add logger (#170)
* Add mcp server for next * Use loglevel, remove any types
1 parent 31d678d commit 8978f7e

30 files changed

+275
-215
lines changed

.mcp.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"mcpServers": {
3+
"next-devtools": {
4+
"command": "npx",
5+
"args": ["-y", "next-devtools-mcp@latest"]
6+
}
7+
}
8+
}

package-lock.json

Lines changed: 49 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"immutability-helper": "^3.1.1",
2424
"jschardet": "^3.1.4",
2525
"lodash": "^4.17.23",
26+
"loglevel": "^1.9.2",
2627
"lru-cache": "^11.2.6",
2728
"moment": "^2.30.1",
2829
"next": "^16.1.6",

src/app/api/currencies/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import { fetchRates } from '../../../utils/eurofx';
3+
import logger from '../../../utils/logger';
34

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

1011
return NextResponse.json(currencies);
1112
} catch (error) {
12-
console.error('Error fetching currencies:', error);
13+
logger.error('Error fetching currencies:', error);
1314
return NextResponse.json(
1415
{ error: 'Failed to fetch currencies' },
1516
{ status: 500 }

src/app/api/currencyRates/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import { fetchRates } from '../../../utils/eurofx';
3+
import logger from '../../../utils/logger';
34

45
export async function GET(request: NextRequest) {
56
try {
67
const url = new URL(request.url);
78
const currencyParams = url.searchParams.getAll('currencies');
8-
9+
910
const options: { historical: boolean; currencies?: string[] } = { historical: true };
1011
if (currencyParams.length > 0) {
1112
options.currencies = currencyParams;
@@ -22,7 +23,7 @@ export async function GET(request: NextRequest) {
2223

2324
return NextResponse.json(ratesObject);
2425
} catch (error) {
25-
console.error('Error fetching currency rates:', error);
26+
logger.error('Error fetching currency rates:', error);
2627
return NextResponse.json(
2728
{ error: 'Failed to fetch currency rates' },
2829
{ status: 500 }

src/components/Charts.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { type AppDispatch, Transaction, Account, Category } from '../types/redux
44
import dynamic from 'next/dynamic';
55
import moment, { Moment } from 'moment';
66
import { nest } from 'd3-collection';
7-
import { TransactionGroup } from '../types/app';
7+
import { type TransactionGroup, type CategoryExpense } from '../types/app';
88
import { sum } from 'd3-array';
99
import { createSelector } from 'reselect';
1010
import { uncategorized } from '../data/categories';
@@ -18,15 +18,6 @@ import AmountSumBar from './charts/AmountSumBar';
1818
import IncomeExpensesLine from './charts/IncomeExpensesLine';
1919
import Loading from './shared/Loading';
2020

21-
interface CategoryExpense {
22-
key: string;
23-
value: {
24-
amount: number;
25-
transactions: Transaction[];
26-
category: Category;
27-
};
28-
}
29-
3021
const CategoryExpenses = dynamic(() => import('./charts/CategoryExpenses'), {
3122
loading: () => <Loading />
3223
});
@@ -190,15 +181,15 @@ const getSortedCategoryExpenses = createSelector(
190181
[getIncomeAndExpenses],
191182
(incomeAndExpenses: Transaction[][]): CategoryExpense[] => {
192183
const expenses = incomeAndExpenses[1];
193-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
194-
return (nest() as any)
184+
return (nest<Transaction>()
195185
.key((d: Transaction) => (d.category as unknown as Category).id)
186+
// @ts-expect-error d3-collection types: .key() this-return doesn't track .rollup() generic
196187
.rollup((transactions: Transaction[]) => ({
197188
transactions,
198189
category: transactions[0].category as unknown as Category,
199190
amount: Math.abs(sum(transactions, (d: Transaction) => d.amount))
200191
}))
201-
.entries(expenses)
192+
.entries(expenses) as unknown as CategoryExpense[])
202193
.sort((a: CategoryExpense, b: CategoryExpense) => b.value.amount - a.value.amount);
203194
}
204195
);

src/components/Intro.test.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,21 @@ describe('Intro Component', () => {
7171
accounts: {
7272
data: []
7373
},
74-
edit: {},
74+
edit: {
75+
isCategoryGuessing: false,
76+
isParsing: false,
77+
isFetchingCurrencies: false,
78+
isFetchingCurrencyRates: false,
79+
dateSelect: {},
80+
transactionList: {
81+
page: 1,
82+
pageSize: 50,
83+
sortKey: 'date',
84+
sortAscending: false,
85+
filterCategories: new Set<string>()
86+
},
87+
charts: {}
88+
},
7589
search: {
7690
transactions: {
7791
text: '',

src/components/Transactions.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useState, useRef } from 'react';
22
import moment, { Moment } from 'moment';
33
import { useSelector, useDispatch } from 'react-redux';
44
import { type AppDispatch, type Transaction, type Category } from '../types/redux';
5-
import type { TransactionGroup } from '../types/app';
5+
import type { TransactionGroup, DisplayTransaction, DisplayTransactionGroup } from '../types/app';
66
import Link from 'next/link';
77
import { createSearchAction } from 'redux-search';
88
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
@@ -37,9 +37,8 @@ export default function Transactions() {
3737
return obj;
3838
}, {});
3939

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

5655
// Create an ID -> transactions mapping for easier tooltip'ing.
5756
const transactionGroupsObj = Object.entries(state.transactions.groups || {})
58-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59-
.reduce((obj: Record<string, { groupId: string; linkedTransactions: any[] }>, [groupId, group]: [string, TransactionGroup]) => {
57+
.reduce((obj: Record<string, DisplayTransactionGroup>, [groupId, group]: [string, TransactionGroup]) => {
6058
obj[group.primaryId] = {
6159
groupId,
6260
linkedTransactions: group.linkedIds.map((id: string) => transactionsData[reverseTransactionLookup[id]])

src/components/charts/AmountCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { formatNumber } from '../../util';
55

66
interface Account {
77
name: string;
8-
currency: string;
8+
currency?: string;
99
}
1010

1111
interface Amounts {

src/components/charts/AmountSumBar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { sum, ascending } from 'd3-array';
1414
import color from '../../data/color';
1515
import { formatNumber } from '../../util';
1616
import { Transaction } from '../../types/redux';
17+
import { type NestEntry } from '../../types/app';
1718

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

3031
return (
3132
<div className="chart">

0 commit comments

Comments
 (0)