Skip to content

Commit

Permalink
Add page layouts to frontend (#2)
Browse files Browse the repository at this point in the history
* add page layout with no header or footer

* add page layout with header and footer

* edit index.tsx page to work with new page layouts

* remove Header and Footer from _app.tsx

* alter _app.tsx to work with new page layouts
  • Loading branch information
Spencer-Sch authored Nov 14, 2023
1 parent 55d6a6d commit f2054ae
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
13 changes: 13 additions & 0 deletions packages/nextjs/components/layouts/CleanLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { ReactNode } from "react";

interface CleanLayoutProps {
children: ReactNode;
}

export default function CleanLayout({ children }: CleanLayoutProps) {
return (
<>
<main className="relative flex flex-col justify-center flex-1">{children}</main>
</>
);
}
17 changes: 17 additions & 0 deletions packages/nextjs/components/layouts/HeaderFooterLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { ReactNode } from "react";
import { Footer } from "~~/components/Footer";
import { Header } from "~~/components/Header";

interface HeaderFooterLayoutProps {
children: ReactNode;
}

export default function HeaderFooterLayout({ children }: HeaderFooterLayoutProps) {
return (
<>
<Header />
<main className="relative flex flex-col justify-center flex-1">{children}</main>
<Footer />
</>
);
}
25 changes: 14 additions & 11 deletions packages/nextjs/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { useEffect, useState } from "react";
import { ReactElement, ReactNode, useEffect, useState } from "react";
import type { AppProps } from "next/app";
import { RainbowKitProvider, darkTheme, lightTheme } from "@rainbow-me/rainbowkit";
import "@rainbow-me/rainbowkit/styles.css";
import type { NextPage } from "next";
import NextNProgress from "nextjs-progressbar";
import { Toaster } from "react-hot-toast";
import { useDarkMode } from "usehooks-ts";
import { WagmiConfig } from "wagmi";
import { Footer } from "~~/components/Footer";
import { Header } from "~~/components/Header";
import { BlockieAvatar } from "~~/components/scaffold-eth";
import { useNativeCurrencyPrice } from "~~/hooks/scaffold-eth";
import { useGlobalState } from "~~/services/store/store";
import { wagmiConfig } from "~~/services/web3/wagmiConfig";
import { appChains } from "~~/services/web3/wagmiConnectors";
import "~~/styles/globals.css";

const ScaffoldEthApp = ({ Component, pageProps }: AppProps) => {
export type NextPageWithLayout<P = Record<string, never>, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode;
};

type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};

const ScaffoldEthApp = ({ Component, pageProps }: AppPropsWithLayout) => {
const price = useNativeCurrencyPrice();
const setNativeCurrencyPrice = useGlobalState(state => state.setNativeCurrencyPrice);
// This variable is required for initial client side rendering of correct theme for RainbowKit
Expand All @@ -32,6 +39,8 @@ const ScaffoldEthApp = ({ Component, pageProps }: AppProps) => {
setIsDarkTheme(isDarkMode);
}, [isDarkMode]);

const getLayout = Component.getLayout || (page => page);

return (
<WagmiConfig config={wagmiConfig}>
<NextNProgress />
Expand All @@ -40,13 +49,7 @@ const ScaffoldEthApp = ({ Component, pageProps }: AppProps) => {
avatar={BlockieAvatar}
theme={isDarkTheme ? darkTheme() : lightTheme()}
>
<div className="flex flex-col min-h-screen">
<Header />
<main className="relative flex flex-col justify-center flex-1">
<Component {...pageProps} />
</main>
<Footer />
</div>
<div className="flex flex-col min-h-screen">{getLayout(<Component {...pageProps} />)}</div>
<Toaster />
</RainbowKitProvider>
</WagmiConfig>
Expand Down
14 changes: 10 additions & 4 deletions packages/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ReactElement } from "react";
import Link from "next/link";
import type { NextPage } from "next";
import type { NextPageWithLayout } from "./_app";
import { MetaHeader } from "~~/components/MetaHeader";
import CleanLayout from "~~/components/layouts/CleanLayout";

const Home: NextPage = () => {
const LandingPage: NextPageWithLayout = () => {
return (
<>
<MetaHeader />
<MetaHeader /> {/* Look into MetaHeader - should it be moved to _app.tsx ??? */}
<div className="flex flex-col items-center pt-10">
<div className="px-5">
<h1 className="text-center mb-8">
Expand All @@ -26,4 +28,8 @@ const Home: NextPage = () => {
);
};

export default Home;
LandingPage.getLayout = function getLayout(page: ReactElement) {
return <CleanLayout>{page}</CleanLayout>;
};

export default LandingPage;

0 comments on commit f2054ae

Please sign in to comment.