Imported the new context to calendar componenet.

This commit is contained in:
Lucid Kobold
2021-12-29 13:52:39 -06:00
parent ee481158f0
commit 96a9bedf9a
4 changed files with 44 additions and 31 deletions

View File

@@ -3,12 +3,11 @@ import { Box, Text } from "@chakra-ui/react";
import { NewCalenderContext } from "../../contexts/NewCalenderContext"; import { NewCalenderContext } from "../../contexts/NewCalenderContext";
const NewContext = (): JSX.Element => { const NewContext = (): JSX.Element => {
const { selectedMonthInfo } = useContext(NewCalenderContext); const { selectedDate } = useContext(NewCalenderContext);
const { date } = selectedMonthInfo;
return ( return (
<Box> <Box>
<Text>{`New Context Was Provided. Selected date is ${date}`}</Text> <Text>{`New Context Was Provided. Selected date is ${selectedDate}`}</Text>
</Box> </Box>
); );
}; };

View File

@@ -2,7 +2,8 @@ import React, { useContext, useEffect } from "react";
import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react"; import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react";
import CalenderNav from "./CalenderNav"; import CalenderNav from "./CalenderNav";
import { CalenderContext } from "../../contexts/CalenderContext"; import { CalenderContext } from "../../contexts/CalenderContext";
import NewContext from "./NewContext"; import { NewCalenderContext } from "../../contexts/NewCalenderContext";
import { getDate } from "date-fns";
interface UpdateCalendarProps { interface UpdateCalendarProps {
year: number; year: number;
@@ -12,6 +13,7 @@ interface UpdateCalendarProps {
const Calender = (newDate?: UpdateCalendarProps): JSX.Element => { const Calender = (newDate?: UpdateCalendarProps): JSX.Element => {
const { daysOfMonth, daysOfWeek, setDate } = useContext(CalenderContext); const { daysOfMonth, daysOfWeek, setDate } = useContext(CalenderContext);
const { layout } = useContext(NewCalenderContext);
useEffect(() => { useEffect(() => {
if (newDate) { if (newDate) {
@@ -31,9 +33,12 @@ const Calender = (newDate?: UpdateCalendarProps): JSX.Element => {
startOfWeek: "Sunday" startOfWeek: "Sunday"
}; };
const currMonth = layout[`${userSettings.startOfWeek.toLowerCase()}`];
const { month, weekdays } = currMonth;
return ( return (
<VStack h="100vh" w="100%"> <VStack h="100vh" w="100%">
<NewContext /> {/* <NewContext /> */}
<CalenderNav /> <CalenderNav />
<HStack <HStack
px={6} px={6}
@@ -44,7 +49,7 @@ const Calender = (newDate?: UpdateCalendarProps): JSX.Element => {
alignContent="center" alignContent="center"
alignItems="center" alignItems="center"
> >
{daysOfWeek.startOfWeek[userSettings.startOfWeek].map((weekDay) => { {weekdays.map((weekDay) => {
return ( return (
<Box <Box
d="flex" d="flex"
@@ -73,20 +78,27 @@ const Calender = (newDate?: UpdateCalendarProps): JSX.Element => {
// alignContent="center" // alignContent="center"
alignItems="center" alignItems="center"
> >
{daysOfMonth.map((monthDay) => { {Object.keys(month).map((week) => {
return ( const thisWeek = month[week];
<Box
bg="transparent" return thisWeek.map((day) => {
border="2px solid #0068ff" const { date, isOverflow } = day;
w="100%"
h="100%" return (
key={monthDay} <Box
> bg="transparent"
<Text w="100%" h="100%"> color={isOverflow ? "gray.600" : "whiteAlpha"}
{`Day ${monthDay}`} border={isOverflow ? "2px solid #181d8f" : "2px solid #0068ff"}
</Text> w="100%"
</Box> h="100%"
); key={date}
>
<Text w="100%" h="100%">
{`Day ${getDate(date)}`}
</Text>
</Box>
);
});
})} })}
</SimpleGrid> </SimpleGrid>
</VStack> </VStack>

View File

@@ -49,11 +49,11 @@ interface MonthInfo {
interface MonthLayout { interface MonthLayout {
sunday: { sunday: {
layout: DaysOfWeek; weekdays: DaysOfWeek;
month: Month; month: Month;
}; };
monday: { monday: {
layout: DaysOfWeek; weekdays: DaysOfWeek;
month: Month; month: Month;
}; };
} }
@@ -63,7 +63,9 @@ interface MonthContext extends MonthInfo {
} }
interface CalenderContextState { interface CalenderContextState {
selectedMonth: MonthContext; selectedDate: Date;
title: string;
layout: MonthLayout;
} }
const NewCalenderContext = createContext({} as CalenderContextState); const NewCalenderContext = createContext({} as CalenderContextState);
@@ -210,11 +212,11 @@ const NewCalenderContextProvider = ({
const output = { const output = {
sunday: { sunday: {
layout: weekDays.sunday, weekdays: weekDays.sunday,
month: sundays month: sundays
}, },
monday: { monday: {
layout: weekDays.monday, weekdays: weekDays.monday,
month: mondays month: mondays
} }
}; };
@@ -231,10 +233,7 @@ const NewCalenderContextProvider = ({
// ); // );
const [selectedDate, setSelectedMonth] = useState<Date>(new Date()); const [selectedDate, setSelectedMonth] = useState<Date>(new Date());
const [prevMonth, setPrevMonth] = useState<Date>( const [selectedDateInfo, setSelectedMonthInfo] = useState<MonthContext>({
sub(selectedDate, { months: 1 })
);
const [selectedMonthInfo, setSelectedMonthInfo] = useState<MonthContext>({
date: selectedDate, date: selectedDate,
title: format(selectedDate, "LLLL uuuu"), title: format(selectedDate, "LLLL uuuu"),
layout: populateMonth(selectedDate) layout: populateMonth(selectedDate)
@@ -249,7 +248,9 @@ const NewCalenderContextProvider = ({
//TODO: Add a useEffect that will trigger the update function(s) to run when the selected date is updated. //TODO: Add a useEffect that will trigger the update function(s) to run when the selected date is updated.
const calenderContextValues = { const calenderContextValues = {
selectedMonthInfo selectedDate: selectedDate,
title: selectedDateInfo.title,
layout: selectedDateInfo.layout
}; };
return ( return (

View File

@@ -1,5 +1,5 @@
import { extendTheme, ThemeConfig } from "@chakra-ui/react"; import { extendTheme, ThemeConfig } from "@chakra-ui/react";
import { createBreakpoints } from "@chakra-ui/theme-tools"; // import { createBreakpoints } from "@chakra-ui/theme-tools";
import buttons from "./components/buttonStyles"; import buttons from "./components/buttonStyles";
const config: ThemeConfig = { const config: ThemeConfig = {
@@ -20,6 +20,7 @@ const AppTheme = extendTheme({
colors: { colors: {
brand: { brand: {
main: "#3138dc", main: "#3138dc",
mainInactive: "#181d8f",
primary: "#0068ff", primary: "#0068ff",
secondary: "#0086ff", secondary: "#0086ff",
hover: "#00aec1", hover: "#00aec1",