A local-first personal finance app
:recycle: (typescript) migrated NetWorth component to TS (#3576)
Matiss Janis Aboltins38c5f89c4106
diff --git a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsxindex 09ca5d5746..109a5f2d65 100644--- a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx@@ -23,15 +23,28 @@ import { numberFormatterTooltip } from '../numberFormatter';type NetWorthGraphProps = {style?: CSSProperties;- graphData;- compact: boolean;+ graphData: {+ data: Array<{+ x: string;+ y: number;+ assets: string;+ debt: string;+ change: string;+ networth: string;+ date: string;+ }>;+ hasNegative: boolean;+ start: string;+ end: string;+ };+ compact?: boolean;showTooltip?: boolean;};export function NetWorthGraph({style,graphData,- compact,+ compact = false,showTooltip = true,}: NetWorthGraphProps) {const { t } = useTranslation();diff --git a/packages/desktop-client/src/components/reports/reports/NetWorth.jsx b/packages/desktop-client/src/components/reports/reports/NetWorth.tsxsimilarity index 92%rename from packages/desktop-client/src/components/reports/reports/NetWorth.jsxrename to packages/desktop-client/src/components/reports/reports/NetWorth.tsxindex 7f58ab8d04..5a75a58b95 100644--- a/packages/desktop-client/src/components/reports/reports/NetWorth.jsx+++ b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx@@ -10,6 +10,7 @@ import { useWidget } from 'loot-core/src/client/data-hooks/widget';import { send } from 'loot-core/src/platform/client/fetch';import * as monthUtils from 'loot-core/src/shared/months';import { integerToCurrency } from 'loot-core/src/shared/util';+import { type TimeFrame, type NetWorthWidget } from 'loot-core/types/models';import { useAccounts } from '../../../hooks/useAccounts';import { useFilters } from '../../../hooks/useFilters';@@ -33,7 +34,7 @@ import { fromDateRepr } from '../util';export function NetWorth() {const params = useParams();- const { data: widget, isLoading } = useWidget(+ const { data: widget, isLoading } = useWidget<NetWorthWidget>(params.id ?? '','net-worth-card',);@@ -45,14 +46,17 @@ export function NetWorth() {return <NetWorthInner widget={widget} />;}-function NetWorthInner({ widget }) {+type NetWorthInnerProps = {+ widget?: NetWorthWidget;+};++function NetWorthInner({ widget }: NetWorthInnerProps) {const dispatch = useDispatch();const { t } = useTranslation();const accounts = useAccounts();const {conditions,- saved,conditionsOp,onApply: onApplyFilter,onDelete: onDeleteFilter,@@ -60,7 +64,10 @@ function NetWorthInner({ widget }) {onConditionsOpChange,} = useFilters(widget?.meta?.conditions, widget?.meta?.conditionsOp);- const [allMonths, setAllMonths] = useState(null);+ const [allMonths, setAllMonths] = useState<Array<{+ name: string;+ pretty: string;+ }> | null>(null);const [initialStart, initialEnd, initialMode] = calculateTimeRange(widget?.meta?.timeFrame,@@ -103,15 +110,19 @@ function NetWorthInner({ widget }) {run();}, []);- function onChangeDates(start, end, mode) {+ function onChangeDates(start: string, end: string, mode: TimeFrame['mode']) {setStart(start);setEnd(end);setMode(mode);}async function onSaveWidget() {+ if (!widget) {+ throw new Error('No widget that could be saved.');+ }+await send('dashboard-update-widget', {- id: widget?.id,+ id: widget.id,meta: {...(widget.meta ?? {}),conditions,@@ -163,7 +174,6 @@ function NetWorthInner({ widget }) {mode={mode}onChangeDates={onChangeDates}filters={conditions}- saved={saved}onApply={onApplyFilter}onUpdateFilter={onUpdateFilter}onDeleteFilter={onDeleteFilter}@@ -203,12 +213,7 @@ function NetWorthInner({ widget }) {</View><NetWorthGraph- start={start}- end={end}graphData={data.graphData}- domain={{- y: [data.lowestNetWorth * 0.99, data.highestNetWorth * 1.01],- }}showTooltip={!isNarrowWidth}/>diff --git a/upcoming-release-notes/3576.md b/upcoming-release-notes/3576.mdnew file mode 100644index 0000000000..bcad219edc--- /dev/null+++ b/upcoming-release-notes/3576.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [MatissJanis]+---++TypeScript: migrate `NetWorth` component to TS.