More use effect effeciency.

This commit is contained in:
Lucid Kobold
2022-06-23 13:59:43 -05:00
parent 488f56354d
commit f808f6b250
4 changed files with 26 additions and 12 deletions

View File

@@ -43,7 +43,7 @@ const Calender = ({
console.warn("Invalid date format: ", newDate); console.warn("Invalid date format: ", newDate);
} }
} }
}, [dispatch, newDate]); }, [currentSelectedDateStr, dispatch, newDate]);
useEffect(() => { useEffect(() => {
// console.info("Check to update date."); // console.info("Check to update date.");
@@ -151,7 +151,7 @@ const Calender = ({
id.length id.length
? id ? id
: format(toDateObj, "yyyyddLL") + : format(toDateObj, "yyyyddLL") +
`/${sticker === null ? 0 : sticker}` `/${sticker === null ? 0 : sticker}`
} }
/> />
); );

View File

@@ -7,18 +7,23 @@ import Day from "../calender/Day";
interface CalenderExampleProps { interface CalenderExampleProps {
type: "add" | "edit"; type: "add" | "edit";
isLoading: boolean;
} }
const CalenderExample = ({ type }: CalenderExampleProps): JSX.Element => { const CalenderExample = ({
type,
isLoading
}: CalenderExampleProps): JSX.Element => {
// TODO: Check if the current date is the start of the user's preferred start of the week and use the previous week for the edit example. // TODO: Check if the current date is the start of the user's preferred start of the week and use the previous week for the edit example.
// TODO: Add highlight to the current date for the add example and highlight other dates when the edit example is used. // TODO: Add highlight to the current date for the add example and highlight other dates when the edit example is used.
// TODO: Disable the days that shouldn't have a function to prevent edits on add example and add to current date on the edit example. // TODO: Disable the days that shouldn't have a function to prevent edits on add example and add to current date on the edit example.
const currDateStr: string = useAppSelector(state => state.calender.currDate); const currDateStr: string = useAppSelector(
(state) => state.calender.currDate
);
const currDateObj: Date = new Date(currDateStr); const currDateObj: Date = new Date(currDateStr);
const isLoading = false;
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();

View File

@@ -1,3 +1,6 @@
import React from "react";
import { useAppDispatch, useAppSelector } from "../../app/hooks";
import { toggleRememberCompleted } from "../../features/tutorial";
import { import {
Box, Box,
Button, Button,
@@ -8,9 +11,6 @@ import {
Text, Text,
VStack VStack
} from "@chakra-ui/react"; } from "@chakra-ui/react";
import React from "react";
import { useAppDispatch, useAppSelector } from "../../app/hooks";
import { toggleRememberCompleted } from "../../features/tutorial";
import CustomButton from "../buttons/Custom"; import CustomButton from "../buttons/Custom";
import Patreon from "../buttons/Patreon"; import Patreon from "../buttons/Patreon";
import Twitter from "../buttons/Twitter"; import Twitter from "../buttons/Twitter";
@@ -19,11 +19,13 @@ import CalenderExample from "./CalenderExample";
interface TutorialProps { interface TutorialProps {
setTutorialComplete: () => void; setTutorialComplete: () => void;
setTempTutorialComplete: () => void; setTempTutorialComplete: () => void;
isLoading: boolean;
} }
const Tutorial = ({ const Tutorial = ({
setTutorialComplete, setTutorialComplete,
setTempTutorialComplete setTempTutorialComplete,
isLoading
}: TutorialProps): JSX.Element => { }: TutorialProps): JSX.Element => {
const rememberComplete = useAppSelector( const rememberComplete = useAppSelector(
(state) => state.tutorial.rememberCompleted (state) => state.tutorial.rememberCompleted
@@ -271,7 +273,12 @@ const Tutorial = ({
alignItems="flex-start" alignItems="flex-start"
pt={8} pt={8}
> >
<Button type="button" onClick={() => handleSkip()} variant="skip"> <Button
type="button"
isDisabled={isLoading}
onClick={() => handleSkip()}
variant="skip"
>
{"Skip"} {"Skip"}
</Button> </Button>
<VStack <VStack
@@ -283,6 +290,7 @@ const Tutorial = ({
> >
<Button <Button
type="button" type="button"
isDisabled={isLoading}
onClick={() => handleComplete()} onClick={() => handleComplete()}
variant="primary" variant="primary"
> >
@@ -290,6 +298,7 @@ const Tutorial = ({
</Button> </Button>
<Checkbox <Checkbox
isChecked={rememberComplete} isChecked={rememberComplete}
isDisabled={isLoading}
onChange={() => handleUpdateCheck()} onChange={() => handleUpdateCheck()}
> >
{"Remember completed?"} {"Remember completed?"}

View File

@@ -39,9 +39,8 @@ const IndexPage = (): JSX.Element => {
}; };
useEffect(() => { useEffect(() => {
if (completedTutorial === null || tutorialCompletionInfo === null) { if (completedTutorial === null && tutorialCompletionInfo === null) {
dispatch(getAndSetTutorial()); dispatch(getAndSetTutorial());
dispatch(updateLoading(false));
} }
if (completedTutorial !== null) { if (completedTutorial !== null) {
@@ -63,6 +62,7 @@ const IndexPage = (): JSX.Element => {
<Tutorial <Tutorial
setTutorialComplete={handleTutorialCompleted} setTutorialComplete={handleTutorialCompleted}
setTempTutorialComplete={handleTempTutorialCompleted} setTempTutorialComplete={handleTempTutorialCompleted}
isLoading={isLoading}
/> />
)} )}
</Provider> </Provider>