-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from jadmsaadaot/SUBMIT-task#18
Simplify sidenav
- Loading branch information
Showing
10 changed files
with
165 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
submit-web/src/components/Shared/layout/SideNav/MainListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { alpha, ListItem, ListItemButton } from "@mui/material"; | ||
import { RouteType } from "./SideNavElements"; | ||
import { Link, useRouterState } from "@tanstack/react-router"; | ||
import { theme } from "@/styles/theme"; | ||
|
||
export const MainListItem = ({ route }: { route: RouteType }) => { | ||
const router = useRouterState(); | ||
const currentPath = router.location.pathname; | ||
return ( | ||
<ListItem key={route.name}> | ||
<Link | ||
to={route.path} | ||
style={{ | ||
color: theme.palette.primary.light, | ||
fontWeight: "bold", | ||
textDecoration: "none", | ||
width: "100%", | ||
}} | ||
> | ||
<ListItemButton | ||
sx={{ | ||
pl: "2rem", | ||
backgroundColor: | ||
currentPath === route.path | ||
? alpha(theme.palette.secondary.main, 0.1) | ||
: theme.palette.primary.light, | ||
borderLeft: `4px solid ${theme.palette.primary.main}`, | ||
}} | ||
> | ||
<span | ||
style={{ | ||
color: alpha(theme.palette.primary.main, 0.8), | ||
}} | ||
> | ||
{route.name} | ||
</span> | ||
</ListItemButton> | ||
</Link> | ||
</ListItem> | ||
); | ||
}; |
23 changes: 23 additions & 0 deletions
23
submit-web/src/components/Shared/layout/SideNav/ProjectsSubRoutes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useGetProjects } from "@/hooks/api/useProjects"; | ||
import { useAccount } from "@/store/accountStore"; | ||
import { SubListItem } from "./SubListItem"; | ||
import { SubListItemSkeleton } from "./SubListItemSkeleton"; | ||
|
||
export default function ProjectsSubRoutes() { | ||
const { accountId } = useAccount(); | ||
const { data: accountProjects, isPending } = useGetProjects({ | ||
accountId, | ||
}); | ||
|
||
if (isPending) return <SubListItemSkeleton />; | ||
|
||
return accountProjects?.map((accountProject) => ( | ||
<SubListItem | ||
key={`sub-list-${accountProject.id}`} | ||
route={{ | ||
name: accountProject.project.name, | ||
path: `/projects/${accountProject.id}`, | ||
}} | ||
/> | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 10 additions & 18 deletions
28
submit-web/src/components/Shared/layout/SideNav/SideNavElements.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
import { Project } from "@/models/Project"; | ||
|
||
export const createProjectRoutes = (projects: Project[]): RouteType[] => { | ||
const projectRoutes = projects?.map((project) => ({ | ||
name: project.name, | ||
path: `/projects/${project.id}`, | ||
})); | ||
return [ | ||
{ | ||
name: "All Projects", | ||
path: "/projects", | ||
routes: projectRoutes, | ||
}, | ||
]; | ||
}; | ||
|
||
export const AuthenticatedRoutes: RouteType[] = [ | ||
{ | ||
name: "Admin", | ||
path: "/profile", | ||
}, | ||
]; | ||
|
||
export const AdminRoute: RouteType = { | ||
name: "Admin", | ||
path: "/admin", | ||
}; | ||
|
||
export const ProjectRoute: RouteType = { | ||
name: "All Projects", | ||
path: "/projects", | ||
}; | ||
|
||
export interface RouteType { | ||
name: string; | ||
path: string; | ||
group?: string; | ||
routes?: RouteType[]; | ||
} |
44 changes: 44 additions & 0 deletions
44
submit-web/src/components/Shared/layout/SideNav/SubListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ListItem, ListItemButton, ListItemText } from "@mui/material"; | ||
import { RouteType } from "./SideNavElements"; | ||
import { Link, useRouterState } from "@tanstack/react-router"; | ||
import { theme } from "@/styles/theme"; | ||
|
||
export const SubListItem = ({ route }: { route: RouteType }) => { | ||
const router = useRouterState(); | ||
const currentPath = router.location.pathname; | ||
return ( | ||
<ListItem key={`sub-list-${route?.name}`} sx={{ margin: 0, padding: 0 }}> | ||
<Link | ||
to={route.path} | ||
style={{ | ||
textDecoration: "none", | ||
margin: 0, | ||
padding: 0, | ||
color: "inherit", | ||
}} | ||
activeProps={{ | ||
style: { | ||
color: theme.palette.primary.main, | ||
fontWeight: currentPath === route.path ? "bold" : "normal", | ||
width: "100%", | ||
}, | ||
}} | ||
> | ||
<ListItemButton | ||
key={`sub-list-button-${route?.name}`} | ||
sx={{ | ||
marginLeft: "40px", | ||
borderLeft: | ||
currentPath === route.path | ||
? `4px solid ${theme.palette.primary.main}` | ||
: `1px solid ${theme.palette.divider}`, | ||
}} | ||
> | ||
<ListItemText key={`sub-list-text-${route?.name}`}> | ||
<span style={{ color: "inherit" }}>{route.name}</span> | ||
</ListItemText> | ||
</ListItemButton> | ||
</Link> | ||
</ListItem> | ||
); | ||
}; |
24 changes: 24 additions & 0 deletions
24
submit-web/src/components/Shared/layout/SideNav/SubListItemSkeleton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
ListItem, | ||
ListItemButton, | ||
ListItemText, | ||
Skeleton, | ||
} from "@mui/material"; | ||
import { theme } from "@/styles/theme"; | ||
|
||
export const SubListItemSkeleton = () => { | ||
return ( | ||
<ListItem sx={{ margin: 0, padding: 0 }}> | ||
<ListItemButton | ||
sx={{ | ||
marginLeft: "40px", | ||
borderLeft: `1px solid ${theme.palette.divider}`, | ||
}} | ||
> | ||
<ListItemText> | ||
<Skeleton /> | ||
</ListItemText> | ||
</ListItemButton> | ||
</ListItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters