diff --git a/packages/loot-design/src/components/budget/index.js b/packages/loot-design/src/components/budget/index.js index 27b726422e..21c2297ffa 100644 --- a/packages/loot-design/src/components/budget/index.js +++ b/packages/loot-design/src/components/budget/index.js @@ -1,7 +1,5 @@ import React, { useContext, useState, useMemo } from 'react'; -import { scope } from '@jlongster/lively'; - import * as monthUtils from 'loot-core/src/shared/months'; import { styles, colors } from '../../style'; @@ -1243,182 +1241,159 @@ export const BudgetPageHeader = React.memo( }, ); -export const MonthPicker = scope(lively => { - function getRangeForYear(year) { - return monthUtils.rangeInclusive( - monthUtils.getYearStart(year), - monthUtils.getYearEnd(year), - ); - } +function getRangeForYear(year) { + return monthUtils.rangeInclusive( + monthUtils.getYearStart(year), + monthUtils.getYearEnd(year), + ); +} - function getMonth(year, idx) { - return monthUtils.addMonths(year, idx); - } +function getMonth(year, idx) { + return monthUtils.addMonths(year, idx); +} - function getCurrentMonthName(startMonth, currentMonth) { - return monthUtils.getYear(startMonth) === monthUtils.getYear(currentMonth) - ? monthUtils.format(currentMonth, 'MMM') - : null; - } +function getCurrentMonthName(startMonth, currentMonth) { + return monthUtils.getYear(startMonth) === monthUtils.getYear(currentMonth) + ? monthUtils.format(currentMonth, 'MMM') + : null; +} - function getInitialState({ props: { startMonth, monthBounds } }) { - const currentMonth = monthUtils.currentMonth(); - const range = getRangeForYear(currentMonth); - const monthNames = range.map(month => { - return monthUtils.format(month, 'MMM'); - }); +export const MonthPicker = ({ + startMonth, + numDisplayed, + monthBounds, + style, + onSelect, +}) => { + const currentMonth = monthUtils.currentMonth(); + const range = getRangeForYear(currentMonth); + const monthNames = range.map(month => { + return monthUtils.format(month, 'MMM'); + }); + const currentMonthName = getCurrentMonthName(startMonth, currentMonth); + const year = monthUtils.getYear(startMonth); + const selectedIndex = monthUtils.getMonthIndex(startMonth); - return { - monthNames, - currentMonthName: getCurrentMonthName(startMonth, currentMonth), - }; - } - - function componentWillReceiveProps({ props }, nextProps) { - if ( - monthUtils.getYear(props.startMonth) !== - monthUtils.getYear(nextProps.startMonth) - ) { - return { - currentMonthName: getCurrentMonthName( - nextProps.startMonth, - monthUtils.currentMonth(), - ), - }; - } - } - - function MonthPicker({ - state: { monthNames, currentMonthName }, - props: { startMonth, numDisplayed, monthBounds, style, onSelect }, - }) { - const year = monthUtils.getYear(startMonth); - const selectedIndex = monthUtils.getMonthIndex(startMonth); - - return ( + return ( + + {monthUtils.format(year, 'yyyy')} + + - - {monthUtils.format(year, 'yyyy')} - - - {(matched, ref) => ( - - {monthNames.map((monthName, idx) => { - const lastSelectedIndex = selectedIndex + numDisplayed; - const selected = - idx >= selectedIndex && idx < lastSelectedIndex; - const current = monthName === currentMonthName; - const month = getMonth(year, idx); - const isMonthBudgeted = - month >= monthBounds.start && month <= monthBounds.end; + {(matched, ref) => ( + + {monthNames.map((monthName, idx) => { + const lastSelectedIndex = selectedIndex + numDisplayed; + const selected = idx >= selectedIndex && idx < lastSelectedIndex; + const current = monthName === currentMonthName; + const month = getMonth(year, idx); + const isMonthBudgeted = + month >= monthBounds.start && month <= monthBounds.end; - return ( - = selectedIndex && + idx < lastSelectedIndex - 1 && { + marginRight: 0, + borderRight: 'solid 1px', + borderColor: colors.p6, }, - idx === lastSelectedIndex - 1 && { - borderTopRightRadius: 2, - borderBottomRightRadius: 2, - }, - idx >= selectedIndex && - idx < lastSelectedIndex - 1 && { - marginRight: 0, - borderRight: 'solid 1px', - borderColor: colors.p6, - }, - current && { textDecoration: 'underline' }, - ]} - onClick={() => onSelect(month)} - > - {matched && matched.size === 'small' - ? monthName[0] - : monthName} - - ); - })} - - )} - - onSelect(month)} + > + {matched && matched.size === 'small' + ? monthName[0] + : monthName} + + ); + })} + + )} + + + - - + + + - ); - } - - return lively(MonthPicker, { getInitialState, componentWillReceiveProps }); -}); + + ); +};