Calender Navigation #13
@@ -1,42 +1,12 @@
|
|||||||
import React from "react";
|
import React, { useContext } from "react";
|
||||||
import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react";
|
import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react";
|
||||||
import { endOfMonth, getDate } from "date-fns";
|
|
||||||
import CalenderNav from "./CalenderNav";
|
import CalenderNav from "./CalenderNav";
|
||||||
|
import { CalenderContext } from "../../contexts/CalenderContext";
|
||||||
|
|
||||||
const Calender = (): JSX.Element => {
|
const Calender = (): JSX.Element => {
|
||||||
const today = new Date();
|
const { daysOfMonth, daysOfWeek } = useContext(CalenderContext);
|
||||||
|
|
||||||
const endOfCurrMonth = endOfMonth(today);
|
|
||||||
const lastDay = getDate(endOfCurrMonth);
|
|
||||||
|
|
||||||
// console.info(`This month has ${lastDay} days.`);
|
|
||||||
|
|
||||||
const daysOfMonth = [];
|
|
||||||
for (let i = daysOfMonth.length; i < lastDay; i++) {
|
|
||||||
daysOfMonth.push(daysOfMonth.length + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const daysOfWeek = {
|
|
||||||
Sunday: [
|
|
||||||
"Sunday",
|
|
||||||
"Monday",
|
|
||||||
"Tuesday",
|
|
||||||
"Wednesday",
|
|
||||||
"Thursday",
|
|
||||||
"Friday",
|
|
||||||
"Saturday",
|
|
||||||
],
|
|
||||||
Monday: [
|
|
||||||
"Monday",
|
|
||||||
"Tuesday",
|
|
||||||
"Wednesday",
|
|
||||||
"Thursday",
|
|
||||||
"Friday",
|
|
||||||
"Saturday",
|
|
||||||
"Sunday",
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Simulated user settings context
|
||||||
const userSettings = {
|
const userSettings = {
|
||||||
theme: "default",
|
theme: "default",
|
||||||
startOfWeek: "Sunday",
|
startOfWeek: "Sunday",
|
||||||
@@ -54,7 +24,7 @@ const Calender = (): JSX.Element => {
|
|||||||
alignContent="center"
|
alignContent="center"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
>
|
>
|
||||||
{daysOfWeek[userSettings.startOfWeek].map((weekDay) => {
|
{daysOfWeek.startOfWeek[userSettings.startOfWeek].map((weekDay) => {
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
d="flex"
|
d="flex"
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React from "react";
|
import React, { useContext } from "react";
|
||||||
import { Heading, HStack, IconButton } from "@chakra-ui/react";
|
import { Heading, HStack, IconButton } from "@chakra-ui/react";
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
import { CalenderContext } from "../../contexts/CalenderContext";
|
||||||
|
|
||||||
const CalenderNav = (): JSX.Element => {
|
const CalenderNav = (): JSX.Element => {
|
||||||
const today = new Date();
|
const { today } = useContext(CalenderContext);
|
||||||
|
|
||||||
const currentMonth = format(today, "LLLL uuuu");
|
const currentMonth = format(today, "LLLL uuuu");
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Box } from "@chakra-ui/react";
|
import { Box } from "@chakra-ui/react";
|
||||||
import Calender from "../components/calender/Calender";
|
import Calender from "../components/calender/Calender";
|
||||||
|
import { CalenderContextProvider } from "../contexts/CalenderContext";
|
||||||
|
|
||||||
const IndexPage = (): JSX.Element => {
|
const IndexPage = (): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
<Box textAlign="center" w="100%" h="auto" pt="50px" pb="10vh">
|
<Box textAlign="center" w="100%" h="auto" pt="50px" pb="10vh">
|
||||||
|
<CalenderContextProvider>
|
||||||
<Calender />
|
<Calender />
|
||||||
|
</CalenderContextProvider>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user