-
Notifications
You must be signed in to change notification settings - Fork 0
/
__root.tsx
79 lines (73 loc) · 2.28 KB
/
__root.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Box, CircularProgress } from "@mui/material"
import { createRootRoute, Outlet } from "@tanstack/react-router"
import React, { Suspense } from "react"
import { auth } from "../firebase"
import { ProfilePresenter } from "./profile/index.lazy"
import Sidebar from "../views/Application/Sidebar"
import { useAuthState } from "react-firebase-hooks/auth"
import {
Add,
DonutLarge,
FitnessCenter,
Flag,
Home,
} from "@mui/icons-material"
import { ProfileAvatar } from "../views/Profile/ProfileAvatar"
// TanStack devtools only in development
const TanStackRouterDevtools =
process.env.NODE_ENV === "production"
? () => null // Render nothing in production
: React.lazy(() =>
// Lazy load in development
import("@tanstack/router-devtools").then((res) => ({
default: res.TanStackRouterDevtools,
// For Embedded Mode
// default: res.TanStackRouterDevtoolsPanel
}))
)
function RootPresenter() {
const [user, loading] = useAuthState(auth)
const pages = [
{
text: "Profile",
path: "/profile",
icon: <ProfileAvatar />,
},
{ text: "Overview", path: "/", icon: <Home />, disabled: !user },
{ text: "Add Workout", path: "/add-workout", icon: <Add />, disabled: !user },
{ text: "My Workouts", path: "/workouts", icon: <FitnessCenter />, disabled: !user },
{ text: "Goals", path: "/goals", icon: <Flag />, disabled: !user },
{ text: "Progress", path: "/progress", icon: <DonutLarge />, disabled: !user },
// { text: "Meals", path: "/meals", icon: <Restaurant />, disabled: !user },
]
return (
<>
<Box sx={{ display: "flex" }}>
<Sidebar pages={pages} />
{loading ? (
<Box
sx={{
width: "100%",
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<CircularProgress />
</Box>
) : (
<Box sx={{ width: "100%", height: "100vh" }}>
{auth.currentUser ? <Outlet /> : <ProfilePresenter />}
</Box>
)}
</Box>
<Suspense>
<TanStackRouterDevtools />
</Suspense>
</>
)
}
export const Route = createRootRoute({
component: RootPresenter,
})