Tutorial #62
@@ -1,9 +1,10 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect } from "react";
|
||||||
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
||||||
import { updateMonth } from "../../features/calender";
|
import { updateMonth } from "../../features/calender";
|
||||||
import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react";
|
import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react";
|
||||||
import { format, isSameDay, isToday } from "date-fns";
|
import { format, isSameDay, isToday } from "date-fns";
|
||||||
import Day from "../calender/Day";
|
import Day from "../calender/Day";
|
||||||
|
import { setCurrentWeek } from "../../features/tutorial";
|
||||||
|
|
||||||
interface CalenderExampleProps {
|
interface CalenderExampleProps {
|
||||||
type: "add" | "edit";
|
type: "add" | "edit";
|
||||||
@@ -30,7 +31,6 @@ const CalenderExample = ({
|
|||||||
const { layout, date: currSelectedDateStr } = selectedDate;
|
const { layout, date: currSelectedDateStr } = selectedDate;
|
||||||
|
|
||||||
// * Stickers * //
|
// * Stickers * //
|
||||||
|
|
||||||
const stickersMonth: StickerDays = useAppSelector(
|
const stickersMonth: StickerDays = useAppSelector(
|
||||||
(state) => state.stickers.stickersMonth
|
(state) => state.stickers.stickersMonth
|
||||||
);
|
);
|
||||||
@@ -56,7 +56,9 @@ const CalenderExample = ({
|
|||||||
}, [currDateStr, currSelectedDateStr, dispatch]);
|
}, [currDateStr, currSelectedDateStr, dispatch]);
|
||||||
|
|
||||||
// * The current week * //
|
// * The current week * //
|
||||||
|
const currWeek = useAppSelector((state) => state.tutorial.currWeek);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
const getCurrentWeek = (): MonthDay[] => {
|
const getCurrentWeek = (): MonthDay[] => {
|
||||||
let foundWeek: MonthDay[] | null;
|
let foundWeek: MonthDay[] | null;
|
||||||
for (const week in month) {
|
for (const week in month) {
|
||||||
@@ -74,7 +76,10 @@ const CalenderExample = ({
|
|||||||
return foundWeek || ([] as MonthDay[]);
|
return foundWeek || ([] as MonthDay[]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [currWeek /*, setCurrWeek*/] = useState<MonthDay[]>(getCurrentWeek());
|
if (currWeek === null) {
|
||||||
|
dispatch(setCurrentWeek(getCurrentWeek()));
|
||||||
|
}
|
||||||
|
}, [currWeek, dispatch, month]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack h="8.5rem" w="100%" spacing={0}>
|
<VStack h="8.5rem" w="100%" spacing={0}>
|
||||||
@@ -122,7 +127,8 @@ const CalenderExample = ({
|
|||||||
columns={7}
|
columns={7}
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
>
|
>
|
||||||
{currWeek.map((day: MonthDay) => {
|
{currWeek &&
|
||||||
|
currWeek.map((day: MonthDay) => {
|
||||||
const { date, isOverflow, overflowDirection } = day;
|
const { date, isOverflow, overflowDirection } = day;
|
||||||
|
|
||||||
const toDateObj: Date = new Date(date);
|
const toDateObj: Date = new Date(date);
|
||||||
|
|||||||
@@ -29,15 +29,22 @@ const TutorialLinks = (): JSX.Element => {
|
|||||||
const { href, name, type } = link;
|
const { href, name, type } = link;
|
||||||
|
|
||||||
if (type === "primary" || type === "secondary") {
|
if (type === "primary" || type === "secondary") {
|
||||||
return <CustomButton link={href} text={name} type={type} />;
|
return (
|
||||||
|
<CustomButton
|
||||||
|
key={name.replaceAll(" ", "-")}
|
||||||
|
link={href}
|
||||||
|
text={name}
|
||||||
|
type={type}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "patreon") {
|
if (type === "patreon") {
|
||||||
return <Patreon />;
|
return <Patreon key={type} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "twitter") {
|
if (type === "twitter") {
|
||||||
return <Twitter />;
|
return <Twitter key={type} />;
|
||||||
}
|
}
|
||||||
})}
|
})}
|
||||||
</HStack>
|
</HStack>
|
||||||
@@ -53,15 +60,22 @@ const TutorialLinks = (): JSX.Element => {
|
|||||||
const { href, name, type } = link;
|
const { href, name, type } = link;
|
||||||
|
|
||||||
if (type === "primary" || type === "secondary") {
|
if (type === "primary" || type === "secondary") {
|
||||||
return <CustomButton link={href} text={name} type={type} />;
|
return (
|
||||||
|
<CustomButton
|
||||||
|
key={name.replaceAll(" ", "-")}
|
||||||
|
link={href}
|
||||||
|
text={name}
|
||||||
|
type={type}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "patreon") {
|
if (type === "patreon") {
|
||||||
return <Patreon />;
|
return <Patreon key={type} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "twitter") {
|
if (type === "twitter") {
|
||||||
return <Twitter />;
|
return <Twitter key={type} />;
|
||||||
}
|
}
|
||||||
})}
|
})}
|
||||||
</VStack>
|
</VStack>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createSlice /*, PayloadAction*/ } from "@reduxjs/toolkit";
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
import { addMonths } from "date-fns";
|
import { addMonths } from "date-fns";
|
||||||
|
|
||||||
interface StorageState {
|
interface StorageState {
|
||||||
@@ -37,12 +37,14 @@ interface TutorialSlice {
|
|||||||
completedTutorial: boolean | null;
|
completedTutorial: boolean | null;
|
||||||
storageState: StorageState | null;
|
storageState: StorageState | null;
|
||||||
rememberCompleted: boolean;
|
rememberCompleted: boolean;
|
||||||
|
currWeek: MonthDay[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: TutorialSlice = {
|
const initialState: TutorialSlice = {
|
||||||
completedTutorial: null,
|
completedTutorial: null,
|
||||||
storageState: null,
|
storageState: null,
|
||||||
rememberCompleted: false
|
rememberCompleted: false,
|
||||||
|
currWeek: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const tutorialSlice = createSlice({
|
const tutorialSlice = createSlice({
|
||||||
@@ -104,6 +106,12 @@ const tutorialSlice = createSlice({
|
|||||||
const { rememberCompleted } = state;
|
const { rememberCompleted } = state;
|
||||||
|
|
||||||
state.rememberCompleted = !rememberCompleted;
|
state.rememberCompleted = !rememberCompleted;
|
||||||
|
},
|
||||||
|
// Set current week
|
||||||
|
setCurrentWeek(state: TutorialSlice, action: PayloadAction<MonthDay[]>) {
|
||||||
|
const { payload } = action;
|
||||||
|
|
||||||
|
state.currWeek = payload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -113,6 +121,7 @@ export const {
|
|||||||
setTutorialCompleted,
|
setTutorialCompleted,
|
||||||
clearTutorialCompleted,
|
clearTutorialCompleted,
|
||||||
getAndSetTutorial,
|
getAndSetTutorial,
|
||||||
toggleRememberCompleted
|
toggleRememberCompleted,
|
||||||
|
setCurrentWeek
|
||||||
} = tutorialSlice.actions;
|
} = tutorialSlice.actions;
|
||||||
export default tutorialSlice.reducer;
|
export default tutorialSlice.reducer;
|
||||||
|
|||||||
Reference in New Issue
Block a user