diff --git a/src/features/HomePage/hooks.tsx b/src/features/HomePage/hooks.tsx index efe3923c..3bbf437d 100644 --- a/src/features/HomePage/hooks.tsx +++ b/src/features/HomePage/hooks.tsx @@ -34,7 +34,7 @@ const getTimezoneOffset = (date: Date) => { const getDate = (date: Date) => format(date, 'yyyy-MM-dd') export const useHomePage = () => { - const { userInfo } = useAuthStore() + const { user, userInfo } = useAuthStore() const { selectedDate } = useHeaderFiltersStore() const [isOpenDownload, setIsOpenDownload] = useState(false) const [isShowConfirmPopup, setIsShowConfirmPopup] = useState(false) @@ -75,7 +75,7 @@ export const useHomePage = () => { timezoneOffset: getTimezoneOffset(selectedDate), }), // eslint-disable-next-line react-hooks/exhaustive-deps - [selectedDate, userInfo?.email], + [selectedDate, user], ) useEffect(() => { diff --git a/src/features/UserFavorites/hooks/index.tsx b/src/features/UserFavorites/hooks/index.tsx index bffa44d4..42554489 100644 --- a/src/features/UserFavorites/hooks/index.tsx +++ b/src/features/UserFavorites/hooks/index.tsx @@ -1,5 +1,6 @@ import { useCallback, + useEffect, useMemo, useState, } from 'react' @@ -42,7 +43,7 @@ export type SuperTournament = ObjectWithName & { type Args = Parameters[0] export const useUserFavorites = () => { - const { userInfo } = useAuthStore() + const { user, userInfo } = useAuthStore() const [userFavorites, setUserFavorites] = useState([]) const [playerHighlight, setPlayerHighlight] = useState({} as ProfileType) @@ -97,6 +98,14 @@ export const useUserFavorites = () => { }) } + useEffect(() => { + if (!user) return + + fetchFavorites() + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [fetchFavorites]) + const addRemoveFavorite = (args: Args) => { modifyUserFavorites(args).then(setUserFavorites, open) } diff --git a/src/features/UserFavorites/index.tsx b/src/features/UserFavorites/index.tsx index 3f343a85..5e9465ac 100644 --- a/src/features/UserFavorites/index.tsx +++ b/src/features/UserFavorites/index.tsx @@ -1,7 +1,6 @@ import { MouseEvent, FocusEvent, - useEffect, useState, } from 'react' @@ -29,8 +28,6 @@ import { ScrollWrapper, } from './styled' -import { useAuthStore } from '../AuthStore' - type Props = { marginTop?: number, } @@ -39,22 +36,14 @@ export const UserFavorites = ({ marginTop }: Props) => { const { addRemoveFavorite, close, - fetchFavorites, isOpen, removeSuperTournament, superTournaments, userFavorites, } = useUserFavoritesStore() - const { user } = useAuthStore() const [position, setPosition] = useState(0) - useEffect(() => { - if (!user) return - fetchFavorites() - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [fetchFavorites]) - const getPosition = (event: MouseEvent | FocusEvent) => { if (event.currentTarget) { setPosition(event.currentTarget.getBoundingClientRect().top)