From 4c3d73eebcaa4ceab868c06bfda4032e374cee0d Mon Sep 17 00:00:00 2001 From: Josh Krebs Date: Mon, 18 Sep 2023 16:24:05 -0700 Subject: [PATCH 1/3] refactor MonthsContext to tsx --- .../src/components/budget/MonthsContext.js | 30 ------------ .../src/components/budget/MonthsContext.tsx | 49 +++++++++++++++++++ 2 files changed, 49 insertions(+), 30 deletions(-) delete mode 100644 packages/desktop-client/src/components/budget/MonthsContext.js create mode 100644 packages/desktop-client/src/components/budget/MonthsContext.tsx diff --git a/packages/desktop-client/src/components/budget/MonthsContext.js b/packages/desktop-client/src/components/budget/MonthsContext.js deleted file mode 100644 index dd321a75a99..00000000000 --- a/packages/desktop-client/src/components/budget/MonthsContext.js +++ /dev/null @@ -1,30 +0,0 @@ -import React, { createContext } from 'react'; - -import * as monthUtils from 'loot-core/src/shared/months'; - -export function getValidMonthBounds(bounds, startMonth, endMonth) { - return { - start: startMonth < bounds.start ? bounds.start : startMonth, - end: endMonth > bounds.end ? bounds.end : endMonth, - }; -} - -export let MonthsContext = createContext(); - -export function MonthsProvider({ - startMonth, - numMonths, - monthBounds, - type, - children, -}) { - let endMonth = monthUtils.addMonths(startMonth, numMonths - 1); - let bounds = getValidMonthBounds(monthBounds, startMonth, endMonth); - let months = monthUtils.rangeInclusive(bounds.start, bounds.end); - - return ( - - {children} - - ); -} diff --git a/packages/desktop-client/src/components/budget/MonthsContext.tsx b/packages/desktop-client/src/components/budget/MonthsContext.tsx new file mode 100644 index 00000000000..94f219a422f --- /dev/null +++ b/packages/desktop-client/src/components/budget/MonthsContext.tsx @@ -0,0 +1,49 @@ +import React, { createContext, type ReactNode } from 'react'; + +import * as monthUtils from 'loot-core/src/shared/months'; + +type BoundsParams = { + start: string | Date; + end: string | Date; +}; + +type GetValidMonthBoundsParams = { + bounds: BoundsParams; + startMonth: string | Date; + endMonth: string | Date; +}; + +export function getValidMonthBounds({ bounds, startMonth, endMonth }: GetValidMonthBoundsParams) { + return { + start: startMonth < bounds.start ? bounds.start : startMonth, + end: endMonth > bounds.end ? bounds.end : endMonth, + }; +} + +export let MonthsContext = createContext(null); + +type MonthsProviderProps = { + startMonth: string | Date; + numMonths: number; + monthBounds: BoundsParams; + type: string; + children?: ReactNode; +}; + +export function MonthsProvider({ + startMonth, + numMonths, + monthBounds, + type, + children, +}: MonthsProviderProps) { + let endMonth = monthUtils.addMonths(startMonth, numMonths - 1); + let bounds = getValidMonthBounds({ bounds: monthBounds, startMonth, endMonth }); + let months = monthUtils.rangeInclusive(bounds.start, bounds.end); + + return ( + + {children} + + ); +} From a70ada2287fddf36e269cb97f7e808e386d976d1 Mon Sep 17 00:00:00 2001 From: Josh Krebs Date: Mon, 18 Sep 2023 16:29:06 -0700 Subject: [PATCH 2/3] add release notes --- upcoming-release-notes/1711.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/1711.md diff --git a/upcoming-release-notes/1711.md b/upcoming-release-notes/1711.md new file mode 100644 index 00000000000..70e08a37622 --- /dev/null +++ b/upcoming-release-notes/1711.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [Jod929] +--- + +Refactor budget/MonthsContext to tsx \ No newline at end of file From 7ad8d681d08fedd7c3759b27757222fe45ae022b Mon Sep 17 00:00:00 2001 From: Josh Krebs Date: Mon, 18 Sep 2023 16:41:19 -0700 Subject: [PATCH 3/3] fix linting --- .../src/components/budget/MonthsContext.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/desktop-client/src/components/budget/MonthsContext.tsx b/packages/desktop-client/src/components/budget/MonthsContext.tsx index 94f219a422f..7d739309601 100644 --- a/packages/desktop-client/src/components/budget/MonthsContext.tsx +++ b/packages/desktop-client/src/components/budget/MonthsContext.tsx @@ -13,7 +13,11 @@ type GetValidMonthBoundsParams = { endMonth: string | Date; }; -export function getValidMonthBounds({ bounds, startMonth, endMonth }: GetValidMonthBoundsParams) { +export function getValidMonthBounds({ + bounds, + startMonth, + endMonth, +}: GetValidMonthBoundsParams) { return { start: startMonth < bounds.start ? bounds.start : startMonth, end: endMonth > bounds.end ? bounds.end : endMonth, @@ -38,7 +42,11 @@ export function MonthsProvider({ children, }: MonthsProviderProps) { let endMonth = monthUtils.addMonths(startMonth, numMonths - 1); - let bounds = getValidMonthBounds({ bounds: monthBounds, startMonth, endMonth }); + let bounds = getValidMonthBounds({ + bounds: monthBounds, + startMonth, + endMonth, + }); let months = monthUtils.rangeInclusive(bounds.start, bounds.end); return (