From 632674c8982c9e5f3cfd7363fc030651c5b08f54 Mon Sep 17 00:00:00 2001 From: Lucid Kobold <72232219+LucidKobold@users.noreply.github.com> Date: Mon, 13 Jun 2022 15:49:41 -0500 Subject: [PATCH] Updating some documentation. --- data/stickerSeeder.ts | 12 ++++++++---- lib/populateMonth.ts | 18 +++++++++--------- .../calender/modals/AddUpdateSticker.tsx | 12 +++++------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/data/stickerSeeder.ts b/data/stickerSeeder.ts index f6efddb..8e514b7 100644 --- a/data/stickerSeeder.ts +++ b/data/stickerSeeder.ts @@ -7,11 +7,9 @@ import { } from "date-fns"; /** - * This seeder is to simulate the date and sticker info from the database. - * Filling up an array for the current month with sticker from ths first to - * the day before the current date, leaving the rest of the month empty. + * Generated a valid sticker value for use when generating a sticker obj. + * @returns {ValidStickerVal} a number that will represent a valid sticker value. */ - const generateSticker = (): -2 | -1 | 0 | 1 | 2 => { const sticker = Math.floor(Math.random() * (2 - -2 + 1)) + -2; @@ -26,6 +24,12 @@ const generateSticker = (): -2 | -1 | 0 | 1 | 2 => { } }; +/** + * This seeder is to simulate the date and sticker info from the database. + * Filling up an array for the current month with sticker from ths first to + * the day before the current date, leaving the rest of the month empty. + * @returns {StickerDays} an array with populated sticker objects that correspond to the current month's info. + */ const stickersSeeder = (): StickerDays => { const stickers = [] as Sticker[]; diff --git a/lib/populateMonth.ts b/lib/populateMonth.ts index 0834a0b..84a442f 100644 --- a/lib/populateMonth.ts +++ b/lib/populateMonth.ts @@ -7,7 +7,9 @@ import { set, add, isAfter, - isBefore + isBefore, + subMonths, + addDays } from "date-fns"; const weekDays: WeekDays = { @@ -104,10 +106,11 @@ const populateMonth = (selectedDate: Date): MonthLayout => { week6: new Array(7).fill(null) }; + // The date of the first day in the overflow const sunStartDay = endLastMonth - (ISOToIndex.sunday[startOfSelectedMonth] - 1); - let sunCurrDate = set(sub(selectedDate, { months: 1 }), { + let sunCurrDate = set(subMonths(selectedDate, 1), { date: sunStartDay }); @@ -122,9 +125,7 @@ const populateMonth = (selectedDate: Date): MonthLayout => { date: sunCurrDate.toJSON() }; - sunCurrDate = add(sunCurrDate, { - days: 1 - }); + sunCurrDate = addDays(sunCurrDate, 1); sundays[week][i] = day; }); @@ -139,9 +140,10 @@ const populateMonth = (selectedDate: Date): MonthLayout => { week6: new Array(7).fill(null) }; + // The date of the first day in the overflow const monStartDay = endLastMonth - ISOToIndex.monday[startOfSelectedMonth]; - let monCurrDate = set(sub(selectedDate, { months: 1 }), { + let monCurrDate = set(subMonths(selectedDate, 1), { date: monStartDay }); @@ -156,9 +158,7 @@ const populateMonth = (selectedDate: Date): MonthLayout => { date: monCurrDate.toJSON() }; - monCurrDate = add(monCurrDate, { - days: 1 - }); + monCurrDate = addDays(monCurrDate, 1); mondays[week][i] = day; }); diff --git a/src/components/calender/modals/AddUpdateSticker.tsx b/src/components/calender/modals/AddUpdateSticker.tsx index a657272..a82c19d 100644 --- a/src/components/calender/modals/AddUpdateSticker.tsx +++ b/src/components/calender/modals/AddUpdateSticker.tsx @@ -57,10 +57,8 @@ const AddUpdateSticker = ({ const dispatch = useAppDispatch(); const currDateObj = new Date(date); - // ! Update these states to say "add" and "edit" for easier reading. - - const [modalVariant] = useState<"currDate" | "notCurrDate">( - isSameDay(currDateObj, currDate) ? "currDate" : "notCurrDate" + const [modalVariant] = useState<"add" | "edit">( + isSameDay(currDateObj, currDate) ? "add" : "edit" ); const handleClose = () => { @@ -79,7 +77,7 @@ const AddUpdateSticker = ({ // * Double check that the submit button is disabled if the selected sticker is the same as the current sticker. const variants = { - currDate: [ + add: [ { header: `Which sticker did you earn for ${format( currDateObj, @@ -118,7 +116,7 @@ const AddUpdateSticker = ({ ) } ], - notCurrDate: [ + edit: [ { header: `Which sticker did you want to update for ${format( currDateObj, @@ -234,7 +232,7 @@ const AddUpdateSticker = ({ onClose={() => handleClose()} motionPreset="slideInBottom" scrollBehavior="inside" - size={modalVariant === "currDate" ? "xl" : "2xl"} + size={modalVariant === "add" ? "xl" : "2xl"} >