From 11c80105152cd93f83ab2c182c9f26d9e350ea37 Mon Sep 17 00:00:00 2001 From: Lucid Kobold Date: Wed, 29 Dec 2021 11:40:08 -0600 Subject: [PATCH] Prittier rules. --- .prettierrc | 4 ++- components/calender/DatePicker.tsx | 6 +++- contexts/NewCalenderContext.tsx | 51 ++++++++++-------------------- pages/calendar/[...date].tsx | 4 ++- theme/layout/BackToTopButton.tsx | 6 +++- theme/layout/Header.tsx | 10 ++++-- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/.prettierrc b/.prettierrc index 36b3563..d0ec4af 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,3 +1,5 @@ { - "trailingComma": "none" + "trailingComma": "none", + "tabWidth": 2, + "bracketSameLine": false } diff --git a/components/calender/DatePicker.tsx b/components/calender/DatePicker.tsx index 03d76ed..bf38209 100644 --- a/components/calender/DatePicker.tsx +++ b/components/calender/DatePicker.tsx @@ -165,7 +165,11 @@ const DatePicker = (): JSX.Element => { }); }} > - {(formProps: FormikProps<{ date: string }>) => ( + {( + formProps: FormikProps<{ + date: string; + }> + ) => (
{ - const { endDay: endLastMonth } = prevMonth; + /** + * A function that will return a month layout when given a date. It produces an object with 6 weeks that include overflow from the previous and next month with all dates aligned with the day of the week. + * @param selectedDate The date of the month to generate a month layout for. + */ + const populateMonth = (selectedDate: Date): MonthLayout => { + const endLastMonth = getDate(endOfMonth(sub(selectedDate, { months: 1 }))); + const startOfSelectedMonth = format(startOfMonth(selectedDate), "iii"); const ISOToIndex = { sunday: { @@ -161,7 +152,8 @@ const NewCalenderContextProvider = ({ week6: new Array(7).fill(null) }; - const sunStartDay = endLastMonth - (ISOToIndex.sunday[startOfMonth] - 1); + const sunStartDay = + endLastMonth - (ISOToIndex.sunday[startOfSelectedMonth] - 1); let sunCurrDate = set(sub(selectedDate, { months: 1 }), { date: sunStartDay @@ -175,7 +167,9 @@ const NewCalenderContextProvider = ({ isOverflow: isOverflow(selectedDate, sunCurrDate), date: sunCurrDate }; - sunCurrDate = add(sunCurrDate, { days: 1 }); + sunCurrDate = add(sunCurrDate, { + days: 1 + }); sundays[week][i] = day; }); @@ -190,7 +184,7 @@ const NewCalenderContextProvider = ({ week6: new Array(7).fill(null) }; - const monStartDay = endLastMonth - ISOToIndex.monday[startOfMonth]; + const monStartDay = endLastMonth - ISOToIndex.monday[startOfSelectedMonth]; let monCurrDate = set(sub(selectedDate, { months: 1 }), { date: monStartDay @@ -204,7 +198,9 @@ const NewCalenderContextProvider = ({ isOverflow: isOverflow(selectedDate, monCurrDate), date: monCurrDate }; - monCurrDate = add(monCurrDate, { days: 1 }); + monCurrDate = add(monCurrDate, { + days: 1 + }); mondays[week][i] = day; }); @@ -239,20 +235,7 @@ const NewCalenderContextProvider = ({ const [selectedMonthInfo, setSelectedMonthInfo] = useState({ date: selectedDate, title: format(selectedDate, "LLLL uuuu"), - startDay: format(startOfMonth(selectedDate), "iii"), // TODO Update to use the ISOToIndex dynamically with the user's start day preferences. - endDay: format(endOfMonth(selectedDate), "iii"), // TODO Update to use the ISOToIndex dynamically with the user's start day preferences. - days: getDate(endOfMonth(selectedDate)), - prevMonth: { - date: prevMonth, - endDay: getDate(endOfMonth(prevMonth)) - }, - layout: populateMonth( - selectedDate, - format(startOfMonth(selectedDate), "iii"), - { - endDay: getDate(endOfMonth(prevMonth)) - } - ) + layout: populateMonth(selectedDate) }); //TODO: Update the MonthInfo to use the new month population function on first render. diff --git a/pages/calendar/[...date].tsx b/pages/calendar/[...date].tsx index 1eb321f..83f8d88 100644 --- a/pages/calendar/[...date].tsx +++ b/pages/calendar/[...date].tsx @@ -58,7 +58,9 @@ const DateRoute: React.FC = () => { const parsedSlug = slug.map((e) => { return parseInt(e); }); - setDate({ ...validateDateInput(parsedSlug) }); + setDate({ + ...validateDateInput(parsedSlug) + }); } }, [slug]); diff --git a/theme/layout/BackToTopButton.tsx b/theme/layout/BackToTopButton.tsx index c26a021..ea0f080 100644 --- a/theme/layout/BackToTopButton.tsx +++ b/theme/layout/BackToTopButton.tsx @@ -14,7 +14,11 @@ const BackToTopButton: FC = ({ d={show ? "flex" : "none"} pos="fixed" top="85vh" - right={{ base: "1.25rem", sm: "2rem", md: "3rem" }} + right={{ + base: "1.25rem", + sm: "2rem", + md: "3rem" + }} >