A local-first personal finance app
Migrate top common components to TS (#979)
Alberto Gasparinf618055aabf4
diff --git a/.eslintrc.js b/.eslintrc.jsindex 608656cefb..bd1854c898 100644--- a/.eslintrc.js+++ b/.eslintrc.js@@ -1,3 +1,4 @@+/* eslint-disable rulesdir/typography */const path = require('path');const rulesDirPlugin = require('eslint-plugin-rulesdir');@@ -9,13 +10,26 @@ rulesDirPlugin.RULES_DIR = path.join('rules',);+const ruleFCMsg =+ 'Type the props argument and let TS infer or use ComponentType for a component prop';+module.exports = {plugins: ['prettier', 'import', 'rulesdir', '@typescript-eslint'],extends: ['react-app', 'plugin:@typescript-eslint/recommended'],+ parser: '@typescript-eslint/parser',+ parserOptions: { project: [path.join(__dirname, './tsconfig.json')] },reportUnusedDisableDirectives: true,rules: {'prettier/prettier': 'error','no-unused-vars': 'off',+ '@typescript-eslint/no-unused-vars': [+ 'error',+ {+ args: 'none',+ varsIgnorePattern: '^_',+ ignoreRestSiblings: true,+ },+ ],curly: ['error', 'multi-line', 'consistent'],@@ -64,18 +78,53 @@ module.exports = {},],+ 'no-restricted-syntax': [+ 'error',+ {+ // forbid React.* as they are legacy https://twitter.com/dan_abramov/status/1308739731551858689+ selector:+ ":matches(MemberExpression[object.name='React'], TSQualifiedName[left.name='React'])",+ message:+ 'Using default React import is discouraged, please use named exports directly instead.',+ },+ ],+// Rules disable during TS migration'@typescript-eslint/no-var-requires': 'off','prefer-const': 'off','prefer-spread': 'off','@typescript-eslint/no-empty-function': 'off',- '@typescript-eslint/no-unused-vars': [- 'error',- {- args: 'none',- varsIgnorePattern: '^_',- ignoreRestSiblings: true,- },- ],},+ overrides: [+ {+ files: ['./**/*.js'],+ parserOptions: { project: null },+ },+ {+ files: [+ './packages/desktop-client/**/*.{ts,tsx}',+ './packages/loot-core/src/client/**/*.{ts,tsx}',+ ],+ rules: {+ // enforce type over interface+ '@typescript-eslint/consistent-type-definitions': ['error', 'type'],+ // enforce import type+ '@typescript-eslint/consistent-type-imports': [+ 'error',+ { prefer: 'type-imports', fixStyle: 'inline-type-imports' },+ ],+ '@typescript-eslint/ban-types': [+ 'error',+ {+ types: {+ // forbid FC as superflous+ FunctionComponent: { message: ruleFCMsg },+ FC: { message: ruleFCMsg },+ },+ extendDefaults: true,+ },+ ],+ },+ },+ ],};diff --git a/packages/desktop-client/package.json b/packages/desktop-client/package.jsonindex cecb2e49ab..b8a22ae1da 100644--- a/packages/desktop-client/package.json+++ b/packages/desktop-client/package.json@@ -18,6 +18,10 @@"@svgr/cli": "^6.5.1","@testing-library/react": "14.0.0","@testing-library/user-event": "14.4.3",+ "@types/react": "^18.2.0",+ "@types/react-dom": "^18.2.1",+ "@types/react-modal": "^3.16.0",+ "@types/react-router-dom": "^5.3.3","chalk": "2.4.1","chroma-js": "^1.3.3","cross-env": "^7.0.3",diff --git a/packages/desktop-client/src/components/ActiveLocation.js b/packages/desktop-client/src/components/ActiveLocation.jsindex b0aa870db1..65b8a050b6 100644--- a/packages/desktop-client/src/components/ActiveLocation.js+++ b/packages/desktop-client/src/components/ActiveLocation.js@@ -1,6 +1,6 @@-import React, { useContext } from 'react';+import React, { createContext, useContext } from 'react';-let ActiveLocationContext = React.createContext(null);+let ActiveLocationContext = createContext(null);export function ActiveLocationProvider({ location, children }) {return (diff --git a/packages/desktop-client/src/components/App.js b/packages/desktop-client/src/components/App.jsindex 5568e7a6da..3fbc61eb67 100644--- a/packages/desktop-client/src/components/App.js+++ b/packages/desktop-client/src/components/App.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { Component } from 'react';import { connect } from 'react-redux';import { css } from 'glamor';@@ -19,7 +19,7 @@ import ManagementApp from './manager/ManagementApp';import MobileWebMessage from './MobileWebMessage';import UpdateNotification from './UpdateNotification';-class App extends React.Component {+class App extends Component {state = {fatalError: null,initializing: true,@@ -102,10 +102,10 @@ class App extends React.Component {])}>{fatalError ? (- <React.Fragment>+ <><AppBackground /><FatalError error={fatalError} buttonText="Restart app" />- </React.Fragment>+ </>) : initializing ? (<AppBackgroundinitializing={initializing}diff --git a/packages/desktop-client/src/components/AppBackground.js b/packages/desktop-client/src/components/AppBackground.jsindex d0bcc8adcb..26010f74c6 100644--- a/packages/desktop-client/src/components/AppBackground.js+++ b/packages/desktop-client/src/components/AppBackground.js@@ -10,7 +10,7 @@ import { View, Block } from './common';function AppBackground({ initializing, loadingText }) {return (- <React.Fragment>+ <><Background />{(loadingText != null || initializing) && (@@ -32,7 +32,7 @@ function AppBackground({ initializing, loadingText }) {<AnimatedLoading width={25} color={colors.n1} /></View>)}- </React.Fragment>+ </>);}diff --git a/packages/desktop-client/src/components/FatalError.js b/packages/desktop-client/src/components/FatalError.jsindex 1fdd59b7b2..785ecf4838 100644--- a/packages/desktop-client/src/components/FatalError.js+++ b/packages/desktop-client/src/components/FatalError.js@@ -1,11 +1,11 @@-import React, { useState } from 'react';+import React, { Component, useState } from 'react';import { colors } from '../style';import { View, Stack, Text, Block, Modal, P, Link, Button } from './common';import { Checkbox } from './forms';-class FatalError extends React.Component {+class FatalError extends Component {state = { showError: false };renderSimple(error) {diff --git a/packages/desktop-client/src/components/FinancesApp.js b/packages/desktop-client/src/components/FinancesApp.jsindex 1db5ae0533..61e4cfa12a 100644--- a/packages/desktop-client/src/components/FinancesApp.js+++ b/packages/desktop-client/src/components/FinancesApp.js@@ -1,4 +1,4 @@-import React, { useMemo } from 'react';+import React, { Component, useMemo } from 'react';import { DndProvider } from 'react-dnd';import Backend from 'react-dnd-html5-backend';import { connect } from 'react-redux';@@ -198,7 +198,7 @@ function MobileNavTabs() {);}-class FinancesApp extends React.Component {+class FinancesApp extends Component {constructor(props) {super(props);this.state = { isMobile: isMobile() };diff --git a/packages/desktop-client/src/components/FixedSizeList.js b/packages/desktop-client/src/components/FixedSizeList.jsindex 0c39dd6d7a..e811f65187 100644--- a/packages/desktop-client/src/components/FixedSizeList.js+++ b/packages/desktop-client/src/components/FixedSizeList.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { createRef, PureComponent } from 'react';import memoizeOne from 'memoize-one';@@ -15,7 +15,7 @@ function ResizeObserver({ onResize, children }) {return children(ref);}-export class FixedSizeList extends React.PureComponent {+export class FixedSizeList extends PureComponent {_outerRef;_resetIsScrollingTimeoutId = null;@@ -31,9 +31,9 @@ export class FixedSizeList extends React.PureComponent {constructor(props) {super(props);- this.lastPositions = React.createRef();+ this.lastPositions = createRef();this.lastPositions.current = new Map();- this.needsAnimationRerender = React.createRef();+ this.needsAnimationRerender = createRef();this.needsAnimationRerender.current = false;this.animationEnabled = false;diff --git a/packages/desktop-client/src/components/FloatableSidebar.js b/packages/desktop-client/src/components/FloatableSidebar.jsindex a8e1d49ca1..03f685586e 100644--- a/packages/desktop-client/src/components/FloatableSidebar.js+++ b/packages/desktop-client/src/components/FloatableSidebar.js@@ -1,4 +1,4 @@-import React, { useState, useContext, useMemo } from 'react';+import React, { createContext, useState, useContext, useMemo } from 'react';import { connect } from 'react-redux';import { withRouter } from 'react-router-dom';@@ -10,7 +10,7 @@ import { View } from './common';import { SIDEBAR_WIDTH } from './sidebar';import SidebarWithData from './SidebarWithData';-const SidebarContext = React.createContext(null);+const SidebarContext = createContext(null);export function SidebarProvider({ children }) {let [hidden, setHidden] = useState(true);diff --git a/packages/desktop-client/src/components/KeyHandlers.js b/packages/desktop-client/src/components/KeyHandlers.jsindex a814aed692..156b8c0199 100644--- a/packages/desktop-client/src/components/KeyHandlers.js+++ b/packages/desktop-client/src/components/KeyHandlers.js@@ -1,8 +1,8 @@-import React, { useEffect, useContext } from 'react';+import React, { createContext, useEffect, useContext } from 'react';import hotkeys from 'hotkeys-js';-let KeyScopeContext = React.createContext('app');+let KeyScopeContext = createContext('app');hotkeys.filter = event => {var target = event.target || event.srcElement;diff --git a/packages/desktop-client/src/components/ManageRules.js b/packages/desktop-client/src/components/ManageRules.jsindex 9249a8aa63..ca9b979cac 100644--- a/packages/desktop-client/src/components/ManageRules.js+++ b/packages/desktop-client/src/components/ManageRules.js@@ -1,4 +1,6 @@import React, {+ forwardRef,+ memo,useState,useEffect,useRef,@@ -297,7 +299,7 @@ export function ActionExpression({ field, op, value, options, style }) {);}-let Rule = React.memo(+let Rule = memo(({rule,hovered,@@ -411,7 +413,7 @@ let Rule = React.memo(},);-let SimpleTable = React.forwardRef(+let SimpleTable = forwardRef(({ data, navigator, loadMore, style, onHoverLeave, children, ...props },ref,diff --git a/packages/desktop-client/src/components/NotesButton.js b/packages/desktop-client/src/components/NotesButton.jsindex b3d03e311e..b6dcc1b000 100644--- a/packages/desktop-client/src/components/NotesButton.js+++ b/packages/desktop-client/src/components/NotesButton.js@@ -1,4 +1,4 @@-import React, { useState, useEffect, useMemo } from 'react';+import React, { createRef, useState, useEffect, useMemo } from 'react';import { css } from 'glamor';@@ -18,7 +18,7 @@ export function NotesTooltip({onClose,}) {let [notes, setNotes] = useState(defaultNotes);- let inputRef = React.createRef();+ let inputRef = createRef();useEffect(() => {if (editable) {diff --git a/packages/desktop-client/src/components/Page.js b/packages/desktop-client/src/components/Page.jsindex 5152c91a64..7c78170629 100644--- a/packages/desktop-client/src/components/Page.js+++ b/packages/desktop-client/src/components/Page.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { createContext, useContext } from 'react';import { useHistory } from 'react-router-dom';import { colors, styles } from '../style';@@ -6,7 +6,7 @@ import { isMobile } from '../util';import { Modal, View, Text } from './common';-let PageTypeContext = React.createContext({ type: 'page' });+let PageTypeContext = createContext({ type: 'page' });const HORIZONTAL_PADDING = isMobile() ? 10 : 20;@@ -19,7 +19,7 @@ export function PageTypeProvider({ type, current, children }) {}export function usePageType() {- return React.useContext(PageTypeContext);+ return useContext(PageTypeContext);}function PageTitle({ name, style }) {diff --git a/packages/desktop-client/src/components/Stack.js b/packages/desktop-client/src/components/Stack.jsindex 717e7bc03c..a15576734f 100644--- a/packages/desktop-client/src/components/Stack.js+++ b/packages/desktop-client/src/components/Stack.js@@ -1,12 +1,12 @@-import React from 'react';+import React, { Children, Fragment, cloneElement, forwardRef } from 'react';import Text from './common/Text';import View from './common/View';function getChildren(key, children) {- return React.Children.toArray(children).reduce((list, child) => {+ return Children.toArray(children).reduce((list, child) => {if (child) {- if (child.type === React.Fragment) {+ if (child.type === Fragment) {return list.concat(getChildren(child.key, child.props.children));}list.push({ key: key + child.key, child });@@ -16,7 +16,7 @@ function getChildren(key, children) {}, []);}-const Stack = React.forwardRef(+const Stack = forwardRef(({direction = 'column',@@ -57,7 +57,7 @@ const Stack = React.forwardRef(marginProp = isReversed ? 'marginTop' : 'marginBottom';}- return React.cloneElement(+ return cloneElement(typeof child === 'string' ? <Text>{child}</Text> : child,{key,diff --git a/packages/desktop-client/src/components/Titlebar.js b/packages/desktop-client/src/components/Titlebar.jsindex 618c81fd37..2aff10480b 100644--- a/packages/desktop-client/src/components/Titlebar.js+++ b/packages/desktop-client/src/components/Titlebar.js@@ -1,4 +1,10 @@-import React, { useState, useEffect, useRef, useContext } from 'react';+import React, {+ createContext,+ useState,+ useEffect,+ useRef,+ useContext,+} from 'react';import { connect } from 'react-redux';import { Switch, Route, withRouter } from 'react-router-dom';@@ -33,7 +39,7 @@ import LoggedInUser from './LoggedInUser';import { useServerURL } from './ServerContext';import SheetValue from './spreadsheet/SheetValue';-export let TitlebarContext = React.createContext();+export let TitlebarContext = createContext();export function TitlebarProvider({ children }) {let listeners = useRef([]);diff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.jsindex 58c0c4e19a..b5fe9fe4c1 100644--- a/packages/desktop-client/src/components/accounts/Account.js+++ b/packages/desktop-client/src/components/accounts/Account.js@@ -1,4 +1,11 @@-import React, { useState, useRef, useMemo } from 'react';+import React, {+ PureComponent,+ createRef,+ memo,+ useState,+ useRef,+ useMemo,+} from 'react';import { useSelector, useDispatch } from 'react-redux';import { Redirect, useParams, useHistory, useLocation } from 'react-router-dom';@@ -627,7 +634,7 @@ function SelectedTransactionsButton({);}-const AccountHeader = React.memo(+const AccountHeader = memo(({tableRef,editingName,@@ -1037,11 +1044,11 @@ function AllTransactions({ account = {}, transactions, filtered, children }) {return children(allTransactions);}-class AccountInternal extends React.PureComponent {+class AccountInternal extends PureComponent {constructor(props) {super(props);this.paged = null;- this.table = React.createRef();+ this.table = createRef();this.animated = true;this.state = {diff --git a/packages/desktop-client/src/components/accounts/MobileAccounts.js b/packages/desktop-client/src/components/accounts/MobileAccounts.jsindex 475f18589a..6604e1960f 100644--- a/packages/desktop-client/src/components/accounts/MobileAccounts.js+++ b/packages/desktop-client/src/components/accounts/MobileAccounts.js@@ -1,4 +1,4 @@-import React, { useEffect, useState } from 'react';+import React, { Component, useEffect, useState } from 'react';import { connect } from 'react-redux';import { useNavigate } from 'react-router-dom-v5-compat';@@ -164,7 +164,7 @@ function EmptyMessage({ onAdd }) {);}-export class AccountList extends React.Component {+export class AccountList extends Component {isNewTransaction = id => {return this.props.newTransactions.includes(id);};diff --git a/packages/desktop-client/src/components/accounts/MobileTransaction.js b/packages/desktop-client/src/components/accounts/MobileTransaction.jsindex 7bd152d5d3..ec2999aa23 100644--- a/packages/desktop-client/src/components/accounts/MobileTransaction.js+++ b/packages/desktop-client/src/components/accounts/MobileTransaction.js@@ -1,4 +1,10 @@-import React, { useEffect } from 'react';+import React, {+ PureComponent,+ Component,+ forwardRef,+ useEffect,+ useRef,+} from 'react';import { useFocusRing } from '@react-aria/focus';import { useListBox, useListBoxSection, useOption } from '@react-aria/listbox';@@ -88,7 +94,7 @@ function Status({ status }) {);}-export class Transaction extends React.PureComponent {+export class Transaction extends PureComponent {render() {const {transaction,@@ -233,7 +239,7 @@ export class Transaction extends React.PureComponent {}}-export class TransactionList extends React.Component {+export class TransactionList extends Component {makeData = memoizeOne(transactions => {// Group by date. We can assume transactions is orderedconst sections = [];@@ -339,7 +345,7 @@ export class TransactionList extends React.Component {function ListBox(props) {let state = useListState(props);- let listBoxRef = React.useRef();+ let listBoxRef = useRef();let { listBoxProps, labelProps } = useListBox(props, state, listBoxRef);useEffect(() => {@@ -439,7 +445,7 @@ function ListBoxSection({ section, state }) {function Option({ isLast, item, state }) {// Get props for the option element- let ref = React.useRef();+ let ref = useRef();let { optionProps, isSelected } = useOption({ key: item.key }, state, ref);// Determine whether we should show a keyboard@@ -464,25 +470,23 @@ function Option({ isLast, item, state }) {export const ROW_HEIGHT = 50;-export const ListItem = React.forwardRef(- ({ children, style, ...props }, ref) => {- return (- <View- style={[- {- height: ROW_HEIGHT,- flexDirection: 'row',- alignItems: 'center',- paddingLeft: 10,- paddingRight: 10,- },- style,- ]}- ref={ref}- {...props}- >- {children}- </View>- );- },-);+export const ListItem = forwardRef(({ children, style, ...props }, ref) => {+ return (+ <View+ style={[+ {+ height: ROW_HEIGHT,+ flexDirection: 'row',+ alignItems: 'center',+ paddingLeft: 10,+ paddingRight: 10,+ },+ style,+ ]}+ ref={ref}+ {...props}+ >+ {children}+ </View>+ );+});diff --git a/packages/desktop-client/src/components/accounts/SimpleTransactionsTable.js b/packages/desktop-client/src/components/accounts/SimpleTransactionsTable.jsindex 9252c57801..dad8e1afd4 100644--- a/packages/desktop-client/src/components/accounts/SimpleTransactionsTable.js+++ b/packages/desktop-client/src/components/accounts/SimpleTransactionsTable.js@@ -1,4 +1,4 @@-import React, { useMemo, useCallback } from 'react';+import React, { memo, useMemo, useCallback } from 'react';import { useSelector } from 'react-redux';import {@@ -32,7 +32,7 @@ function serializeTransaction(transaction, dateFormat) {};}-const TransactionRow = React.memo(function TransactionRow({+const TransactionRow = memo(function TransactionRow({transaction,fields,payees,diff --git a/packages/desktop-client/src/components/accounts/TransactionsTable.js b/packages/desktop-client/src/components/accounts/TransactionsTable.jsindex a93a5e25b1..1430124989 100644--- a/packages/desktop-client/src/components/accounts/TransactionsTable.js+++ b/packages/desktop-client/src/components/accounts/TransactionsTable.js@@ -1,4 +1,9 @@import React, {+ createContext,+ createElement,+ createRef,+ forwardRef,+ memo,useState,useRef,useMemo,@@ -136,7 +141,7 @@ function isLastChild(transactions, index) {);}-let SplitsExpandedContext = React.createContext(null);+let SplitsExpandedContext = createContext(null);export function useSplitsExpanded() {let data = useContext(SplitsExpandedContext);@@ -231,7 +236,7 @@ export function SplitsExpandedProvider({ children, initialMode = 'expand' }) {);}-export const TransactionHeader = React.memo(+export const TransactionHeader = memo(({ hasSelected, showAccount, showCategory, showBalance, showCleared }) => {let dispatchSelected = useSelectedDispatch();@@ -363,7 +368,7 @@ function StatusCell({onEdit={() => onEdit(id, 'cleared')}onSelect={onSelect}>- {React.createElement(statusProps.Icon, {+ {createElement(statusProps.Icon, {style: {width: 13,height: 13,@@ -491,7 +496,7 @@ function CellWithScheduleIcon({ scheduleId, children }) {);}-export const Transaction = React.memo(function Transaction(props) {+export const Transaction = memo(function Transaction(props) {let {transaction: originalTransaction,editing,@@ -1240,7 +1245,7 @@ function TransactionTableInner({onScroll,...props}) {- const containerRef = React.createRef();+ const containerRef = createRef();const isAddingPrev = usePrevious(props.isAdding);useEffect(() => {@@ -1427,7 +1432,7 @@ function TransactionTableInner({);}-export let TransactionTable = React.forwardRef((props, ref) => {+export let TransactionTable = forwardRef((props, ref) => {let [newTransactions, setNewTransactions] = useState(null);let [hoveredTransaction, setHoveredTransaction] = useState(props.hoveredTransaction,diff --git a/packages/desktop-client/src/components/alerts.tsx b/packages/desktop-client/src/components/alerts.tsxindex 0fcd81af30..bf04311da3 100644--- a/packages/desktop-client/src/components/alerts.tsx+++ b/packages/desktop-client/src/components/alerts.tsx@@ -1,4 +1,4 @@-import React from 'react';+import React, { type ComponentType, type ReactNode } from 'react';import type { CSSProperties } from 'glamor';@@ -9,21 +9,21 @@ import { styles, colors } from '../style';import Text from './common/Text';import View from './common/View';-interface AlertProps {- icon?: React.FC<{ width?: number; style?: CSSProperties }>;+type AlertProps = {+ icon?: ComponentType<{ width?: number; style?: CSSProperties }>;color?: string;backgroundColor?: string;style?: CSSProperties;- children?: React.ReactNode;-}+ children?: ReactNode;+};-export const Alert: React.FC<AlertProps> = ({+export const Alert = ({icon: Icon,color,backgroundColor,style,children,-}) => {+}: AlertProps) => {return (<Viewstyle={[@@ -58,15 +58,12 @@ export const Alert: React.FC<AlertProps> = ({);};-interface ScopedAlertProps {+type ScopedAlertProps = {style?: CSSProperties;- children?: React.ReactNode;-}+ children?: ReactNode;+};-export const Information: React.FC<ScopedAlertProps> = ({- style,- children,-}) => {+export const Information = ({ style, children }: ScopedAlertProps) => {return (<Alerticon={InformationOutline}@@ -79,7 +76,7 @@ export const Information: React.FC<ScopedAlertProps> = ({);};-export const Warning: React.FC<ScopedAlertProps> = ({ style, children }) => {+export const Warning = ({ style, children }: ScopedAlertProps) => {return (<Alerticon={ExclamationOutline}@@ -92,7 +89,7 @@ export const Warning: React.FC<ScopedAlertProps> = ({ style, children }) => {);};-export const Error: React.FC<ScopedAlertProps> = ({ style, children }) => {+export const Error = ({ style, children }: ScopedAlertProps) => {return (<Alerticon={ExclamationOutline}diff --git a/packages/desktop-client/src/components/autocomplete/CategorySelect.js b/packages/desktop-client/src/components/autocomplete/CategorySelect.jsindex b692376a39..7579baf9a2 100644--- a/packages/desktop-client/src/components/autocomplete/CategorySelect.js+++ b/packages/desktop-client/src/components/autocomplete/CategorySelect.js@@ -1,4 +1,4 @@-import React, { useMemo } from 'react';+import React, { Fragment, forwardRef, useMemo } from 'react';import Split from '../../icons/v0/Split';import { colors } from '../../style';@@ -6,7 +6,7 @@ import { View, Text, Select } from '../common';import Autocomplete, { defaultFilterSuggestion } from './Autocomplete';-export const NativeCategorySelect = React.forwardRef(+export const NativeCategorySelect = forwardRef(({ categoryGroups, emptyLabel, ...nativeProps }, ref) => {return (<Select {...nativeProps} ref={ref}>@@ -80,7 +80,7 @@ export function CategoryList({const showGroup = item.cat_group !== lastGroup;lastGroup = item.cat_group;return (- <React.Fragment key={item.id}>+ <Fragment key={item.id}>{showGroup && (<divstyle={{@@ -108,7 +108,7 @@ export function CategoryList({>{item.name}</div>- </React.Fragment>+ </Fragment>);})}</View>diff --git a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.js b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.jsindex 1ecbf0d727..d826bc1fb3 100644--- a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.js+++ b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.js@@ -1,4 +1,4 @@-import React, { useState, useMemo } from 'react';+import React, { Fragment, useState, useMemo } from 'react';import { useDispatch } from 'react-redux';import { createPayee } from 'loot-core/src/client/actions/queries';@@ -120,7 +120,7 @@ export function PayeeList({lastType = type;return (- <React.Fragment key={item.id}>+ <Fragment key={item.id}>{title && (<divkey={'title-' + idx}@@ -161,7 +161,7 @@ export function PayeeList({More payees are available, search to find them</div>)}- </React.Fragment>+ </Fragment>);})}</View>diff --git a/packages/desktop-client/src/components/budget/BudgetMonthCountContext.js b/packages/desktop-client/src/components/budget/BudgetMonthCountContext.jsindex 7e7d2c513f..489cb938ec 100644--- a/packages/desktop-client/src/components/budget/BudgetMonthCountContext.js+++ b/packages/desktop-client/src/components/budget/BudgetMonthCountContext.js@@ -1,6 +1,6 @@-import React, { useContext, useState } from 'react';+import React, { createContext, useContext, useState } from 'react';-export let BudgetMonthCountContext = React.createContext();+export let BudgetMonthCountContext = createContext();export function BudgetMonthCountProvider({ children }) {let [displayMax, setDisplayMax] = useState(1);diff --git a/packages/desktop-client/src/components/budget/DynamicBudgetTable.js b/packages/desktop-client/src/components/budget/DynamicBudgetTable.jsindex 98256999b6..5acac8e161 100644--- a/packages/desktop-client/src/components/budget/DynamicBudgetTable.js+++ b/packages/desktop-client/src/components/budget/DynamicBudgetTable.js@@ -1,4 +1,4 @@-import React, { useEffect } from 'react';+import React, { forwardRef, useEffect } from 'react';import AutoSizer from 'react-virtualized-auto-sizer';import { View } from '../common';@@ -25,7 +25,7 @@ function getNumPossibleMonths(width) {return 6;}-const DynamicBudgetTableInner = React.forwardRef(+const DynamicBudgetTableInner = forwardRef(({width,@@ -88,7 +88,7 @@ const DynamicBudgetTableInner = React.forwardRef(},);-export default React.forwardRef((props, ref) => {+export default forwardRef((props, ref) => {return (<AutoSizer>{({ width, height }) => (diff --git a/packages/desktop-client/src/components/budget/MobileBudget.js b/packages/desktop-client/src/components/budget/MobileBudget.jsindex e53638b28a..e2f2bc9830 100644--- a/packages/desktop-client/src/components/budget/MobileBudget.js+++ b/packages/desktop-client/src/components/budget/MobileBudget.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { Component } from 'react';import { connect } from 'react-redux';import * as actions from 'loot-core/src/client/actions';@@ -19,7 +19,7 @@ import SyncRefresh from '../SyncRefresh';import { BudgetTable } from './MobileBudgetTable';-class Budget extends React.Component {+class Budget extends Component {constructor(props) {super(props);diff --git a/packages/desktop-client/src/components/budget/MobileBudgetTable.js b/packages/desktop-client/src/components/budget/MobileBudgetTable.jsindex ad099a268e..b2cf6ed06f 100644--- a/packages/desktop-client/src/components/budget/MobileBudgetTable.js+++ b/packages/desktop-client/src/components/budget/MobileBudgetTable.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { Component, PureComponent } from 'react';// import {// RectButton,// PanGestureHandler,@@ -99,7 +99,7 @@ function Saved({ projected }) {);}-export class BudgetCell extends React.PureComponent {+export class BudgetCell extends PureComponent {render() {const {name,@@ -237,7 +237,7 @@ function BudgetCategoryPreview({ name, pending, style }) {);}-export class BudgetCategory extends React.PureComponent {+export class BudgetCategory extends PureComponent {constructor(props) {super(props);@@ -364,7 +364,7 @@ export class BudgetCategory extends React.PureComponent {}}-export class TotalsRow extends React.PureComponent {+export class TotalsRow extends PureComponent {constructor(props) {super(props);@@ -483,7 +483,7 @@ export class TotalsRow extends React.PureComponent {}}-export class IncomeCategory extends React.PureComponent {+export class IncomeCategory extends PureComponent {render() {const { name, budget, balance, style, nameTextStyle, amountTextStyle } =this.props;@@ -568,7 +568,7 @@ export class IncomeCategory extends React.PureComponent {// );// }-export class BudgetGroup extends React.PureComponent {+export class BudgetGroup extends PureComponent {render() {const {group,@@ -650,7 +650,7 @@ export class BudgetGroup extends React.PureComponent {}}-export class IncomeBudgetGroup extends React.Component {+export class IncomeBudgetGroup extends Component {render() {const { type, group } = this.props;return (@@ -713,7 +713,7 @@ export class IncomeBudgetGroup extends React.Component {}}-export class BudgetGroups extends React.Component {+export class BudgetGroups extends Component {getGroups = memoizeOne(groups => {return {incomeGroup: groups.find(group => group.is_income),@@ -766,7 +766,7 @@ export class BudgetGroups extends React.Component {}}-export class BudgetTable extends React.Component {+export class BudgetTable extends Component {// static contextType = AmountAccessoryContext;state = { editingCategory: null };@@ -979,7 +979,7 @@ export class BudgetTable extends React.Component {// scrollRef,// onScroll// }) => (- <React.Fragment>+ <><View><BudgetGroupscategoryGroups={categoryGroups}@@ -994,7 +994,7 @@ export class BudgetTable extends React.Component {</View>{/* <DragDropHighlight /> */}- </React.Fragment>+ </>// )}// </DragDrop>)}diff --git a/packages/desktop-client/src/components/budget/MonthsContext.js b/packages/desktop-client/src/components/budget/MonthsContext.jsindex cbddaac648..dd321a75a9 100644--- a/packages/desktop-client/src/components/budget/MonthsContext.js+++ b/packages/desktop-client/src/components/budget/MonthsContext.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { createContext } from 'react';import * as monthUtils from 'loot-core/src/shared/months';@@ -9,7 +9,7 @@ export function getValidMonthBounds(bounds, startMonth, endMonth) {};}-export let MonthsContext = React.createContext();+export let MonthsContext = createContext();export function MonthsProvider({startMonth,diff --git a/packages/desktop-client/src/components/budget/index.js b/packages/desktop-client/src/components/budget/index.jsindex ca479d03ce..602b071a2e 100644--- a/packages/desktop-client/src/components/budget/index.js+++ b/packages/desktop-client/src/components/budget/index.js@@ -1,4 +1,4 @@-import React, { useContext, useMemo } from 'react';+import React, { memo, PureComponent, useContext, useMemo } from 'react';import { connect } from 'react-redux';import * as actions from 'loot-core/src/client/actions';@@ -30,7 +30,7 @@ import { RolloverContext } from './rollover/RolloverContext';let _initialBudgetMonth = null;-class Budget extends React.PureComponent {+class Budget extends PureComponent {constructor(props) {super(props);@@ -497,7 +497,7 @@ class Budget extends React.PureComponent {}}-const RolloverBudgetSummary = React.memo(props => {+const RolloverBudgetSummary = memo(props => {const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');return (<rollover.BudgetSummarydiff --git a/packages/desktop-client/src/components/budget/misc.js b/packages/desktop-client/src/components/budget/misc.jsindex dba9a2418a..c3f569fb0c 100644--- a/packages/desktop-client/src/components/budget/misc.js+++ b/packages/desktop-client/src/components/budget/misc.js@@ -1,4 +1,11 @@-import React, { useContext, useState, useMemo } from 'react';+import React, {+ createRef,+ memo,+ Component,+ useContext,+ useState,+ useMemo,+} from 'react';import * as monthUtils from 'loot-core/src/shared/months';@@ -35,10 +42,10 @@ function getScrollbarWidth() {return Math.max(styles.scrollbarWidth - 2, 0);}-export class BudgetTable extends React.Component {+export class BudgetTable extends Component {constructor(props) {super(props);- this.budgetCategoriesRef = React.createRef();+ this.budgetCategoriesRef = createRef();this.state = {editing: null,@@ -605,7 +612,7 @@ function RenderMonths({ component: Component, editingIndex, args, style }) {});}-const BudgetTotals = React.memo(function BudgetTotals({ MonthComponent }) {+const BudgetTotals = memo(function BudgetTotals({ MonthComponent }) {return (<Viewdata-testid="budget-totals"@@ -906,7 +913,7 @@ function IncomeCategory({);}-const BudgetCategories = React.memo(+const BudgetCategories = memo(({categoryGroups,newCategoryForGroup,@@ -1209,7 +1216,7 @@ function IncomeHeader({ MonthComponent, onShowNewGroup }) {);}-export const BudgetPageHeader = React.memo(+export const BudgetPageHeader = memo(({ startMonth, onMonthSelect, numMonths, monthBounds, style }) => {function getValidMonth(month) {let start = monthBounds.start;diff --git a/packages/desktop-client/src/components/budget/report/BudgetSummary.js b/packages/desktop-client/src/components/budget/report/BudgetSummary.jsindex 1b0e46f676..7dcc057857 100644--- a/packages/desktop-client/src/components/budget/report/BudgetSummary.js+++ b/packages/desktop-client/src/components/budget/report/BudgetSummary.js@@ -1,4 +1,4 @@-import React, { useState } from 'react';+import React, { memo, useState } from 'react';import { css } from 'glamor';@@ -239,7 +239,7 @@ function Saved({ projected, style }) {);}-export const BudgetSummary = React.memo(function BudgetSummary({ month }) {+export const BudgetSummary = memo(function BudgetSummary({ month }) {let {currentMonth,summaryCollapsed: collapsed,diff --git a/packages/desktop-client/src/components/budget/report/ReportContext.js b/packages/desktop-client/src/components/budget/report/ReportContext.jsindex 2edbab4018..09dd444be7 100644--- a/packages/desktop-client/src/components/budget/report/ReportContext.js+++ b/packages/desktop-client/src/components/budget/report/ReportContext.js@@ -1,8 +1,8 @@-import React, { useContext } from 'react';+import React, { createContext, useContext } from 'react';import * as monthUtils from 'loot-core/src/shared/months';-let Context = React.createContext(null);+let Context = createContext(null);export function ReportProvider({summaryCollapsed,diff --git a/packages/desktop-client/src/components/budget/report/components.js b/packages/desktop-client/src/components/budget/report/components.jsindex ccee65210f..b68192611e 100644--- a/packages/desktop-client/src/components/budget/report/components.js+++ b/packages/desktop-client/src/components/budget/report/components.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { memo } from 'react';import { reportBudget } from 'loot-core/src/client/queries';import evalArithmetic from 'loot-core/src/shared/arithmetic';@@ -18,7 +18,7 @@ export { BudgetSummary } from './BudgetSummary';let headerLabelStyle = { flex: 1, padding: '0 5px', textAlign: 'right' };-export const BudgetTotalsMonth = React.memo(function BudgetTotalsMonth() {+export const BudgetTotalsMonth = memo(function BudgetTotalsMonth() {return (<Viewstyle={{@@ -79,7 +79,7 @@ export function IncomeHeaderMonth() {);}-export const GroupMonth = React.memo(function ExpenseGroupMonth({ group }) {+export const GroupMonth = memo(function ExpenseGroupMonth({ group }) {let borderColor = colors.border;let { id } = group;@@ -158,7 +158,7 @@ function BalanceTooltip({ categoryId, tooltip, monthIndex, onBudgetAction }) {);}-export const CategoryMonth = React.memo(function CategoryMonth({+export const CategoryMonth = memo(function CategoryMonth({monthIndex,category,budgeted,diff --git a/packages/desktop-client/src/components/budget/rollover/RolloverContext.js b/packages/desktop-client/src/components/budget/rollover/RolloverContext.jsindex fb7223c4e7..c3a00bec39 100644--- a/packages/desktop-client/src/components/budget/rollover/RolloverContext.js+++ b/packages/desktop-client/src/components/budget/rollover/RolloverContext.js@@ -1,8 +1,8 @@-import React, { useContext } from 'react';+import React, { createContext, useContext } from 'react';import * as monthUtils from 'loot-core/src/shared/months';-let Context = React.createContext(null);+let Context = createContext(null);export function RolloverContext({categoryGroups,diff --git a/packages/desktop-client/src/components/budget/rollover/rollover-components.js b/packages/desktop-client/src/components/budget/rollover/rollover-components.jsindex dfdb7e815d..a604d22cea 100644--- a/packages/desktop-client/src/components/budget/rollover/rollover-components.js+++ b/packages/desktop-client/src/components/budget/rollover/rollover-components.js@@ -1,4 +1,4 @@-import React, { useContext, useState } from 'react';+import React, { memo, useContext, useState } from 'react';import { rolloverBudget } from 'loot-core/src/client/queries';import evalArithmetic from 'loot-core/src/shared/arithmetic';@@ -181,7 +181,7 @@ function BalanceTooltip({ categoryId, tooltip, monthIndex, onBudgetAction }) {let headerLabelStyle = { flex: 1, padding: '0 5px', textAlign: 'right' };-export const BudgetTotalsMonth = React.memo(function BudgetTotalsMonth() {+export const BudgetTotalsMonth = memo(function BudgetTotalsMonth() {return (<Viewstyle={{@@ -237,9 +237,7 @@ export function IncomeHeaderMonth() {);}-export const ExpenseGroupMonth = React.memo(function ExpenseGroupMonth({- group,-}) {+export const ExpenseGroupMonth = memo(function ExpenseGroupMonth({ group }) {let borderColor = colors.border;let { id } = group;@@ -285,7 +283,7 @@ export const ExpenseGroupMonth = React.memo(function ExpenseGroupMonth({);});-export const ExpenseCategoryMonth = React.memo(function ExpenseCategoryMonth({+export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({monthIndex,category,editing,diff --git a/packages/desktop-client/src/components/budget/util.js b/packages/desktop-client/src/components/budget/util.jsindex 978c5a9313..a1ae12712d 100644--- a/packages/desktop-client/src/components/budget/util.js+++ b/packages/desktop-client/src/components/budget/util.js@@ -1,8 +1,8 @@-import React from 'react';+import { createContext } from 'react';import { colors } from '../../style';-export let CategoryGroupsContext = React.createContext([]);+export let CategoryGroupsContext = createContext([]);export function addToBeBudgetedGroup(groups) {return [diff --git a/packages/desktop-client/src/components/common.js b/packages/desktop-client/src/components/common.tsxsimilarity index 69%rename from packages/desktop-client/src/components/common.jsrename to packages/desktop-client/src/components/common.tsxindex a8129fc7b0..e2fa996f3c 100644--- a/packages/desktop-client/src/components/common.js+++ b/packages/desktop-client/src/components/common.tsx@@ -4,7 +4,16 @@ import React, {useLayoutEffect,useState,useCallback,+ type ChangeEvent,+ type ComponentProps,+ type ReactElement,+ type ReactNode,+ type Ref,+ forwardRef,+ createElement,+ cloneElement,} from 'react';+import type { RouteComponentProps } from 'react-router';import { Route, NavLink, withRouter, useRouteMatch } from 'react-router-dom';import {@@ -14,12 +23,11 @@ import {ListboxList,ListboxOption,} from '@reach/listbox';-import { css } from 'glamor';--import { integerToCurrency } from 'loot-core/src/shared/util';+import { type CSSProperties, css } from 'glamor';import ExpandArrow from '../icons/v0/ExpandArrow';import { styles, colors } from '../style';+import type { HTMLPropsWithStyle } from '../types/utils';import Button from './common/Button';import Input, { defaultInputStyle } from './common/Input';@@ -33,7 +41,9 @@ export { default as View } from './common/View';export { default as Text } from './common/Text';export { default as Stack } from './Stack';-export function TextOneLine({ children, ...props }) {+type TextOneLineProps = ComponentProps<typeof Text>;++export function TextOneLine({ children, ...props }: TextOneLineProps) {return (<Text{...props}@@ -52,10 +62,12 @@ export function TextOneLine({ children, ...props }) {);}-export const useStableCallback = callback => {- const callbackRef = useRef();+type UseStableCallbackArg = (...args: unknown[]) => unknown;++export const useStableCallback = (callback: UseStableCallbackArg) => {+ const callbackRef = useRef<UseStableCallbackArg>();const memoCallback = useCallback(- (...args) => callbackRef.current(...args),+ (...args) => callbackRef.current && callbackRef.current(...args),[],);useLayoutEffect(() => {@@ -64,7 +76,11 @@ export const useStableCallback = callback => {return memoCallback;};-export function Block(props) {+type BlockProps = HTMLPropsWithStyle<HTMLDivElement> & {+ innerRef?: Ref<HTMLDivElement>;+};++export function Block(props: BlockProps) {const { style, innerRef, ...restProps } = props;return (<div@@ -75,37 +91,43 @@ export function Block(props) {);}-export const Card = React.forwardRef(({ children, ...props }, ref) => {- return (- <View- {...props}- ref={ref}- style={[- {- marginTop: 15,- marginLeft: 5,- marginRight: 5,- borderRadius: 6,- backgroundColor: 'white',- borderColor: colors.p3,- boxShadow: '0 1px 2px #9594A8',- },- props.style,- ]}- >+type CardProps = ComponentProps<typeof View>;++export const Card = forwardRef<HTMLDivElement, CardProps>(+ ({ children, ...props }, ref) => {+ return (<View- style={{- borderRadius: 6,- overflow: 'hidden',- }}+ {...props}+ ref={ref}+ style={[+ {+ marginTop: 15,+ marginLeft: 5,+ marginRight: 5,+ borderRadius: 6,+ backgroundColor: 'white',+ borderColor: colors.p3,+ boxShadow: '0 1px 2px #9594A8',+ },+ props.style,+ ]}>- {children}+ <View+ style={{+ borderRadius: 6,+ overflow: 'hidden',+ }}+ >+ {children}+ </View></View>- </View>- );-});+ );+ },+);++type LinkProps = ComponentProps<typeof Button>;-export function Link({ style, children, ...nativeProps }) {+export function Link({ style, children, ...nativeProps }: LinkProps) {return (<Button{...css(@@ -131,7 +153,21 @@ export function Link({ style, children, ...nativeProps }) {);}-export function AnchorLink({ to, exact, style, activeStyle, children }) {+type AnchorLinkProps = {+ to: string;+ exact: boolean;+ style?: CSSProperties;+ activeStyle?: CSSProperties;+ children?: ReactNode;+};++export function AnchorLink({+ to,+ exact,+ style,+ activeStyle,+ children,+}: AnchorLinkProps) {let match = useRouteMatch({ path: to, exact: true });return (@@ -145,7 +181,15 @@ export function AnchorLink({ to, exact, style, activeStyle, children }) {);}-export const ExternalLink = React.forwardRef(+type ExternalLinkAnchorProps = {+ asAnchor: true;+} & HTMLPropsWithStyle<HTMLAnchorElement>;+type ExternalLinkButtonProps = { asAnchor: false | undefined } & ComponentProps<+ typeof Button+>;+type ExternalLinkProps = ExternalLinkAnchorProps | ExternalLinkButtonProps;++export const ExternalLink = forwardRef<HTMLElement, ExternalLinkProps>(({ asAnchor, children, ...props }, ref) => {function onClick(e) {e.preventDefault();@@ -154,19 +198,33 @@ export const ExternalLink = React.forwardRef(if (asAnchor) {return (- <a ref={ref} {...props} onClick={onClick}>+ <a+ ref={ref as Ref<HTMLAnchorElement>}+ {...(props as ExternalLinkAnchorProps)}+ onClick={onClick}+ >{children}</a>);}return (- <Button ref={ref} bare {...props} onClick={onClick}>+ <Button+ ref={ref as Ref<HTMLButtonElement>}+ bare+ {...(props as ExternalLinkButtonProps)}+ onClick={onClick}+ >{children}</Button>);},);+type ButtonLinkProps = ComponentProps<typeof Button> &+ RouteComponentProps & {+ to: string;+ activeStyle?: CSSProperties;+ };function ButtonLink_({history,staticContext,@@ -176,7 +234,7 @@ function ButtonLink_({match,location,...props-}) {+}: ButtonLinkProps) {return (<Routepath={to}@@ -196,6 +254,13 @@ function ButtonLink_({export const ButtonLink = withRouter(ButtonLink_);+type InputWithContentProps = ComponentProps<typeof Input> & {+ leftContent: ReactNode;+ rightContent: ReactNode;+ inputStyle?: CSSProperties;+ style?: CSSProperties;+ getStyle?: (focused: boolean) => CSSProperties;+};export function InputWithContent({leftContent,rightContent,@@ -203,7 +268,7 @@ export function InputWithContent({style,getStyle,...props-}) {+}: InputWithContentProps) {let [focused, setFocused] = useState(false);return (@@ -253,6 +318,14 @@ export function InputWithContent({);}+type SearchProps = {+ inputRef: Ref<HTMLInputElement>;+ value: string;+ onChange: (value: string) => unknown;+ placeholder: string;+ isInModal: boolean;+ width?: number;+};export function Search({inputRef,value,@@ -260,13 +333,13 @@ export function Search({placeholder,isInModal,width = 350,-}) {+}: SearchProps) {return (<InputinputRef={inputRef}placeholder={placeholder}value={value}- onChange={e => onChange(e.target.value)}+ onChange={(e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value)}style={{width,borderColor: isInModal ? null : 'transparent',@@ -282,7 +355,14 @@ export function Search({);}-export function KeyboardButton({ highlighted, children, ...props }) {+type KeyboardButtonProps = ComponentProps<typeof Button> & {+ highlighted?: boolean;+};+export function KeyboardButton({+ highlighted,+ children,+ ...props+}: KeyboardButtonProps) {return (<Button{...props}@@ -309,7 +389,9 @@ export function KeyboardButton({ highlighted, children, ...props }) {);}-export const Select = React.forwardRef(+type SelectProps = HTMLPropsWithStyle<HTMLSelectElement>;++export const Select = forwardRef<HTMLSelectElement, SelectProps>(({ style, children, ...nativeProps }, ref) => {return (<select@@ -339,13 +421,21 @@ export const Select = React.forwardRef(},);+type CustomSelectProps = {+ options: Array<[string, string]>;+ value: string;+ onChange?: (newValue: string) => void;+ style?: CSSProperties;+ disabledKeys?: string[];+};+export function CustomSelect({options,value,onChange,style,disabledKeys = [],-}) {+}: CustomSelectProps) {return (<ListboxInputvalue={value}@@ -373,11 +463,37 @@ export function CustomSelect({);}-export function Keybinding({ keyName }) {+type KeybindingProps = {+ keyName: ReactNode;+};++export function Keybinding({ keyName }: KeybindingProps) {return <Text style={{ fontSize: 10, color: colors.n6 }}>{keyName}</Text>;}-export function Menu({ header, footer, items: allItems, onMenuSelect }) {+type MenuItem = {+ type: string | symbol;+ name: string;+ disabled?: boolean;+ icon?;+ iconSize?: number;+ text: string;+ key: string;+};++type MenuProps = {+ header: ReactNode;+ footer: ReactNode;+ items: Array<MenuItem | typeof Menu.line>;+ onMenuSelect;+};++export function Menu({+ header,+ footer,+ items: allItems,+ onMenuSelect,+}: MenuProps) {let elRef = useRef(null);let items = allItems.filter(x => x);let [hoveredIndex, setHoveredIndex] = useState(null);@@ -415,8 +531,9 @@ export function Menu({ header, footer, items: allItems, onMenuSelect }) {break;case 'Enter':e.preventDefault();- if (hoveredIndex !== null) {- onMenuSelect && onMenuSelect(items[hoveredIndex].name);+ const item = items[hoveredIndex];+ if (hoveredIndex !== null && item !== Menu.line) {+ onMenuSelect && onMenuSelect(item.name);}break;default:@@ -493,7 +610,7 @@ export function Menu({ header, footer, items: allItems, onMenuSelect }) {{/* Force it to line up evenly */}<Text style={{ lineHeight: 0 }}>{item.icon &&- React.createElement(item.icon, {+ createElement(item.icon, {width: item.iconSize || 10,height: item.iconSize || 10,style: { marginRight: 7, width: 10 },@@ -510,9 +627,18 @@ export function Menu({ header, footer, items: allItems, onMenuSelect }) {);}-Menu.line = Symbol('menu-line');+const MenuLine: unique symbol = Symbol('menu-line');+Menu.line = MenuLine;Menu.label = Symbol('menu-label');+type AlignedTextProps = ComponentProps<typeof View> & {+ left;+ right;+ style?: CSSProperties;+ leftStyle?: CSSProperties;+ rightStyle?: CSSProperties;+ truncate: 'left' | 'right';+};export function AlignedText({left,right,@@ -521,7 +647,7 @@ export function AlignedText({rightStyle,truncate = 'left',...nativeProps-}) {+}: AlignedTextProps) {const truncateStyle = {textOverflow: 'ellipsis',whiteSpace: 'nowrap',@@ -555,19 +681,10 @@ export function AlignedText({);}-export function PlainCurrency({ amount, style }) {- return <span style={style}>{integerToCurrency(amount)}</span>;-}--export function PageHeader({ title, style }) {- return (- <View style={{ alignItems: 'flex-start' }}>- <span style={[styles.pageHeader, style]}>{title}</span>- </View>- );-}--export function P({ style, isLast, children, ...props }) {+type PProps = HTMLPropsWithStyle<HTMLDivElement> & {+ isLast?: boolean;+};+export function P({ style, isLast, children, ...props }: PProps) {return (<div{...props}@@ -578,7 +695,9 @@ export function P({ style, isLast, children, ...props }) {);}-export function Strong({ style, children, ...props }) {+type StrongProps = HTMLPropsWithStyle<HTMLSpanElement>;++export function Strong({ style, children, ...props }: StrongProps) {return (<span {...props} {...css(style, { fontWeight: 500 })}>{children}@@ -586,7 +705,21 @@ export function Strong({ style, children, ...props }) {);}-export function InlineField({ label, labelWidth, children, width, style }) {+type InlineFieldProps = {+ label: ReactNode;+ labelWidth?: number;+ children?: ReactNode;+ width: number;+ style?: CSSProperties;+};++export function InlineField({+ label,+ labelWidth,+ children,+ width,+ style,+}: InlineFieldProps) {return (<label{...css(@@ -614,13 +747,22 @@ export function InlineField({ label, labelWidth, children, width, style }) {);}-export function FormError({ style, children }) {+type FormErrorProps = {+ style?: CSSProperties;+ children?: ReactNode;+};++export function FormError({ style, children }: FormErrorProps) {return (<View style={[{ color: 'red', fontSize: 13 }, style]}>{children}</View>);}-export function InitialFocus({ children }) {+type InitialFocusProps = {+ children?: ReactElement | ((node: unknown) => ReactNode);+};++export function InitialFocus({ children }: InitialFocusProps) {let node = useRef(null);useEffect(() => {@@ -640,16 +782,24 @@ export function InitialFocus({ children }) {if (typeof children === 'function') {return children(node);}- return React.cloneElement(children, { inputRef: node });+ return cloneElement(children, { inputRef: node });}+type HoverTargetProps = {+ style?: CSSProperties;+ contentStyle?: CSSProperties;+ children: ReactNode;+ renderContent: () => ReactNode;+ disabled?: boolean;+};+export function HoverTarget({style,contentStyle,children,renderContent,disabled,-}) {+}: HoverTargetProps) {let [hovered, setHovered] = useState(false);const onMouseEnter = useCallback(() => {@@ -684,7 +834,12 @@ export function HoverTarget({);}-export function Label({ title, style }) {+type LabelProps = {+ title: ReactNode;+ style?: CSSProperties;+};++export function Label({ title, style }: LabelProps) {return (<Textstyle={[diff --git a/packages/desktop-client/src/components/common/Button.tsx b/packages/desktop-client/src/components/common/Button.tsxindex 23f5653d95..c0325ac673 100644--- a/packages/desktop-client/src/components/common/Button.tsx+++ b/packages/desktop-client/src/components/common/Button.tsx@@ -1,33 +1,27 @@-import React from 'react';+import React, { forwardRef } from 'react';-import { css } from 'glamor';-import type { CSSProperties } from 'glamor';+import { css, type CSSProperties } from 'glamor';import Loading from '../../icons/AnimatedLoading';import { styles, colors } from '../../style';+import { type HTMLPropsWithStyle } from '../../types/utils';import View from './View';-interface ButtonProps- extends Omit<React.HTMLProps<HTMLButtonElement>, 'style'> {+type ButtonProps = HTMLPropsWithStyle<HTMLButtonElement> & {pressed?: boolean;primary?: boolean;hover?: boolean;bare?: boolean;disabled?: boolean;- style?: CSSProperties;hoveredStyle?: CSSProperties;activeStyle?: CSSProperties;+ textStyle?: CSSProperties;bounce?: boolean;as?: 'button';- children: React.ReactNode;- onClick?: () => void;-}+};-const Button: React.FC<ButtonProps> = React.forwardRef<- HTMLButtonElement,- ButtonProps->(+const Button = forwardRef<HTMLButtonElement, ButtonProps>(({children,@@ -115,47 +109,50 @@ const Button: React.FC<ButtonProps> = React.forwardRef<},);-interface ButtonWithLoadingProps extends ButtonProps {+type ButtonWithLoadingProps = ButtonProps & {loading?: boolean;-}+};-export const ButtonWithLoading: React.FC<ButtonWithLoadingProps> =- React.forwardRef((props, ref) => {- let { loading, children, ...buttonProps } = props;- return (- <Button- {...buttonProps}- style={[{ position: 'relative' }, buttonProps.style]}- >- {loading && (- <View- style={{- position: 'absolute',- top: 0,- left: 0,- right: 0,- bottom: 0,- alignItems: 'center',- justifyContent: 'center',- }}- >- <Loading- color="currentColor"- style={{ width: 20, height: 20, color: 'currentColor' }}- />- </View>- )}+export const ButtonWithLoading = forwardRef<+ HTMLButtonElement,+ ButtonWithLoadingProps+>((props, ref) => {+ let { loading, children, ...buttonProps } = props;+ return (+ <Button+ {...buttonProps}+ ref={ref}+ style={[{ position: 'relative' }, buttonProps.style]}+ >+ {loading && (<Viewstyle={{- opacity: loading ? 0 : 1,- flexDirection: 'row',+ position: 'absolute',+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,alignItems: 'center',+ justifyContent: 'center',}}>- {children}+ <Loading+ color="currentColor"+ style={{ width: 20, height: 20, color: 'currentColor' }}+ /></View>- </Button>- );- });+ )}+ <View+ style={{+ opacity: loading ? 0 : 1,+ flexDirection: 'row',+ alignItems: 'center',+ }}+ >+ {children}+ </View>+ </Button>+ );+});export default Button;diff --git a/packages/desktop-client/src/components/common/Input.tsx b/packages/desktop-client/src/components/common/Input.tsxindex 7cfef4dc58..c9f4ae3ac2 100644--- a/packages/desktop-client/src/components/common/Input.tsx+++ b/packages/desktop-client/src/components/common/Input.tsx@@ -1,11 +1,11 @@-import React, { useRef } from 'react';+import React, { useRef, type KeyboardEvent, type Ref } from 'react';import mergeRefs from 'react-merge-refs';import { css } from 'glamor';-import type { CSSProperties } from 'glamor';import { useProperFocus } from '../../hooks/useProperFocus';import { styles, colors } from '../../style';+import { type HTMLPropsWithStyle } from '../../types/utils';export const defaultInputStyle = {outline: 0,@@ -16,22 +16,21 @@ export const defaultInputStyle = {border: '1px solid #d0d0d0',};-interface InputProps extends Omit<React.HTMLProps<HTMLInputElement>, 'style'> {- style?: CSSProperties;- inputRef?: React.Ref<HTMLInputElement>;- onEnter?: (event: React.KeyboardEvent<HTMLInputElement>) => void;+type InputProps = HTMLPropsWithStyle<HTMLInputElement> & {+ inputRef?: Ref<HTMLInputElement>;+ onEnter?: (event: KeyboardEvent<HTMLInputElement>) => void;onUpdate?: (newValue: string) => void;focused?: boolean;-}+};-const Input: React.FC<InputProps> = ({+const Input = ({style,inputRef,onEnter,onUpdate,focused,...nativeProps-}) => {+}: InputProps) => {let ref = useRef();useProperFocus(ref, focused);diff --git a/packages/desktop-client/src/components/common/Modal.tsx b/packages/desktop-client/src/components/common/Modal.tsxindex f82449088e..bdfcc9f4c6 100644--- a/packages/desktop-client/src/components/common/Modal.tsx+++ b/packages/desktop-client/src/components/common/Modal.tsx@@ -1,4 +1,9 @@-import React, { useEffect, useRef, useLayoutEffect } from 'react';+import React, {+ type ReactNode,+ useEffect,+ useRef,+ useLayoutEffect,+} from 'react';import ReactModal from 'react-modal';import type { CSSProperties } from 'glamor';@@ -13,11 +18,11 @@ import Button from './Button';import Text from './Text';import View from './View';-export interface ModalProps {+export type ModalProps = {title: string;isCurrent?: boolean;isHidden?: boolean;- children: React.ReactNode;+ children: ReactNode | (() => ReactNode);size?: { width?: number; height?: number };padding?: number;showHeader?: boolean;@@ -28,14 +33,14 @@ export interface ModalProps {noAnimation?: boolean;focusAfterClose?: boolean;stackIndex?: number;- parent?: unknown;+ parent?: HTMLElement;style?: CSSProperties;contentStyle?: CSSProperties;overlayStyle?: CSSProperties;onClose?: () => void;-}+};-const Modal: React.FC<ModalProps> = ({+const Modal = ({title,isCurrent,isHidden,@@ -55,7 +60,7 @@ const Modal: React.FC<ModalProps> = ({overlayStyle,children,onClose,-}) => {+}: ModalProps) => {useEffect(() => {// This deactivates any key handlers in the "app" scope. Ideally// each modal would have a name so they could each have their own@@ -72,7 +77,7 @@ const Modal: React.FC<ModalProps> = ({shouldCloseOnOverlayClick={false}shouldFocusAfterRender={!global.IS_DESIGN_MODE}shouldReturnFocusAfterClose={focusAfterClose}- appElement={document.querySelector('#root')}+ appElement={document.querySelector('#root') as HTMLElement}parentSelector={parent && (() => parent)}style={{content: {@@ -220,23 +225,23 @@ const Modal: React.FC<ModalProps> = ({);};-interface ModalContentProps {+type ModalContentProps = {style?: CSSProperties;size?: ModalProps['size'];noAnimation?: boolean;isCurrent?: boolean;stackIndex?: number;- children: React.ReactNode;-}+ children: ReactNode;+};-const ModalContent: React.FC<ModalContentProps> = ({+const ModalContent = ({style,size,noAnimation,isCurrent,stackIndex,children,-}) => {+}: ModalContentProps) => {let contentRef = useRef(null);let mounted = useRef(false);let rotateFactor = useRef(Math.random() * 10 - 5);@@ -300,19 +305,19 @@ const ModalContent: React.FC<ModalContentProps> = ({);};-interface ModalButtonsProps {+type ModalButtonsProps = {style?: CSSProperties;- leftContent?: React.ReactNode;+ leftContent?: ReactNode;focusButton?: boolean;- children: React.ReactNode;-}+ children: ReactNode;+};-export const ModalButtons: React.FC<ModalButtonsProps> = ({+export const ModalButtons = ({style,leftContent,focusButton = false,children,-}) => {+}: ModalButtonsProps) => {let containerRef = useRef(null);useEffect(() => {diff --git a/packages/desktop-client/src/components/common/Text.tsx b/packages/desktop-client/src/components/common/Text.tsxindex 7ec99bbbbd..0d0acb8248 100644--- a/packages/desktop-client/src/components/common/Text.tsx+++ b/packages/desktop-client/src/components/common/Text.tsx@@ -1,16 +1,16 @@-import React from 'react';+import React, { type Ref, type ReactNode } from 'react';import { css } from 'glamor';-import type { CSSProperties } from 'glamor';-interface TextProps extends Omit<React.HTMLProps<HTMLSpanElement>, 'style'> {- style?: CSSProperties;- innerRef?: React.Ref<HTMLSpanElement>;+import { type HTMLPropsWithStyle } from '../../types/utils';++type TextProps = HTMLPropsWithStyle<HTMLSpanElement> & {+ innerRef?: Ref<HTMLSpanElement>;className?: string;- children?: React.ReactNode;-}+ children?: ReactNode;+};-export const Text: React.FC<TextProps> = props => {+export const Text = (props: TextProps) => {const { style, innerRef, ...restProps } = props;return (<spandiff --git a/packages/desktop-client/src/components/common/View.tsx b/packages/desktop-client/src/components/common/View.tsxindex 375907551b..68849ab909 100644--- a/packages/desktop-client/src/components/common/View.tsx+++ b/packages/desktop-client/src/components/common/View.tsx@@ -1,16 +1,20 @@-import React from 'react';+import React, {+ type HTMLProps,+ type Ref,+ type StyleHTMLAttributes,+} from 'react';import { css } from 'glamor';import type { CSSProperties } from 'glamor';-interface ViewProps extends Omit<React.HTMLProps<HTMLDivElement>, 'style'> {+type ViewProps = {className?: string;style?: CSSProperties;- nativeStyle?: React.StyleHTMLAttributes<HTMLDivElement>;- innerRef?: React.Ref<HTMLDivElement>;-}+ nativeStyle?: StyleHTMLAttributes<HTMLDivElement>;+ innerRef?: Ref<HTMLDivElement>;+} & Omit<HTMLProps<HTMLDivElement>, 'style'>;-const View: React.FC<ViewProps> = props => {+const View = (props: ViewProps) => {// The default styles are special-cased and pulled out into static// styles, and hardcode the class name here. View is used almost// everywhere and we can avoid any perf penalty that glamor woulddiff --git a/packages/desktop-client/src/components/debug/index.js b/packages/desktop-client/src/components/debug/index.jsindex b0957ce9f0..0f12595ae2 100644--- a/packages/desktop-client/src/components/debug/index.js+++ b/packages/desktop-client/src/components/debug/index.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { Component } from 'react';import styled from 'styled-components';@@ -22,7 +22,7 @@ const Output = styled.pre`padding: 0.5em;`;-class Debug extends React.Component {+class Debug extends Component {constructor() {super();this.state = {diff --git a/packages/desktop-client/src/components/forms.tsx b/packages/desktop-client/src/components/forms.tsxindex a1ff7f059d..d99a926204 100644--- a/packages/desktop-client/src/components/forms.tsx+++ b/packages/desktop-client/src/components/forms.tsx@@ -1,18 +1,17 @@-import React from 'react';+import React, { type ReactNode, type HTMLProps } from 'react';-import { css } from 'glamor';-import type { CSSProperties } from 'glamor';+import { css, type CSSProperties } from 'glamor';import { colors } from '../style';import { View, Text } from './common';-interface SectionLabelProps {+type SectionLabelProps = {title?: string;style?: CSSProperties;-}+};-export const SectionLabel: React.FC<SectionLabelProps> = ({ title, style }) => {+export const SectionLabel = ({ title, style }: SectionLabelProps) => {return (<Viewstyle={[@@ -31,19 +30,14 @@ export const SectionLabel: React.FC<SectionLabelProps> = ({ title, style }) => {);};-interface FormLabelProps {+type FormLabelProps = {title: string;id?: string;htmlFor?: string;style?: CSSProperties;-}+};-export const FormLabel: React.FC<FormLabelProps> = ({- style,- title,- id,- htmlFor,-}) => {+export const FormLabel = ({ style, title, id, htmlFor }: FormLabelProps) => {return (<Text style={[{ fontSize: 13, marginBottom: 3, color: colors.n3 }, style]}><label htmlFor={htmlFor} id={id}>@@ -53,23 +47,22 @@ export const FormLabel: React.FC<FormLabelProps> = ({);};-interface FormFieldProps {+type FormFieldProps = {style?: CSSProperties;- children: React.ReactNode;-}+ children: ReactNode;+};-export const FormField: React.FC<FormFieldProps> = ({ style, children }) => {+export const FormField = ({ style, children }: FormFieldProps) => {return <View style={style}>{children}</View>;};// Custom inputs-type CheckboxProps = Omit<- React.HTMLProps<HTMLInputElement>,- 'type' | 'styles'-> & { styles?: CSSProperties };+type CheckboxProps = Omit<HTMLProps<HTMLInputElement>, 'type' | 'styles'> & {+ styles?: CSSProperties;+};-export const Checkbox: React.FC<CheckboxProps> = props => {+export const Checkbox = (props: CheckboxProps) => {return (<inputtype="checkbox"diff --git a/packages/desktop-client/src/components/manager/subscribe/common.js b/packages/desktop-client/src/components/manager/subscribe/common.jsindex 96282dd036..6b132de55d 100644--- a/packages/desktop-client/src/components/manager/subscribe/common.js+++ b/packages/desktop-client/src/components/manager/subscribe/common.js@@ -1,4 +1,4 @@-import React, { useEffect, useState } from 'react';+import React, { forwardRef, useEffect, useState } from 'react';import { useHistory, useLocation } from 'react-router-dom';import { send } from 'loot-core/src/platform/client/fetch';@@ -93,7 +93,7 @@ export function Title({ text }) {);}-export const Input = React.forwardRef((props, ref) => {+export const Input = forwardRef((props, ref) => {return (<BaseInput{...props}@@ -111,7 +111,7 @@ export const Input = React.forwardRef((props, ref) => {);});-export const BareButton = React.forwardRef((props, ref) => {+export const BareButton = forwardRef((props, ref) => {return (<Buttonref={ref}@@ -137,7 +137,7 @@ export const BareButton = React.forwardRef((props, ref) => {);});-export const ExternalLink = React.forwardRef((props, ref) => {+export const ExternalLink = forwardRef((props, ref) => {let { href, ...linkProps } = props;return (<BareButton@@ -151,7 +151,7 @@ export const ExternalLink = React.forwardRef((props, ref) => {);});-export const BackLink = React.forwardRef((props, ref) => {+export const BackLink = forwardRef((props, ref) => {return (<BareButtonref={ref}diff --git a/packages/desktop-client/src/components/modals/LoadBackup.js b/packages/desktop-client/src/components/modals/LoadBackup.jsindex d060ca082b..77e5cc80f6 100644--- a/packages/desktop-client/src/components/modals/LoadBackup.js+++ b/packages/desktop-client/src/components/modals/LoadBackup.js@@ -1,10 +1,10 @@-import React from 'react';+import React, { Component } from 'react';import { colors } from '../../style';import { View, Text, Block, Modal, Button } from '../common';import { Row, Cell } from '../table';-class BackupTable extends React.Component {+class BackupTable extends Component {state = { hoveredBackup: null };onHover = id => {diff --git a/packages/desktop-client/src/components/modals/NordigenInitialise.tsx b/packages/desktop-client/src/components/modals/NordigenInitialise.tsxindex 4184695cc4..397ede3e6c 100644--- a/packages/desktop-client/src/components/modals/NordigenInitialise.tsx+++ b/packages/desktop-client/src/components/modals/NordigenInitialise.tsx@@ -11,15 +11,15 @@ import Text from '../common/Text';import View from '../common/View';import { FormField, FormLabel } from '../forms';-interface NordigenInitialiseProps {+type NordigenInitialiseProps = {modalProps?: Partial<ModalProps>;onSuccess: () => void;-}+};-const NordigenInitialise: React.FC<NordigenInitialiseProps> = ({+const NordigenInitialise = ({modalProps,onSuccess,-}) => {+}: NordigenInitialiseProps) => {const [secretId, setSecretId] = useState('');const [secretKey, setSecretKey] = useState('');const [isValid, setIsValid] = useState(true);diff --git a/packages/desktop-client/src/components/payees/index.js b/packages/desktop-client/src/components/payees/index.jsindex 757fb607e0..09da634f91 100644--- a/packages/desktop-client/src/components/payees/index.js+++ b/packages/desktop-client/src/components/payees/index.js@@ -1,4 +1,6 @@import React, {+ forwardRef,+ memo,useState,useEffect,useLayoutEffect,@@ -86,7 +88,7 @@ function RuleButton({ ruleCount, focused, onEdit, onClick }) {);}-let Payee = React.memo(+let Payee = memo(({style,payee,@@ -164,7 +166,7 @@ let Payee = React.memo(},);-const PayeeTable = React.forwardRef(+const PayeeTable = forwardRef(({payees,@@ -334,7 +336,7 @@ function PayeeMenu({ payeesById, selectedPayees, onDelete, onMerge, onClose }) {);}-export const ManagePayees = React.forwardRef(+export const ManagePayees = forwardRef(({modalProps,diff --git a/packages/desktop-client/src/components/reports/Tooltip.js b/packages/desktop-client/src/components/reports/Tooltip.jsindex 829e1ffbc6..9b1d8c83c4 100644--- a/packages/desktop-client/src/components/reports/Tooltip.js+++ b/packages/desktop-client/src/components/reports/Tooltip.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { Component } from 'react';import ReactDOM from 'react-dom';import { css, before } from 'glamor';@@ -6,7 +6,7 @@ import { VictoryTooltip } from 'victory';import { colors } from '../../style';-class Tooltip extends React.Component {+class Tooltip extends Component {static defaultEvents = VictoryTooltip.defaultEvents;render() {diff --git a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.js b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.jsindex 5a28cf929d..dbaeb4248f 100644--- a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.js+++ b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { createElement } from 'react';import * as d from 'date-fns';import {@@ -102,7 +102,7 @@ function NetWorthGraph({ style, start, end, graphData, compact }) {end={graphData.end}data={graphData.data}/>- {React.createElement(+ {createElement(graphData.data.length === 1 ? VictoryBar : VictoryArea,{data: graphData.data,diff --git a/packages/desktop-client/src/components/select/DateSelect.js b/packages/desktop-client/src/components/select/DateSelect.jsindex 2d1e546bbf..ade52981b4 100644--- a/packages/desktop-client/src/components/select/DateSelect.js+++ b/packages/desktop-client/src/components/select/DateSelect.js@@ -1,4 +1,5 @@import React, {+ forwardRef,useState,useRef,useEffect,@@ -68,7 +69,7 @@ let pickerStyles = {},};-export let DatePicker = React.forwardRef(+export let DatePicker = forwardRef(({ value, firstDayOfWeekIdx, dateFormat, onUpdate, onSelect }, ref) => {let picker = useRef(null);let mountPoint = useRef(null);diff --git a/packages/desktop-client/src/components/settings/Experimental.js b/packages/desktop-client/src/components/settings/Experimental.jsindex 7328c9164e..61d0b9660c 100644--- a/packages/desktop-client/src/components/settings/Experimental.js+++ b/packages/desktop-client/src/components/settings/Experimental.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { useState } from 'react';import { useAllFeatureFlags } from '../../hooks/useFeatureFlag';import { colors } from '../../style';@@ -8,7 +8,7 @@ import { Checkbox } from '../forms';import { Setting } from './UI';export default function ExperimentalFeatures({ prefs, savePrefs }) {- let [expanded, setExpanded] = React.useState(false);+ let [expanded, setExpanded] = useState(false);const flags = useAllFeatureFlags();let disabled = prefs.budgetType === 'report' && flags.reportBudget;diff --git a/packages/desktop-client/src/components/settings/UI.tsx b/packages/desktop-client/src/components/settings/UI.tsxindex ea4d04798f..d64897fd9b 100644--- a/packages/desktop-client/src/components/settings/UI.tsx+++ b/packages/desktop-client/src/components/settings/UI.tsx@@ -1,4 +1,4 @@-import React, { useState } from 'react';+import React, { type ReactNode, useState } from 'react';import { useLocation } from 'react-router';import { css, media } from 'glamor';@@ -8,17 +8,13 @@ import { colors } from '../../style';import tokens from '../../tokens';import { View, Link } from '../common';-interface SettingProps {- primaryAction: React.ReactNode;+type SettingProps = {+ primaryAction: ReactNode;style?: CSSProperties;- children: React.ReactNode;-}+ children: ReactNode;+};-export const Setting: React.FC<SettingProps> = ({- primaryAction,- style,- children,-}) => {+export const Setting = ({ primaryAction, style, children }: SettingProps) => {return (<View{...css([@@ -49,11 +45,11 @@ export const Setting: React.FC<SettingProps> = ({);};-interface AdvancedToggleProps {- children: React.ReactNode;-}+type AdvancedToggleProps = {+ children: ReactNode;+};-export const AdvancedToggle: React.FC<AdvancedToggleProps> = ({ children }) => {+export const AdvancedToggle = ({ children }: AdvancedToggleProps) => {let location = useLocation();let [expanded, setExpanded] = useState(location.hash === '#advanced');diff --git a/packages/desktop-client/src/components/sort.js b/packages/desktop-client/src/components/sort.jsindex 15015af363..c697f7f76b 100644--- a/packages/desktop-client/src/components/sort.js+++ b/packages/desktop-client/src/components/sort.js@@ -1,4 +1,5 @@import React, {+ createContext,useEffect,useRef,useLayoutEffect,@@ -105,7 +106,7 @@ export function useDroppable({ types, id, onDrop, onLongHover }) {};}-export const DropHighlightPosContext = React.createContext(null);+export const DropHighlightPosContext = createContext(null);export function DropHighlight({ pos, offset = {} }) {let itemPos = useContext(DropHighlightPosContext);diff --git a/packages/desktop-client/src/components/spreadsheet/NamespaceContext.js b/packages/desktop-client/src/components/spreadsheet/NamespaceContext.jsindex 417d05a21d..d05f5af3b7 100644--- a/packages/desktop-client/src/components/spreadsheet/NamespaceContext.js+++ b/packages/desktop-client/src/components/spreadsheet/NamespaceContext.js@@ -1,3 +1,3 @@-import React from 'react';+import { createContext } from 'react';-export default React.createContext(undefined);+export default createContext(undefined);diff --git a/packages/desktop-client/src/components/table.js b/packages/desktop-client/src/components/table.jsindex b1c3572074..001b4c8fbb 100644--- a/packages/desktop-client/src/components/table.js+++ b/packages/desktop-client/src/components/table.js@@ -1,4 +1,6 @@import React, {+ createContext,+ forwardRef,useState,useCallback,useRef,@@ -51,7 +53,7 @@ function fireBlur(onBlur, e) {}}-const CellContext = React.createContext({+const CellContext = createContext({backgroundColor: 'white',borderColor: colors.n9,});@@ -68,7 +70,7 @@ function CellProvider({ backgroundColor, borderColor, children }) {return <CellContext.Provider value={value}>{children}</CellContext.Provider>;}-export const Field = React.forwardRef(function Field(+export const Field = forwardRef(function Field({width,name,@@ -364,7 +366,7 @@ export function InputCell({return (<Cell textAlign={textAlign} {...props}>{() => (- <React.Fragment>+ <><InputValuevalue={props.value}onUpdate={onUpdate}@@ -382,7 +384,7 @@ export function InputCell({{error}</Tooltip>)}- </React.Fragment>+ </>)}</Cell>);@@ -465,7 +467,7 @@ export function DeleteCell({ onDelete, style, ...props }) {);}-export const CellButton = React.forwardRef(+export const CellButton = forwardRef(({ style, disabled, clickBehavior, onSelect, onEdit, children }, ref) => {// This represents a cell that acts like a button: it's clickable,// focusable, etc. The reason we don't use a button is because the@@ -724,14 +726,12 @@ export function SelectedItemsButton({ name, keyHandlers, items, onSelect }) {let rowStyle = { position: 'absolute', willChange: 'transform', width: '100%' };-export const TableWithNavigator = React.forwardRef(- ({ fields, ...props }, ref) => {- let navigator = useTableNavigator(props.items, fields);- return <Table {...props} navigator={navigator} />;- },-);+export const TableWithNavigator = forwardRef(({ fields, ...props }, ref) => {+ let navigator = useTableNavigator(props.items, fields);+ return <Table {...props} navigator={navigator} />;+});-export const Table = React.forwardRef(+export const Table = forwardRef(({items,diff --git a/packages/desktop-client/src/components/tooltips.js b/packages/desktop-client/src/components/tooltips.jsindex 0b431b8bc3..28de223260 100644--- a/packages/desktop-client/src/components/tooltips.js+++ b/packages/desktop-client/src/components/tooltips.js@@ -1,11 +1,11 @@-import React, { useState } from 'react';+import React, { Component, createContext, createRef, useState } from 'react';import ReactDOM from 'react-dom';import { css, before } from 'glamor';import { styles } from '../style';-export const IntersectionBoundary = React.createContext();+export const IntersectionBoundary = createContext();export function useTooltip() {let [isOpen, setIsOpen] = useState(false);@@ -23,14 +23,14 @@ export function useTooltip() {};}-export class Tooltip extends React.Component {+export class Tooltip extends Component {static contextType = IntersectionBoundary;state = { position: null };constructor(props) {super(props);this.position = props.position || 'bottom-right';- this.contentRef = React.createRef();+ this.contentRef = createRef();}setup() {diff --git a/packages/desktop-client/src/components/tutorial/AnimateIn.js b/packages/desktop-client/src/components/tutorial/AnimateIn.jsindex 026a3d292d..21465e7270 100644--- a/packages/desktop-client/src/components/tutorial/AnimateIn.js+++ b/packages/desktop-client/src/components/tutorial/AnimateIn.js@@ -1,6 +1,6 @@-import React from 'react';+import { Component } from 'react';-class AnimateIn extends React.Component {+class AnimateIn extends Component {state = { animating: false };componentDidMount() {diff --git a/packages/desktop-client/src/components/tutorial/BudgetInitial.js b/packages/desktop-client/src/components/tutorial/BudgetInitial.jsindex 1adc4e80e2..56cedf0e27 100644--- a/packages/desktop-client/src/components/tutorial/BudgetInitial.js+++ b/packages/desktop-client/src/components/tutorial/BudgetInitial.js@@ -17,7 +17,7 @@ function BudgetInitial({ accounts, navigationProps }) {<Standalone><Title>Go ahead and budget your money</Title>{!minimized && (- <React.Fragment>+ <><P>You should see all of your current accounts’ balance available tobudget. Click on the budgeted column for a category create a budget.@@ -27,7 +27,7 @@ function BudgetInitial({ accounts, navigationProps }) {Don’t worry too much about your initial budget. Just guess. You’lllearn more about your spending in the first couple months.</P>- </React.Fragment>+ </>)}<Navigation{...navigationProps}diff --git a/packages/desktop-client/src/components/tutorial/common.js b/packages/desktop-client/src/components/tutorial/common.jsindex 8ce32a4876..f77426e6d6 100644--- a/packages/desktop-client/src/components/tutorial/common.js+++ b/packages/desktop-client/src/components/tutorial/common.js@@ -1,4 +1,4 @@-import React, { useState } from 'react';+import React, { forwardRef, useState } from 'react';import { colors } from '../../style';import { View, AnchorLink } from '../common';@@ -42,7 +42,7 @@ export function Standalone({ children, width = 320, skipAnimation = false }) {);}-export const ExternalLink = React.forwardRef((props, ref) => {+export const ExternalLink = forwardRef((props, ref) => {let { href, ...linkProps } = props;return (<AnchorLinkdiff --git a/packages/desktop-client/src/hooks/useProperFocus.js b/packages/desktop-client/src/hooks/useProperFocus.jsindex 20ac5a9e80..780c4d7ca7 100644--- a/packages/desktop-client/src/hooks/useProperFocus.js+++ b/packages/desktop-client/src/hooks/useProperFocus.js@@ -1,4 +1,10 @@-import React, { useRef, useLayoutEffect, useContext, useMemo } from 'react';+import React, {+ createContext,+ useRef,+ useLayoutEffect,+ useContext,+ useMemo,+} from 'react';function getFocusedKey(el) {let node = el;@@ -28,7 +34,7 @@ export function focusElement(el, refocusContext) {}}-let AvoidRefocusScrollContext = React.createContext(null);+let AvoidRefocusScrollContext = createContext(null);export function AvoidRefocusScrollProvider({ children }) {let keyRef = useRef(null);diff --git a/packages/desktop-client/src/hooks/useSelected.js b/packages/desktop-client/src/hooks/useSelected.jsindex f2b9bc0e06..ef031056eb 100644--- a/packages/desktop-client/src/hooks/useSelected.js+++ b/packages/desktop-client/src/hooks/useSelected.js@@ -1,4 +1,5 @@import React, {+ createContext,useContext,useReducer,useCallback,@@ -203,8 +204,8 @@ export default function useSelected(name, items, initialSelectedIds) {};}-let SelectedDispatch = React.createContext(null);-let SelectedItems = React.createContext(null);+let SelectedDispatch = createContext(null);+let SelectedItems = createContext(null);export function useSelectedDispatch() {return useContext(SelectedDispatch);diff --git a/packages/desktop-client/src/style.js b/packages/desktop-client/src/style.tsxsimilarity index 92%rename from packages/desktop-client/src/style.jsrename to packages/desktop-client/src/style.tsxindex ebf344f6cf..7d5d61cc9d 100644--- a/packages/desktop-client/src/style.js+++ b/packages/desktop-client/src/style.tsx@@ -71,19 +71,14 @@ export const colors = {p9: '#DAC4FF',p10: '#F2EBFE',p11: '#F9F6FE',-};--colors.border = colors.n10;-colors.hover = '#fafafa';-colors.selected = colors.b9;-colors.resolve = (name, offset) => {- switch (name) {- case 'border':- return colors['n' + (8 + offset)];- default:- }- throw new Error('Unknown color name: ' + name);+ get border() {+ return this.n10;+ },+ hover: '#fafafa',+ get selected() {+ return this.b9;+ },};export const styles = {@@ -124,11 +119,9 @@ export const styles = {pageHeader: {fontSize: 25,borderBottomWidth: 5,- borderColor: colors.purple2,borderStyle: 'solid',display: 'inline',flex: 0,- color: colors.grey4,marginTop: 40,marginBottom: 20,paddingBottom: 5,@@ -182,6 +175,10 @@ export const styles = {// lineHeight: 22.4 // TODO: This seems like trouble, but what's the right value?},textColor: colors.n1,+ // Dynamically set+ lightScrollbar: undefined,+ darkScrollbar: undefined,+ scrollbarWidth: undefined,};let hiddenScrollbars = false;@@ -222,7 +219,7 @@ if (Platform.env === 'web') {el.innerHTML ='<div style="width:100px;height:100px;overflow:scroll;position:absolute;top:-9999px;"/>';document.body.appendChild(el);- let testNode = el.childNodes[0];+ let testNode = el.childNodes[0] as HTMLDivElement;if (testNode.offsetWidth === testNode.clientWidth) {return true;}diff --git a/packages/desktop-client/src/types/utils.d.ts b/packages/desktop-client/src/types/utils.d.tsnew file mode 100644index 0000000000..d82664bd8e--- /dev/null+++ b/packages/desktop-client/src/types/utils.d.ts@@ -0,0 +1,7 @@+import type { HTMLProps } from 'react';++export type HTMLPropsWithStyle<E> = Omit<HTMLProps<E>, 'style'> & {+ // glamor CSSProperties is any+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ style?: any;+};diff --git a/packages/desktop-client/src/util/withThemeColor.tsx b/packages/desktop-client/src/util/withThemeColor.tsxindex f4181d7570..f2615e515c 100644--- a/packages/desktop-client/src/util/withThemeColor.tsx+++ b/packages/desktop-client/src/util/withThemeColor.tsx@@ -1,7 +1,7 @@-import React from 'react';+import React, { Component } from 'react';export const withThemeColor = color => WrappedComponent => {- class WithThemeColor extends React.Component {+ class WithThemeColor extends Component {componentDidMount() {setThemeColor(color);}diff --git a/packages/loot-core/src/client/SpreadsheetProvider.tsx b/packages/loot-core/src/client/SpreadsheetProvider.tsxindex 1494c663db..270cba1923 100644--- a/packages/loot-core/src/client/SpreadsheetProvider.tsx+++ b/packages/loot-core/src/client/SpreadsheetProvider.tsx@@ -1,10 +1,10 @@-import React, { useEffect, useMemo, useContext } from 'react';+import React, { createContext, useEffect, useMemo, useContext } from 'react';import LRU from 'lru-cache';import { listen, send } from '../platform/client/fetch';-const SpreadsheetContext = React.createContext(undefined);+const SpreadsheetContext = createContext(undefined);export function useSpreadsheet() {return useContext(SpreadsheetContext);diff --git a/packages/loot-core/src/client/data-hooks/accounts.tsx b/packages/loot-core/src/client/data-hooks/accounts.tsxindex d478bc519c..d282d73150 100644--- a/packages/loot-core/src/client/data-hooks/accounts.tsx+++ b/packages/loot-core/src/client/data-hooks/accounts.tsx@@ -1,4 +1,4 @@-import React, { useEffect, useState, useContext } from 'react';+import React, { createContext, useEffect, useState, useContext } from 'react';import q, { liveQuery } from 'loot-core/src/client/query-helpers';import { getAccountsById } from 'loot-core/src/client/reducers/queries';@@ -22,7 +22,7 @@ export function useAccounts() {return data;}-let AccountsContext = React.createContext(null);+let AccountsContext = createContext(null);export function AccountsProvider({ children }) {let data = useAccounts();diff --git a/packages/loot-core/src/client/data-hooks/payees.tsx b/packages/loot-core/src/client/data-hooks/payees.tsxindex cf7b647855..da2feb476b 100644--- a/packages/loot-core/src/client/data-hooks/payees.tsx+++ b/packages/loot-core/src/client/data-hooks/payees.tsx@@ -1,4 +1,4 @@-import React, { useEffect, useState, useContext } from 'react';+import React, { createContext, useEffect, useState, useContext } from 'react';import q, { liveQuery } from 'loot-core/src/client/query-helpers';import { getPayeesById } from 'loot-core/src/client/reducers/queries';@@ -22,7 +22,7 @@ export function usePayees() {return data;}-let PayeesContext = React.createContext(null);+let PayeesContext = createContext(null);export function PayeesProvider({ children }) {let data = usePayees();diff --git a/packages/loot-core/src/client/data-hooks/schedules.tsx b/packages/loot-core/src/client/data-hooks/schedules.tsxindex 4be18b40b0..960e259ec6 100644--- a/packages/loot-core/src/client/data-hooks/schedules.tsx+++ b/packages/loot-core/src/client/data-hooks/schedules.tsx@@ -1,4 +1,4 @@-import React, { useEffect, useState, useContext } from 'react';+import React, { createContext, useEffect, useState, useContext } from 'react';import q, { liveQuery } from 'loot-core/src/client/query-helpers';import {@@ -57,7 +57,7 @@ export function useSchedules({ transform }: UseSchedulesArgs = {}) {return data;}-let SchedulesContext = React.createContext(null);+let SchedulesContext = createContext(null);export function SchedulesProvider({ transform, children }) {let data = useSchedules({ transform });diff --git a/packages/loot-core/src/client/query-hooks.tsx b/packages/loot-core/src/client/query-hooks.tsxindex f5f3e72b0e..da9b988c95 100644--- a/packages/loot-core/src/client/query-hooks.tsx+++ b/packages/loot-core/src/client/query-hooks.tsx@@ -1,10 +1,16 @@-import React, { useState, useContext, useMemo, useEffect } from 'react';+import React, {+ createContext,+ useState,+ useContext,+ useMemo,+ useEffect,+} from 'react';import { liveQuery, LiveQuery, PagedQuery } from './query-helpers';function makeContext(queryState, opts, QueryClass) {let query = new QueryClass(queryState, null, opts);- let Context = React.createContext(null);+ let Context = createContext(null);function Provider({ children }) {let [data, setData] = useState(query.getData());diff --git a/packages/loot-core/typings/window.d.ts b/packages/loot-core/typings/window.d.tsindex 76a87850c0..57e0efae4b 100644--- a/packages/loot-core/typings/window.d.ts+++ b/packages/loot-core/typings/window.d.ts@@ -5,6 +5,7 @@ declare global {Actual?: {IS_FAKE_WEB: boolean;ACTUAL_VERSION: string;+ openURLInBrowser: (url: string) => void;};__history?: {diff --git a/upcoming-release-notes/979.md b/upcoming-release-notes/979.mdnew file mode 100644index 0000000000..36f9276423--- /dev/null+++ b/upcoming-release-notes/979.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [albertogasparin]+---++Convert top common components in `desktop-client` to Typescriptdiff --git a/yarn.lock b/yarn.lockindex 16494eb17e..83fcfba0d2 100644--- a/yarn.lock+++ b/yarn.lock@@ -67,6 +67,10 @@ __metadata:"@svgr/cli": ^6.5.1"@testing-library/react": 14.0.0"@testing-library/user-event": 14.4.3+ "@types/react": ^18.2.0+ "@types/react-dom": ^18.2.1+ "@types/react-modal": ^3.16.0+ "@types/react-router-dom": ^5.3.3chalk: 2.4.1chroma-js: ^1.3.3cross-env: ^7.0.3@@ -3812,6 +3816,13 @@ __metadata:languageName: nodelinkType: hard+"@types/history@npm:^4.7.11":+ version: 4.7.11+ resolution: "@types/history@npm:4.7.11"+ checksum: c92e2ba407dcab0581a9afdf98f533aa41b61a71133420a6d92b1ca9839f741ab1f9395b17454ba5b88cb86020b70b22d74a1950ccfbdfd9beeaa5459fdc3464+ languageName: node+ linkType: hard+"@types/hoist-non-react-statics@npm:^3.3.1":version: 3.3.1resolution: "@types/hoist-non-react-statics@npm:3.3.1"@@ -4016,23 +4027,53 @@ __metadata:languageName: nodelinkType: hard-"@types/react-dom@npm:^18.0.0":- version: 18.0.11- resolution: "@types/react-dom@npm:18.0.11"+"@types/react-dom@npm:^18.0.0, @types/react-dom@npm:^18.2.1":+ version: 18.2.1+ resolution: "@types/react-dom@npm:18.2.1"+ dependencies:+ "@types/react": "*"+ checksum: 4e607a9d08f707ae2bd6b377f1da32989dcbe4e38ac39110423a1f6bc95dd53a5484f7f952b34e9d12b5f29a265d52a8c74c1a7d1d1e25be0fa69ccf9d64209f+ languageName: node+ linkType: hard++"@types/react-modal@npm:^3.16.0":+ version: 3.16.0+ resolution: "@types/react-modal@npm:3.16.0"+ dependencies:+ "@types/react": "*"+ checksum: 975c0238d81cea234a2318a7cfcb95a8e6beb7fc5341ca2311651535c6476881e8d2f2f2e1c679ca6e416c04505c748071a1fab0d3fb3e88b0a9e43060b012fe+ languageName: node+ linkType: hard++"@types/react-router-dom@npm:^5.3.3":+ version: 5.3.3+ resolution: "@types/react-router-dom@npm:5.3.3"+ dependencies:+ "@types/history": ^4.7.11+ "@types/react": "*"+ "@types/react-router": "*"+ checksum: 28c4ea48909803c414bf5a08502acbb8ba414669b4b43bb51297c05fe5addc4df0b8fd00e0a9d1e3535ec4073ef38aaafac2c4a2b95b787167d113bc059beff3+ languageName: node+ linkType: hard++"@types/react-router@npm:*":+ version: 5.1.20+ resolution: "@types/react-router@npm:5.1.20"dependencies:+ "@types/history": ^4.7.11"@types/react": "*"- checksum: 579691e4d5ec09688087568037c35edf8cfb1ab3e07f6c60029280733ee7b5c06d66df6fcc90786702c93ac8cb13bc7ff16c79ddfc75d082938fbaa36e1cdbf4+ checksum: 128764143473a5e9457ddc715436b5d49814b1c214dde48939b9bef23f0e77f52ffcdfa97eb8d3cc27e2c229869c0cdd90f637d887b62f2c9f065a87d6425419languageName: nodelinkType: hard-"@types/react@npm:*":- version: 17.0.43- resolution: "@types/react@npm:17.0.43"+"@types/react@npm:*, @types/react@npm:^18.2.0":+ version: 18.2.0+ resolution: "@types/react@npm:18.2.0"dependencies:"@types/prop-types": "*""@types/scheduler": "*"csstype: ^3.0.2- checksum: 981b0993f5b3ea9d3488b8cc883201e8ae47ba7732929f788f450a79fd72829e658080d5084e67caa008e58d989b0abc1d5f36ff0a1cda09315ea3a3c0c9dc11+ checksum: db3d92b423150222a666329f7aa3023e3e942044700557b8a7d161530847e621aec9f56c9e7f71761b06dd164c8a7b17ad52355863efe80963dffa5537e8e5fdlanguageName: nodelinkType: hard