diff options
author | LASER-Yi <[email protected]> | 2022-11-09 22:09:10 +0800 |
---|---|---|
committer | LASER-Yi <[email protected]> | 2022-11-09 22:09:17 +0800 |
commit | 726afcc7f81bd931e1c4b91157aceceb9df72300 (patch) | |
tree | 5faee63e908e206672164d25d90d32437959a75e | |
parent | 69e4a9c52657083bdc5c892ce9d0ecb930ef2486 (diff) | |
download | bazarr-726afcc7f81bd931e1c4b91157aceceb9df72300.tar.gz bazarr-726afcc7f81bd931e1c4b91157aceceb9df72300.zip |
Add support of string value for badge in navbar
-rw-r--r-- | frontend/src/App/Navbar.tsx | 27 | ||||
-rw-r--r-- | frontend/src/Router/type.d.ts | 2 |
2 files changed, 20 insertions, 9 deletions
diff --git a/frontend/src/App/Navbar.tsx b/frontend/src/App/Navbar.tsx index a6e8791d4..abde1e82b 100644 --- a/frontend/src/App/Navbar.tsx +++ b/frontend/src/App/Navbar.tsx @@ -53,6 +53,10 @@ function useSelection() { function useBadgeValue(route: Route.Item) { const { badge, children } = route; return useMemo(() => { + if (typeof badge === "string") { + return badge; + } + let value = badge ?? 0; if (children === undefined) { @@ -61,8 +65,9 @@ function useBadgeValue(route: Route.Item) { value += children.reduce((acc, child: Route.Item) => { - if (child.badge && child.hidden !== true) { - return acc + (child.badge ?? 0); + const childBadgeValue = child.badge; + if (typeof childBadgeValue === "number" && child.hidden !== true) { + return acc + childBadgeValue; } return acc; }, 0) ?? 0; @@ -290,7 +295,7 @@ interface NavbarItemProps { name: string; link: string; icon?: IconDefinition; - badge?: number; + badge?: number | string; primary?: boolean; onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void; } @@ -309,6 +314,16 @@ const NavbarItem: FunctionComponent<NavbarItemProps> = ({ const { ref, hovered } = useHover(); + const shouldHideBadge = useMemo(() => { + if (typeof badge === "number") { + return badge === 0; + } else if (typeof badge === "string") { + return badge.length === 0; + } + + return true; + }, [badge]); + return ( <NavLink to={link} @@ -342,11 +357,7 @@ const NavbarItem: FunctionComponent<NavbarItemProps> = ({ ></FontAwesomeIcon> )} {name} - <Badge - className={classes.badge} - radius="xs" - hidden={badge === undefined || badge === 0} - > + <Badge className={classes.badge} radius="xs" hidden={shouldHideBadge}> {badge} </Badge> </Text> diff --git a/frontend/src/Router/type.d.ts b/frontend/src/Router/type.d.ts index edd40bb65..0276a30dd 100644 --- a/frontend/src/Router/type.d.ts +++ b/frontend/src/Router/type.d.ts @@ -5,7 +5,7 @@ declare namespace Route { export type Item = { icon?: IconDefinition; name?: string; - badge?: number; + badge?: number | string; hidden?: boolean; children?: Item[]; }; |