Date align #23

Merged
LucidKobold merged 29 commits from date-align into main 2021-12-29 20:09:30 -05:00
18 changed files with 387 additions and 79 deletions
Showing only changes of commit f8130f55c9 - Show all commits

View File

@@ -54,19 +54,19 @@ interface MonthInfo {
}; };
} }
interface MonthContext extends MonthInfo { interface MonthLayout {
layout: {
sunday: { sunday: {
layout: DaysOfWeek; layout: DaysOfWeek;
header: String;
month: Month; month: Month;
}; };
monday: { monday: {
layout: DaysOfWeek; layout: DaysOfWeek;
header: String;
month: Month; month: Month;
}; };
}; }
interface MonthContext extends MonthInfo {
layout: MonthLayout;
} }
interface CalenderContextState { interface CalenderContextState {
@@ -101,34 +101,6 @@ const NewCalenderContextProvider = ({
] ]
}; };
const [selectedDate, setSelectedMonth] = useState<Date>(new Date());
const [prevMonth, setPrevMonth] = useState<Date>(
sub(selectedDate, { months: 1 })
);
const [selectedMonthInfo, setSelectedMonthInfo] = useState<MonthContext>({
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: {
sunday: {
layout: weekDays.sunday,
header: "Month title here",
month: {} as Month
},
monday: {
layout: weekDays.monday,
header: "Month title here",
month: {} as Month
}
}
});
//TODO Add a function that will populate the "MONTH" layout for the context. It should take in the start of the week (Sunday, Monday) and output the appropriate layout based on that preference. //TODO Add a function that will populate the "MONTH" layout for the context. It should take in the start of the week (Sunday, Monday) and output the appropriate layout based on that preference.
// Checks if the date is before or after the current month. // Checks if the date is before or after the current month.
@@ -151,7 +123,7 @@ const NewCalenderContextProvider = ({
prevMonth: { prevMonth: {
endDay: number; endDay: number;
} }
): void => { ): MonthLayout => {
const { endDay: endLastMonth } = prevMonth; const { endDay: endLastMonth } = prevMonth;
const ISOToIndex = { const ISOToIndex = {
@@ -194,7 +166,7 @@ const NewCalenderContextProvider = ({
const thisWeek = sundays[week]; const thisWeek = sundays[week];
thisWeek.forEach((e, i, a) => { thisWeek.forEach((e, i, a) => {
const day = { const day: MonthDay= {
isOverflow: isOverflow(selectedDate, sunCurrDate), isOverflow: isOverflow(selectedDate, sunCurrDate),
date: sunCurrDate date: sunCurrDate
}; };
@@ -223,7 +195,7 @@ const NewCalenderContextProvider = ({
const thisWeek = mondays[week]; const thisWeek = mondays[week];
thisWeek.forEach((e, i, a) => { thisWeek.forEach((e, i, a) => {
const day = { const day: MonthDay = {
isOverflow: isOverflow(selectedDate, monCurrDate), isOverflow: isOverflow(selectedDate, monCurrDate),
date: monCurrDate date: monCurrDate
}; };
@@ -232,15 +204,51 @@ const NewCalenderContextProvider = ({
mondays[week][i] = day; mondays[week][i] = day;
}); });
} }
const output = {
sunday: {
layout: weekDays.sunday,
month: sundays
},
monday: {
layout: weekDays.monday,
month: mondays
}
};
return output;
}; };
//TODO: Add output typing and move the invocation into the monthInfo state, removing any unended info from the state. //TODO: Add output typing and move the invocation into the monthInfo state, removing any unended info from the state.
populateMonth( // populateMonth(
// selectedDate,
// format(startOfMonth(selectedDate), "iii"),
// selectedMonthInfo.prevMonth
// );
const [selectedDate, setSelectedMonth] = useState<Date>(new Date());
const [prevMonth, setPrevMonth] = useState<Date>(
sub(selectedDate, { months: 1 })
);
const [selectedMonthInfo, setSelectedMonthInfo] = useState<MonthContext>({
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, selectedDate,
format(startOfMonth(selectedDate), "iii"), format(startOfMonth(selectedDate), "iii"),
selectedMonthInfo.prevMonth {
); endDay: getDate(endOfMonth(prevMonth))
}
)
});
//TODO: Update the MonthInfo to use the new month population function on first render. //TODO: Update the MonthInfo to use the new month population function on first render.