-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: App title in the header and current app selected in the Drawer
- Loading branch information
Showing
8 changed files
with
108 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
import { Stack, Typography } from "@mui/material"; | ||
import { useApplicationTitle } from "@/hooks/application"; | ||
|
||
/** | ||
* Application Header component with the application title and type | ||
* @param type the type of the application | ||
* @returns the application header | ||
*/ | ||
export default function ApplicationHeader({ type }: { type: string }) { | ||
const appTitle = useApplicationTitle(); | ||
return ( | ||
<header> | ||
<Stack spacing={2} direction={"row"} alignItems={"end"}> | ||
{appTitle && ( | ||
<Typography | ||
color="text.primary" | ||
variant={"h4"} | ||
fontWeight={"bold"} | ||
width={"fit-content"} | ||
> | ||
{appTitle} | ||
</Typography> | ||
)} | ||
<Typography color="text.secondary" variant={"h4"} width={"fit-content"}> | ||
{type} | ||
</Typography> | ||
</Stack> | ||
</header> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useContext, useMemo } from "react"; | ||
import { useSearchParamsUtils } from "@/hooks/searchParamsUtils"; | ||
import { ApplicationsContext } from "@/contexts/ApplicationsProvider"; | ||
|
||
/** | ||
* Custom hook to access the application id from the URL | ||
* @returns the application id | ||
*/ | ||
export function useApplicationId() { | ||
const { getParam } = useSearchParamsUtils(); | ||
|
||
return useMemo(() => { | ||
return getParam("appId"); | ||
}, [getParam]); | ||
} | ||
|
||
/** | ||
* Custom hook to access the application title based on the application id | ||
* @returns the application title | ||
*/ | ||
export function useApplicationTitle() { | ||
const [sections] = useContext(ApplicationsContext); | ||
const appId = useApplicationId(); | ||
|
||
return useMemo(() => { | ||
if (!sections || !appId) return null; | ||
|
||
const app = sections.reduce( | ||
(acc, section) => { | ||
if (acc) return acc; | ||
return section.items.find((app) => app.id === appId); | ||
}, | ||
undefined as { title: string } | undefined, | ||
); | ||
return app?.title; | ||
}, [sections, appId]); | ||
} |
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