From 7ee4b8e55695e88b58f6f5a31bc48c6b336ed1a5 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 21 Mar 2022 17:52:57 -0300 Subject: [PATCH] Fix issue --- client/views/root/MainLayout/MainLayout.tsx | 15 ++++++++++----- client/views/root/MainLayout/UsernameCheck.tsx | 2 -- client/views/root/MainLayout/useCustomScript.ts | 13 ++++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/client/views/root/MainLayout/MainLayout.tsx b/client/views/root/MainLayout/MainLayout.tsx index bfa3e8ebac52..84fe7f8b1838 100644 --- a/client/views/root/MainLayout/MainLayout.tsx +++ b/client/views/root/MainLayout/MainLayout.tsx @@ -3,15 +3,20 @@ import React, { ReactElement, useMemo } from 'react'; import BlazeTemplate from '../BlazeTemplate'; import AuthenticationCheck from './AuthenticationCheck'; import Preload from './Preload'; +import { useCustomScript } from './useCustomScript'; type MainLayoutProps = { center?: string; } & Record; -const MainLayout = ({ center }: MainLayoutProps): ReactElement => ( - - {useMemo(() => (center ? : null), [center])} - -); +const MainLayout = ({ center }: MainLayoutProps): ReactElement => { + useCustomScript(); + + return ( + + {useMemo(() => (center ? : null), [center])} + + ); +}; export default MainLayout; diff --git a/client/views/root/MainLayout/UsernameCheck.tsx b/client/views/root/MainLayout/UsernameCheck.tsx index 13979fc919f3..d087bdb3c339 100644 --- a/client/views/root/MainLayout/UsernameCheck.tsx +++ b/client/views/root/MainLayout/UsernameCheck.tsx @@ -7,12 +7,10 @@ import { useUserId } from '../../../contexts/UserContext'; import { useReactiveValue } from '../../../hooks/useReactiveValue'; import BlazeTemplate from '../BlazeTemplate'; import PasswordChangeCheck from './PasswordChangeCheck'; -import { useCustomScript } from './useCustomScript'; import { useViewportScrolling } from './useViewportScrolling'; const UsernameCheck = ({ children }: { children: ReactNode }): ReactElement => { useViewportScrolling(); - useCustomScript(); const uid = useUserId(); const allowAnonymousRead = useSetting('Accounts_AllowAnonymousRead'); diff --git a/client/views/root/MainLayout/useCustomScript.ts b/client/views/root/MainLayout/useCustomScript.ts index 823ea5e09078..fe29013c7443 100644 --- a/client/views/root/MainLayout/useCustomScript.ts +++ b/client/views/root/MainLayout/useCustomScript.ts @@ -1,13 +1,16 @@ import { useEffect } from 'react'; +import { useUserId } from '../../../contexts/UserContext'; import { fireGlobalEvent } from '../../../lib/utils/fireGlobalEvent'; export const useCustomScript = (): void => { + const uid = useUserId(); useEffect(() => { - fireGlobalEvent('Custom_Script_Logged_In'); + if (uid) { + fireGlobalEvent('Custom_Script_Logged_In'); + return; + } - return (): void => { - fireGlobalEvent('Custom_Script_Logged_Out'); - }; - }, []); + fireGlobalEvent('Custom_Script_Logged_Out'); + }, [uid]); };