chore: cleanup - Remove WithLayout HoC itself (#19490)
* remove future folder * remove unused file * remove unused files
This commit is contained in:
1 parent
64aa19fcea
commit
a47cd5b106
10 files changed
-171
No files matched your search
@@ -1,31 +0,0 @@
|
||||
import type { GetStaticProps, GetStaticPropsContext } from "next";
|
||||
import { unstable_cache } from "next/cache";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
|
||||
export const withAppDirSsg =
|
||||
<T extends Record<string, any>>(getStaticProps: GetStaticProps<T>, routePath: string) =>
|
||||
async (context: GetStaticPropsContext) => {
|
||||
const cacheKey = JSON.stringify({
|
||||
route: routePath,
|
||||
params: context.params || {},
|
||||
});
|
||||
|
||||
const getCachedProps = unstable_cache(async () => {
|
||||
const ssgResponse = await getStaticProps(context);
|
||||
|
||||
if ("redirect" in ssgResponse) {
|
||||
redirect(ssgResponse.redirect.destination);
|
||||
}
|
||||
|
||||
if ("notFound" in ssgResponse) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return {
|
||||
...ssgResponse.props,
|
||||
...("trpcState" in ssgResponse.props && { dehydratedState: ssgResponse.props.trpcState }),
|
||||
};
|
||||
}, [`ssg-${cacheKey}`]);
|
||||
|
||||
return getCachedProps();
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
import withEmbedSsrAppDir from "app/WithEmbedSSR";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
|
||||
import { getServerSideProps } from "@server/lib/[user]/[type]/getServerSideProps";
|
||||
|
||||
import LegacyPage, { type PageProps } from "~/users/views/users-type-public-view";
|
||||
|
||||
const getEmbedData = withEmbedSsrAppDir<PageProps>(getServerSideProps);
|
||||
|
||||
export default WithLayout({ getLayout: null, getData: getEmbedData, Page: LegacyPage })<"P">;
|
||||
@@ -1,11 +0,0 @@
|
||||
import withEmbedSsrAppDir from "app/WithEmbedSSR";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
|
||||
import { getServerSideProps } from "@server/lib/[user]/getServerSideProps";
|
||||
|
||||
import type { PageProps as UserPageProps } from "~/users/views/users-public-view";
|
||||
import LegacyPage from "~/users/views/users-public-view";
|
||||
|
||||
const getEmbedData = withEmbedSsrAppDir<UserPageProps>(getServerSideProps);
|
||||
|
||||
export default WithLayout({ getLayout: null, getData: getEmbedData, Page: LegacyPage })<"P">;
|
||||
@@ -1,10 +0,0 @@
|
||||
import Page from "@pages/org/[orgSlug]/[user]/[type]/embed";
|
||||
import withEmbedSsrAppDir from "app/WithEmbedSSR";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
import type { OrgTypePageProps } from "app/(booking-page-wrapper)/org/[orgSlug]/[user]/[type]/page";
|
||||
|
||||
import { getServerSideProps } from "@lib/org/[orgSlug]/[user]/[type]/getServerSideProps";
|
||||
|
||||
const getEmbedData = withEmbedSsrAppDir<OrgTypePageProps>(getServerSideProps);
|
||||
|
||||
export default WithLayout({ getLayout: null, getData: getEmbedData, isBookingPage: true, Page });
|
||||
@@ -1,21 +0,0 @@
|
||||
import withEmbedSsrAppDir from "app/WithEmbedSSR";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
import type { OrgPageProps } from "app/(booking-page-wrapper)/org/[orgSlug]/[user]/page";
|
||||
|
||||
import { getServerSideProps } from "@lib/org/[orgSlug]/[user]/getServerSideProps";
|
||||
|
||||
import type { PageProps as TeamPageProps } from "~/team/team-view";
|
||||
import TeamPage from "~/team/team-view";
|
||||
import UserPage from "~/users/views/users-public-view";
|
||||
import type { PageProps as UserPageProps } from "~/users/views/users-public-view";
|
||||
|
||||
const getEmbedData = withEmbedSsrAppDir<OrgPageProps>(getServerSideProps);
|
||||
|
||||
const Page = async (props: OrgPageProps) => {
|
||||
if ((props as TeamPageProps)?.team) {
|
||||
return <TeamPage {...(props as TeamPageProps)} />;
|
||||
}
|
||||
return <UserPage {...(props as UserPageProps)} />;
|
||||
};
|
||||
|
||||
export default WithLayout({ getLayout: null, getData: getEmbedData, isBookingPage: true, ServerPage: Page });
|
||||
@@ -1,16 +0,0 @@
|
||||
import withEmbedSsrAppDir from "app/WithEmbedSSR";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
|
||||
import { getServerSideProps } from "@lib/team/[slug]/getServerSideProps";
|
||||
|
||||
import type { PageProps } from "~/team/team-view";
|
||||
import TeamPage from "~/team/team-view";
|
||||
|
||||
const getEmbedData = withEmbedSsrAppDir<PageProps>(getServerSideProps);
|
||||
|
||||
export default WithLayout({
|
||||
Page: TeamPage,
|
||||
getData: getEmbedData,
|
||||
getLayout: null,
|
||||
isBookingPage: true,
|
||||
})<"P">;
|
||||
@@ -1,61 +0,0 @@
|
||||
import type { LayoutProps, PageProps } from "app/_types";
|
||||
import { type GetServerSidePropsContext } from "next";
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
||||
|
||||
import PageWrapper from "@components/PageWrapperAppDir";
|
||||
|
||||
type WithLayoutParams<T extends Record<string, any>> = {
|
||||
getLayout?: ((page: React.ReactElement) => React.ReactNode) | null;
|
||||
getServerLayout?: (page: React.ReactElement) => Promise<React.ReactNode | null>;
|
||||
Page?: (props: T) => React.ReactElement | null;
|
||||
ServerPage?: (props: T) => Promise<React.ReactElement> | null;
|
||||
getData?: (arg: GetServerSidePropsContext) => Promise<T | undefined>;
|
||||
isBookingPage?: boolean;
|
||||
requiresLicense?: boolean;
|
||||
};
|
||||
|
||||
export function WithLayout<T extends Record<string, any>>({
|
||||
getLayout,
|
||||
getServerLayout,
|
||||
getData,
|
||||
ServerPage,
|
||||
Page,
|
||||
isBookingPage,
|
||||
requiresLicense,
|
||||
}: WithLayoutParams<T>) {
|
||||
// eslint-disable-next-line react/display-name
|
||||
return async <P extends "P" | "L">(p: P extends "P" ? PageProps : LayoutProps) => {
|
||||
const h = headers();
|
||||
const nonce = h.get("x-nonce") ?? undefined;
|
||||
let props = {} as T;
|
||||
|
||||
if ("searchParams" in p && getData) {
|
||||
props = (await getData(buildLegacyCtx(h, cookies(), p.params, p.searchParams))) ?? ({} as T);
|
||||
}
|
||||
|
||||
// `p.children` exists only for layout.tsx files
|
||||
const childrenFromLayoutFile = "children" in p ? p.children : null;
|
||||
const page = ServerPage ? (
|
||||
await ServerPage({ ...props, ...p })
|
||||
) : Page ? (
|
||||
<Page {...props} />
|
||||
) : (
|
||||
childrenFromLayoutFile
|
||||
);
|
||||
const pageWithServerLayout = page ? (getServerLayout ? await getServerLayout(page) : page) : null;
|
||||
|
||||
return (
|
||||
<PageWrapper
|
||||
getLayout={getLayout}
|
||||
requiresLicense={requiresLicense || !!(Page && "requiresLicense" in Page && Page.requiresLicense)}
|
||||
nonce={nonce}
|
||||
themeBasis={null}
|
||||
isBookingPage={isBookingPage || !!(Page && "isBookingPage" in Page && Page.isBookingPage)}
|
||||
{...props}>
|
||||
{pageWithServerLayout}
|
||||
</PageWrapper>
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -18,13 +18,11 @@ let pages = (exports.pages = glob
|
||||
.replace(/(\.tsx|\.js|\.ts)/, "")
|
||||
.replace(/\/.*/, "")
|
||||
)
|
||||
// "/future" is a temporary directory for incremental migration to App Router
|
||||
.filter(
|
||||
(v, i, self) =>
|
||||
self.indexOf(v) === i &&
|
||||
![
|
||||
"[user]",
|
||||
"future",
|
||||
"_trpc",
|
||||
"layout",
|
||||
"layoutHOC",
|
||||
|
||||
@@ -31,9 +31,6 @@ const only = searchParams.get("only");
|
||||
const colorScheme = searchParams.get("color-scheme");
|
||||
const prerender = searchParams.get("prerender");
|
||||
|
||||
// @ts-expect-error We haven't defined ENABLE_FUTURE_ROUTES as it is a playground specific variable.
|
||||
window.ENABLE_FUTURE_ROUTES = searchParams.get("future-routes") === "true";
|
||||
|
||||
if (colorScheme) {
|
||||
document.documentElement.style.colorScheme = colorScheme;
|
||||
}
|
||||
|
||||
@@ -297,12 +297,6 @@ export class Cal {
|
||||
urlInstance.pathname = `${urlInstance.pathname}/embed`;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
if (window.ENABLE_FUTURE_ROUTES) {
|
||||
urlInstance.pathname = `/future${urlInstance.pathname}`;
|
||||
}
|
||||
|
||||
urlInstance.searchParams.set("embed", this.namespace);
|
||||
|
||||
if (embedConfig.debug) {
|
||||
|
||||
Reference in new issue
Block a user