Skip to content

Commit 81368e6

Browse files
committed
Removed client side loading from public pages as much as possible
1 parent 73267b3 commit 81368e6

18 files changed

Lines changed: 760 additions & 1148 deletions

File tree

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,27 @@ import {
1010
} from "@components/contexts";
1111
import { BaseLayout } from "@components/public/base-layout";
1212
import { Profile } from "@courselit/common-models";
13-
import { getPage } from "@ui-lib/utils";
14-
import { useContext, useEffect, useState } from "react";
13+
import { getFullSiteSetup } from "@ui-lib/utils";
14+
import { useContext } from "react";
1515

1616
export default function HomepageLayout({
1717
children,
18+
siteInfo,
1819
}: {
1920
children: React.ReactNode;
21+
siteInfo: Awaited<ReturnType<typeof getFullSiteSetup>>;
2022
}) {
21-
const [page, setPage] = useState<any>(null);
2223
const address = useContext(AddressContext);
2324
const siteinfo = useContext(SiteInfoContext);
2425
const typefaces = useContext(TypefacesContext);
2526
const config = useContext(ServerConfigContext);
2627
const { profile } = useContext(ProfileContext);
2728
const { theme } = useContext(ThemeContext);
2829

29-
useEffect(() => {
30-
if (address.backend) {
31-
getPage(address.backend).then(setPage);
32-
}
33-
}, [address]);
34-
35-
if (!page) {
36-
return null;
37-
}
38-
3930
return (
4031
<BaseLayout
41-
layout={page.layout}
42-
title={page.title}
32+
layout={siteInfo!.page.layout}
33+
title={siteInfo!.page.title || ""}
4334
typefaces={typefaces}
4435
siteInfo={siteinfo}
4536
dispatch={() => {}}
@@ -49,7 +40,7 @@ export default function HomepageLayout({
4940
siteinfo,
5041
address: address,
5142
profile: profile as Profile,
52-
auth: profile.email
43+
auth: profile?.email
5344
? {
5445
guest: false,
5546
checked: true,
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import { auth } from "@/auth";
22
import { SessionProvider } from "next-auth/react";
33
import HomepageLayout from "./home-page-layout";
4+
import { headers } from "next/headers";
5+
import { getAddressFromHeaders, getFullSiteSetup } from "@ui-lib/utils";
46

57
export default async function Layout({
68
children,
79
}: {
810
children: React.ReactNode;
911
}) {
1012
const session = await auth();
13+
const address = getAddressFromHeaders(headers);
14+
const siteInfo = await getFullSiteSetup(address);
15+
16+
if (!siteInfo) {
17+
return null;
18+
}
1119

1220
return (
1321
<SessionProvider session={session}>
14-
<HomepageLayout>{children}</HomepageLayout>
22+
<HomepageLayout siteInfo={siteInfo}>{children}</HomepageLayout>
1523
</SessionProvider>
1624
);
1725
}

apps/web/app/(with-contexts)/(with-layout)/p/[id]/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPage, getSiteInfo } from "@ui-lib/utils";
1+
import { getFullSiteSetup, getPage } from "@ui-lib/utils";
22
import { getAddressFromHeaders } from "@/ui-lib/utils";
33
import ClientSidePage from "./client-side-page";
44
import { headers } from "next/headers";
@@ -15,7 +15,7 @@ export async function generateMetadata(
1515
parent: ResolvingMetadata,
1616
): Promise<Metadata> {
1717
const address = getAddressFromHeaders(headers);
18-
const siteInfo = await getSiteInfo(address);
18+
const siteInfo = await getFullSiteSetup(address);
1919
if (!siteInfo) {
2020
return {
2121
title: `${(await parent)?.title?.absolute}`,
@@ -64,7 +64,7 @@ export async function generateMetadata(
6464

6565
export default async function Page({ params }: Props) {
6666
const address = getAddressFromHeaders(headers);
67-
const siteInfo = await getSiteInfo(address);
67+
const siteInfo = await getFullSiteSetup(address);
6868
if (!siteInfo) {
6969
return null;
7070
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPage, getSiteInfo } from "@ui-lib/utils";
1+
import { getFullSiteSetup } from "@ui-lib/utils";
22
import { getAddressFromHeaders } from "@/ui-lib/utils";
33
import ClientSidePage from "./p/[id]/client-side-page";
44
import { headers } from "next/headers";
@@ -15,14 +15,14 @@ export async function generateMetadata(
1515
parent: ResolvingMetadata,
1616
): Promise<Metadata> {
1717
const address = getAddressFromHeaders(headers);
18-
const siteInfo = await getSiteInfo(address);
18+
const siteInfo = await getFullSiteSetup(address, "homepage");
1919
if (!siteInfo) {
2020
return {
2121
title: "CourseLit",
2222
};
2323
}
2424

25-
const page = await getPage(address, "homepage");
25+
const page = siteInfo.page;
2626

2727
const title = page.title || siteInfo.settings.title;
2828
const socialImage = page.socialImage || siteInfo.settings.logo;
@@ -63,16 +63,14 @@ export async function generateMetadata(
6363

6464
export default async function Page() {
6565
const address = getAddressFromHeaders(headers);
66-
const siteInfo = await getSiteInfo(address);
66+
const siteInfo = await getFullSiteSetup(address, "homepage");
6767
if (!siteInfo) {
6868
return null;
6969
}
7070

71-
const page = await getPage(address, "homepage");
72-
7371
return (
7472
<ClientSidePage
75-
page={page}
73+
page={siteInfo.page}
7674
siteinfo={siteInfo.settings}
7775
theme={siteInfo.theme}
7876
/>

apps/web/app/(with-contexts)/dashboard/(sidebar)/my-content/page.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
import { useState, useEffect, useContext } from "react";
44
import type { ContentItem } from "@/components/admin/my-content/content";
5-
import { AddressContext, ProfileContext } from "@components/contexts";
5+
import {
6+
AddressContext,
7+
ProfileContext,
8+
ThemeContext,
9+
} from "@components/contexts";
610
import { MY_CONTENT_HEADER } from "@ui-config/strings";
711
import DashboardContent from "@components/admin/dashboard-content";
812
import { FetchBuilder } from "@courselit/utils";
913
import { Constants, MembershipEntityType } from "@courselit/common-models";
1014
import { MyContentCard } from "@components/admin/my-content/content-card";
1115
import { BookOpen, Users } from "lucide-react";
1216
import Link from "next/link";
13-
import { Button } from "@components/ui/button";
1417
import { SkeletonCard } from "@components/skeleton-card";
18+
import { Button } from "@courselit/page-primitives";
1519

1620
function ContentGrid({
1721
items,
@@ -45,6 +49,7 @@ export default function Page() {
4549
const [loading, setLoading] = useState(true);
4650
const { profile } = useContext(ProfileContext);
4751
const address = useContext(AddressContext);
52+
const { theme } = useContext(ThemeContext);
4853

4954
useEffect(() => {
5055
const getUserContent = async () => {
@@ -111,13 +116,13 @@ export default function Page() {
111116
</p>
112117
{type === Constants.MembershipEntityType.COURSE ? (
113118
<Link href="/products" className="text-primary">
114-
<Button variant="outline" size="sm">
119+
<Button size="sm" theme={theme.theme}>
115120
Browse products
116121
</Button>
117122
</Link>
118123
) : (
119124
<Link href="/communities" className="text-primary">
120-
<Button variant="outline" size="sm">
125+
<Button size="sm" theme={theme.theme}>
121126
Browse communities
122127
</Button>
123128
</Link>

0 commit comments

Comments
 (0)