diff --git a/dapp/src/DApp.tsx b/dapp/src/DApp.tsx index 71db1bc16..90450d00e 100644 --- a/dapp/src/DApp.tsx +++ b/dapp/src/DApp.tsx @@ -1,36 +1,23 @@ import React from "react" -import { Box, ChakraProvider } from "@chakra-ui/react" +import { ChakraProvider } from "@chakra-ui/react" import { Provider as ReduxProvider } from "react-redux" -import { RouterProvider } from "react-router-dom" -import { useInitApp } from "./hooks" -import { store } from "./store" -import theme from "./theme" +import { AcreSdkProvider } from "./acre-react/contexts" +import GlobalStyles from "./components/GlobalStyles" import { DocsDrawerContextProvider, LedgerWalletAPIProvider, SidebarContextProvider, WalletContextProvider, } from "./contexts" -import { AcreSdkProvider } from "./acre-react/contexts" -import Header from "./components/Header" -import Sidebar from "./components/Sidebar" -import DocsDrawer from "./components/DocsDrawer" -import GlobalStyles from "./components/GlobalStyles" -import { router } from "./router" +import { useInitApp } from "./hooks" +import { Router } from "./router" +import { store } from "./store" +import theme from "./theme" function DApp() { useInitApp() - return ( - <> -
- - - - - - - ) + return } function DAppProviders() { diff --git a/dapp/src/components/shared/Layout.tsx b/dapp/src/components/shared/Layout.tsx new file mode 100644 index 000000000..fd070bc36 --- /dev/null +++ b/dapp/src/components/shared/Layout.tsx @@ -0,0 +1,45 @@ +import React, { useState } from "react" +import { AnimatePresence, motion, Variants } from "framer-motion" +import { useLocation, useOutlet } from "react-router-dom" +import Header from "../Header" +import DocsDrawer from "../DocsDrawer" +import Sidebar from "../Sidebar" + +const wrapperVariants: Variants = { + in: { opacity: 0, y: 48 }, + out: { opacity: 0, y: -48 }, + visible: { opacity: 1, y: 0 }, +} + +// This tricky component makes Outlet persistent so React and Framer Motion can +// distinguish wheather it should be rerendered between routes. +// Ref: https://github.com/remix-run/react-router/discussions/8008#discussioncomment-1280897 +function PersistentOutlet() { + const [outlet] = useState(useOutlet()) + return outlet +} + +function Layout() { + const location = useLocation() + return ( + <> +
+ + + + + + + + + ) +} + +export default Layout diff --git a/dapp/src/router/index.tsx b/dapp/src/router/index.tsx index 5d280ad22..d661e0c3f 100644 --- a/dapp/src/router/index.tsx +++ b/dapp/src/router/index.tsx @@ -1,16 +1,22 @@ import React from "react" -import { createBrowserRouter } from "react-router-dom" +import { BrowserRouter, Route, Routes } from "react-router-dom" import OverviewPage from "#/pages/OverviewPage" import ActivityPage from "#/pages/ActivityPage" +import Layout from "#/components/shared/Layout" import { routerPath } from "./path" -export const router = createBrowserRouter([ - { - path: routerPath.home, - element: , - }, - { - path: `${routerPath.activity}/:activityId`, - element: , - }, -]) +export function Router() { + return ( + + + }> + } /> + } + /> + + + + ) +}