Skip to content

Commit 0749530

Browse files
author
Rajat Saxena
committed
Code injection only works on the public site
1 parent ee82250 commit 0749530

4 files changed

Lines changed: 12 additions & 28 deletions

File tree

apps/web/app/(with-contexts)/(with-layout)/home-page-layout.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { BaseLayout } from "@components/public/base-layout";
1212
import { Profile } from "@courselit/common-models";
1313
import { getFullSiteSetup } from "@ui-lib/utils";
1414
import { useContext } from "react";
15-
import { CodeInjectorWrapper } from "@components/public/code-injector";
15+
import { CodeInjector } from "@components/public/code-injector";
1616

1717
export default function HomepageLayout({
1818
children,
@@ -61,7 +61,10 @@ export default function HomepageLayout({
6161
}}
6262
>
6363
{children}
64-
<CodeInjectorWrapper />
64+
<CodeInjector
65+
head={siteinfo?.codeInjectionHead}
66+
body={siteinfo?.codeInjectionBody}
67+
/>
6568
</BaseLayout>
6669
);
6770
}

apps/web/components/public/code-injector.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
"use client";
22

3-
import React, { useContext } from "react";
3+
import React from "react";
44
import { connect } from "react-redux";
55
import { AppState } from "@courselit/state-management";
6-
import { usePathname } from "next/navigation";
7-
import { SiteInfoContext } from "@components/contexts";
86

97
type InjectionSection = "head" | "body";
108

119
interface CodeInjectorProps {
12-
isAdminPage?: boolean;
1310
head?: string;
1411
body?: string;
1512
}
1613

17-
export const CodeInjectorWrapper = () => {
18-
const siteInfo = useContext(SiteInfoContext);
19-
const pathname = usePathname();
20-
21-
return (
22-
<CodeInjector
23-
isAdminPage={pathname?.startsWith("/dashboard")}
24-
head={siteInfo?.codeInjectionHead}
25-
body={siteInfo?.codeInjectionBody}
26-
/>
27-
);
28-
};
29-
3014
export class CodeInjector extends React.Component<CodeInjectorProps> {
3115
componentDidMount() {
32-
if (!this.props.isAdminPage) {
33-
const targetTagsForInjection: InjectionSection[] = ["head", "body"];
34-
for (const target of targetTagsForInjection) {
35-
this.injectCodeIn(target);
36-
}
16+
const targetTagsForInjection: InjectionSection[] = ["head", "body"];
17+
for (const target of targetTagsForInjection) {
18+
this.injectCodeIn(target);
3719
}
3820
}
3921

apps/web/pages/_app.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ function MyApp({
4949
>
5050
<Component {...pageProps} />
5151
</div>
52-
<CodeInjector
53-
isAdminPage={router.pathname.startsWith("/dashboard")}
54-
/>
52+
<CodeInjector />
5553
</ThemeProvider>
5654
</Provider>
5755
</SessionProvider>

packages/components-library/src/link.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default function Link({
1919
className = "",
2020
onClick,
2121
}: LinkProps) {
22-
const isInternal = href && href.startsWith("/");
22+
const isInternal =
23+
href && href.startsWith("/") && !href.startsWith("/dashboard");
2324
const isInPageNavigation = href && href.startsWith("#");
2425
const router = useRouter();
2526

0 commit comments

Comments
 (0)