Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions client/views/root/MainLayout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;

const MainLayout = ({ center }: MainLayoutProps): ReactElement => (
<Preload>
<AuthenticationCheck>{useMemo(() => (center ? <BlazeTemplate template={center} /> : null), [center])}</AuthenticationCheck>
</Preload>
);
const MainLayout = ({ center }: MainLayoutProps): ReactElement => {
useCustomScript();

return (
<Preload>
<AuthenticationCheck>{useMemo(() => (center ? <BlazeTemplate template={center} /> : null), [center])}</AuthenticationCheck>
</Preload>
);
};

export default MainLayout;
2 changes: 0 additions & 2 deletions client/views/root/MainLayout/UsernameCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 8 additions & 5 deletions client/views/root/MainLayout/useCustomScript.ts
Original file line number Diff line number Diff line change
@@ -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]);
};