Skip to content

Commit

Permalink
[FIX] Custom script not being fired (#24901)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored and sampaiodiego committed Mar 21, 2022
1 parent 374956c commit d7c8b53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
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]);
};

0 comments on commit d7c8b53

Please sign in to comment.