Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Persist Gate (Cause of slowness of web app) and shallow routing #312

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/ui/app/business/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"use client";

import { Box, Grid, Link, Tab, Tabs } from "@mui/material";
import NextLink from "next/link";
import { usePathname } from "next/navigation";
import React, { useEffect } from "react";

const tabs = [
{
title: "Orders",
route: `/business/dashboard/orders`,
value: 0,
key: "orders",
},
{
title: "Order Items",
route: `/business/dashboard/order-items`,
value: 1,
key: "order-items",
},
];

export default function DashboardLayout({
children,
}: {
children: React.ReactNode;
}) {
const pathname = usePathname();
const [selectedTab, setSelectedTab] = React.useState(0);

useEffect(() => {
// last part of the path
const path = pathname.split("/").pop();
const tab = tabs.find((tab) => tab.key === path);
if (tab) {
setSelectedTab(tab.value);
}
}, [pathname]);

return (
<Box
sx={{
p: 2,
}}
>
<Grid container spacing={2}>
<Grid
item
xs={12}
sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
flexDirection: "row",
mb: 2,
}}
>
<Box sx={{ display: "flex", justifyContent: "center", flex: 2 }}>
<Tabs value={selectedTab}>
{tabs.map((tab, index) => {
return (
<Link
key={index}
href={tab.route}
underline="none"
sx={{
textDecoration: "none",
}}
component={NextLink}
>
<Tab
key={index}
label={tab.title}
value={tab.value}
sx={{
color:
selectedTab === tab.value ? "#000000" : "#000000",
fontSize: "16px",
lineHeight: "19px",
fontWeight: "bold",
textTransform: "none",
}}
/>
</Link>
);
})}
</Tabs>
</Box>
</Grid>
</Grid>
<Box>{children}</Box>
</Box>
);
}
Loading