diff --git a/packages/desktop-client/src/components/budget/BudgetSummaries.js b/packages/desktop-client/src/components/budget/BudgetSummaries.tsx similarity index 80% rename from packages/desktop-client/src/components/budget/BudgetSummaries.js rename to packages/desktop-client/src/components/budget/BudgetSummaries.tsx index e8cf86ddd30..cd4bfed88ac 100644 --- a/packages/desktop-client/src/components/budget/BudgetSummaries.js +++ b/packages/desktop-client/src/components/budget/BudgetSummaries.tsx @@ -9,14 +9,22 @@ import { useSpring, animated } from 'react-spring'; import { css } from 'glamor'; -import * as monthUtils from 'loot-core/src/shared/months'; +import { addMonths, subMonths } from 'loot-core/src/shared/months'; import useResizeObserver from '../../hooks/useResizeObserver'; import View from '../common/View'; import { MonthsContext } from './MonthsContext'; +import { type BudgetSummary as ReportBudgetSummary } from './report/BudgetSummary'; +import { type BudgetSummary as RolloverBudgetSummary } from './rollover/BudgetSummary'; -export default function BudgetSummaries({ SummaryComponent }) { +type BudgetSummariesProps = { + SummaryComponent: typeof ReportBudgetSummary | typeof RolloverBudgetSummary; +}; + +export default function BudgetSummaries({ + SummaryComponent, +}: BudgetSummariesProps) { let { months } = useContext(MonthsContext); let [widthState, setWidthState] = useState(0); @@ -32,10 +40,9 @@ export default function BudgetSummaries({ SummaryComponent }) { ); let prevMonth0 = useRef(months[0]); - let allMonths = [...months]; - allMonths.unshift(monthUtils.subMonths(months[0], 1)); - allMonths.push(monthUtils.addMonths(months[months.length - 1], 1)); + allMonths.unshift(subMonths(months[0], 1)); + allMonths.push(addMonths(months[months.length - 1], 1)); let monthWidth = widthState / months.length; useLayoutEffect(() => { @@ -43,9 +50,11 @@ export default function BudgetSummaries({ SummaryComponent }) { let reversed = prevMonth > months[0]; let offsetX = monthWidth; let from = reversed ? -offsetX * 2 : 0; + if (prevMonth !== allMonths[0] && prevMonth !== allMonths[2]) { from = -offsetX; } + let to = -offsetX; spring.start({ from: { x: from }, x: to }); }, [months[0]]); diff --git a/packages/desktop-client/src/components/budget/ExpenseGroup.js b/packages/desktop-client/src/components/budget/ExpenseGroup.js index 26534f3966e..217f36531cb 100644 --- a/packages/desktop-client/src/components/budget/ExpenseGroup.js +++ b/packages/desktop-client/src/components/budget/ExpenseGroup.js @@ -13,7 +13,6 @@ function ExpenseGroup({ collapsed, editingCell, dragState, - itemPos, MonthComponent, onEditName, onSave, diff --git a/packages/desktop-client/src/components/budget/MonthPicker.js b/packages/desktop-client/src/components/budget/MonthPicker.tsx similarity index 94% rename from packages/desktop-client/src/components/budget/MonthPicker.js rename to packages/desktop-client/src/components/budget/MonthPicker.tsx index 4466edb38df..7ee9c2206c1 100644 --- a/packages/desktop-client/src/components/budget/MonthPicker.js +++ b/packages/desktop-client/src/components/budget/MonthPicker.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { type CSSProperties, useState } from 'react'; import * as monthUtils from 'loot-core/src/shared/months'; @@ -6,13 +6,23 @@ import useResizeObserver from '../../hooks/useResizeObserver'; import { styles, theme } from '../../style'; import View from '../common/View'; +import { type BoundsProps } from './MonthsContext'; + +type MonthPickerProps = { + startMonth: string; + numDisplayed: number; + monthBounds: BoundsProps; + style: CSSProperties; + onSelect: (month: string) => void; +}; + export const MonthPicker = ({ startMonth, numDisplayed, monthBounds, style, onSelect, -}) => { +}: MonthPickerProps) => { const [hoverId, setHoverId] = useState(null); const [targetMonthCount, setTargetMonthCount] = useState(12); diff --git a/packages/desktop-client/src/components/budget/MonthsContext.tsx b/packages/desktop-client/src/components/budget/MonthsContext.tsx index 8fd945afece..3292929dfdf 100644 --- a/packages/desktop-client/src/components/budget/MonthsContext.tsx +++ b/packages/desktop-client/src/components/budget/MonthsContext.tsx @@ -2,7 +2,7 @@ import React, { createContext, type ReactNode } from 'react'; import * as monthUtils from 'loot-core/src/shared/months'; -type BoundsProps = { +export type BoundsProps = { start: string; end: string; }; diff --git a/packages/desktop-client/src/components/budget/SidebarCategory.js b/packages/desktop-client/src/components/budget/SidebarCategory.tsx similarity index 87% rename from packages/desktop-client/src/components/budget/SidebarCategory.js rename to packages/desktop-client/src/components/budget/SidebarCategory.tsx index 31a5391d478..d20eea8c80c 100644 --- a/packages/desktop-client/src/components/budget/SidebarCategory.js +++ b/packages/desktop-client/src/components/budget/SidebarCategory.tsx @@ -1,4 +1,6 @@ -import React, { useState } from 'react'; +import React, { type CSSProperties, type Ref, useState } from 'react'; + +import { type CategoryEntity } from 'loot-core/src/types/models'; import CheveronDown from '../../icons/v1/CheveronDown'; import { theme } from '../../style'; @@ -6,9 +8,26 @@ import Button from '../common/Button'; import Menu from '../common/Menu'; import View from '../common/View'; import NotesButton from '../NotesButton'; +import { type OnDragChangeCallback } from '../sort'; import { InputCell } from '../table'; import { Tooltip } from '../tooltips'; +type SidebarCategoryProps = { + innerRef: Ref; + category: CategoryEntity; + dragPreview?: boolean; + dragging?: boolean; + editing: boolean; + style: CSSProperties; + borderColor: string; + isLast?: boolean; + onDragChange?: OnDragChangeCallback; + onEditName: (id: string) => void; + onSave: (group) => void; + onDelete: (id: string) => Promise; + onHideNewCategory: () => void; +}; + function SidebarCategory({ innerRef, category, @@ -16,15 +35,13 @@ function SidebarCategory({ dragging, editing, style, - borderColor = theme.tableBorder, isLast, onDragChange, - onEditMonth, onEditName, onSave, onDelete, onHideNewCategory, -}) { +}: SidebarCategoryProps) { const temporary = category.id === 'new'; const [menuOpen, setMenuOpen] = useState(false); diff --git a/packages/desktop-client/src/components/budget/SidebarGroup.tsx b/packages/desktop-client/src/components/budget/SidebarGroup.tsx index afb8090def4..03969ced3ca 100644 --- a/packages/desktop-client/src/components/budget/SidebarGroup.tsx +++ b/packages/desktop-client/src/components/budget/SidebarGroup.tsx @@ -1,4 +1,5 @@ import React, { type CSSProperties, useState } from 'react'; +import { type ConnectDragSource } from 'react-dnd'; import ExpandArrow from '../../icons/v0/ExpandArrow'; import CheveronDown from '../../icons/v1/CheveronDown'; @@ -24,7 +25,7 @@ type SidebarGroupProps = { editing?: boolean; collapsed: boolean; dragPreview?: () => void; - innerRef?: () => void; + innerRef?: ConnectDragSource; borderColor?: string; style?: CSSProperties; onEdit?: (id: string) => void; diff --git a/packages/desktop-client/src/components/budget/rollover/BudgetSummary.tsx b/packages/desktop-client/src/components/budget/rollover/BudgetSummary.tsx index dde6177cc07..36b6b3b4b7b 100644 --- a/packages/desktop-client/src/components/budget/rollover/BudgetSummary.tsx +++ b/packages/desktop-client/src/components/budget/rollover/BudgetSummary.tsx @@ -260,7 +260,7 @@ function ToBudget({ type BudgetSummaryProps = { month: string; - isGoalTemplatesEnabled: boolean; + isGoalTemplatesEnabled?: boolean; }; export function BudgetSummary({ month, diff --git a/packages/desktop-client/src/hooks/useResizeObserver.ts b/packages/desktop-client/src/hooks/useResizeObserver.ts index 49a0a24d5de..ef34570fc86 100644 --- a/packages/desktop-client/src/hooks/useResizeObserver.ts +++ b/packages/desktop-client/src/hooks/useResizeObserver.ts @@ -1,7 +1,7 @@ import { useRef, useCallback } from 'react'; export default function useResizeObserver( - func: (contentRect: DOMRectReadOnly) => ResizeObserver, + func: (contentRect: DOMRectReadOnly) => void, ): (el: unknown) => void { let observer = useRef(null); if (!observer.current) { diff --git a/upcoming-release-notes/1879.md b/upcoming-release-notes/1879.md new file mode 100644 index 00000000000..2d93e1f5b98 --- /dev/null +++ b/upcoming-release-notes/1879.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MikesGlitch] +--- + +Convert BudgetSummaries, MonthPicker, SidebarCategory components to Typescript.