From f808f6b2501bb2b9a4f8f300d7ed729692bee1c5 Mon Sep 17 00:00:00 2001 From: Lucid Kobold <72232219+LucidKobold@users.noreply.github.com> Date: Thu, 23 Jun 2022 13:59:43 -0500 Subject: [PATCH] More use effect effeciency. --- src/components/calender/index.tsx | 4 ++-- src/components/tutorial/CalenderExample.tsx | 11 ++++++++--- src/components/tutorial/index.tsx | 19 ++++++++++++++----- src/pages/index.tsx | 4 ++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/components/calender/index.tsx b/src/components/calender/index.tsx index 41b7358..44a059d 100644 --- a/src/components/calender/index.tsx +++ b/src/components/calender/index.tsx @@ -43,7 +43,7 @@ const Calender = ({ console.warn("Invalid date format: ", newDate); } } - }, [dispatch, newDate]); + }, [currentSelectedDateStr, dispatch, newDate]); useEffect(() => { // console.info("Check to update date."); @@ -151,7 +151,7 @@ const Calender = ({ id.length ? id : format(toDateObj, "yyyyddLL") + - `/${sticker === null ? 0 : sticker}` + `/${sticker === null ? 0 : sticker}` } /> ); diff --git a/src/components/tutorial/CalenderExample.tsx b/src/components/tutorial/CalenderExample.tsx index 002c4c2..6adb03d 100644 --- a/src/components/tutorial/CalenderExample.tsx +++ b/src/components/tutorial/CalenderExample.tsx @@ -7,18 +7,23 @@ import Day from "../calender/Day"; interface CalenderExampleProps { 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: 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. - const currDateStr: string = useAppSelector(state => state.calender.currDate); + const currDateStr: string = useAppSelector( + (state) => state.calender.currDate + ); const currDateObj: Date = new Date(currDateStr); - const isLoading = false; const dispatch = useAppDispatch(); diff --git a/src/components/tutorial/index.tsx b/src/components/tutorial/index.tsx index 982c2fd..571c5f9 100644 --- a/src/components/tutorial/index.tsx +++ b/src/components/tutorial/index.tsx @@ -1,3 +1,6 @@ +import React from "react"; +import { useAppDispatch, useAppSelector } from "../../app/hooks"; +import { toggleRememberCompleted } from "../../features/tutorial"; import { Box, Button, @@ -8,9 +11,6 @@ import { Text, VStack } 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 Patreon from "../buttons/Patreon"; import Twitter from "../buttons/Twitter"; @@ -19,11 +19,13 @@ import CalenderExample from "./CalenderExample"; interface TutorialProps { setTutorialComplete: () => void; setTempTutorialComplete: () => void; + isLoading: boolean; } const Tutorial = ({ setTutorialComplete, - setTempTutorialComplete + setTempTutorialComplete, + isLoading }: TutorialProps): JSX.Element => { const rememberComplete = useAppSelector( (state) => state.tutorial.rememberCompleted @@ -271,7 +273,12 @@ const Tutorial = ({ alignItems="flex-start" pt={8} > - handleUpdateCheck()} > {"Remember completed?"} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index b9c0430..9a57ed2 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -39,9 +39,8 @@ const IndexPage = (): JSX.Element => { }; useEffect(() => { - if (completedTutorial === null || tutorialCompletionInfo === null) { + if (completedTutorial === null && tutorialCompletionInfo === null) { dispatch(getAndSetTutorial()); - dispatch(updateLoading(false)); } if (completedTutorial !== null) { @@ -63,6 +62,7 @@ const IndexPage = (): JSX.Element => { )}