From 1b1d6e44852eea291925e47601d4da3a24fc5450 Mon Sep 17 00:00:00 2001 From: Carter Date: Wed, 23 Apr 2025 16:07:36 -0600 Subject: [PATCH] using local storage to remember team names in the bread crumbs --- src/common/SmartBreadcrumb.tsx | 22 ++++++++++++++++++++-- src/navigation/BottomNavigator.tsx | 2 +- src/pages/Team.tsx | 3 +++ src/user/UserMenu.tsx | 4 +++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/common/SmartBreadcrumb.tsx b/src/common/SmartBreadcrumb.tsx index d914ac1..240af69 100644 --- a/src/common/SmartBreadcrumb.tsx +++ b/src/common/SmartBreadcrumb.tsx @@ -11,7 +11,7 @@ import { } from "@mui/material"; import { Replay } from "@mui/icons-material"; import { useMobile } from "hooks"; -import { ReactNode } from "react"; +import { ReactNode, useEffect, useRef } from "react"; import { useLocation } from "react-router"; import { Link as RouterLink } from "react-router-dom"; import { or } from "utils/types"; @@ -47,6 +47,7 @@ interface Props { componentName?: string; groupName?: string; binName?: string; + teamName?: string; reportTarget?: string; loading?: boolean; reload?: () => void; @@ -114,6 +115,11 @@ export default function SmartBreadcrumb(props: Props) { return or(regexMatch[1], "0").toString(); }; + const teamKey = (): string => { + const regexMatch = or(location.pathname.match(/\/teams\/([^/]+)/), []) + return or(regexMatch[1], "0").toString(); + }; + const reportIDShort = (): string => { return reportID().split("-")[0]; }; @@ -220,6 +226,10 @@ export default function SmartBreadcrumb(props: Props) { return "/teams"; } + const teamPath = (): string => { + return "/teams" + "/" + teamKey(); + } + const getBreadcrumbMap = (): { [key: string]: string } => { const { groupName, deviceName, componentName, reportTarget, binName } = props; const deviceLabel: string = deviceName ? deviceName : "Device " + deviceID(); @@ -227,6 +237,13 @@ export default function SmartBreadcrumb(props: Props) { const binLabel: string = binName ?? "Bin " + binID(); const mineLabel: string = "Mine Site"; const jobsiteLabel: string = "Job Site"; + + let lastTeamName = props.teamName; + if (props.teamName) { + localStorage.setItem('lastTeamName-'+teamKey(), props.teamName); + } else { + lastTeamName = or(localStorage.getItem('lastTeamName-'+teamKey()), undefined); + } return { [dashboardPath()]: "Dashboard", @@ -250,7 +267,8 @@ export default function SmartBreadcrumb(props: Props) { [usersPath()]: "Users", [binsPath()]: "Bins", [binPath()]: binLabel, - [teamsPath()]: "Teams" + [teamsPath()]: "Teams", + [teamPath()]: lastTeamName ? lastTeamName : "Team " + teamKey(), }; }; diff --git a/src/navigation/BottomNavigator.tsx b/src/navigation/BottomNavigator.tsx index e279c59..514429a 100644 --- a/src/navigation/BottomNavigator.tsx +++ b/src/navigation/BottomNavigator.tsx @@ -187,7 +187,7 @@ export default function BottomNavigator(props: Props) { bottom={0} width="100vw" zIndex={theme.zIndex.appBar} - sx={{ background: theme.palette.background.paper}} + sx={{ background: theme.palette.background.paper }} style={{ overflow: window.location.origin.includes("staging") || window.location.origin.includes("localhost") diff --git a/src/pages/Team.tsx b/src/pages/Team.tsx index af2afda..d720e89 100644 --- a/src/pages/Team.tsx +++ b/src/pages/Team.tsx @@ -2,6 +2,7 @@ import { Avatar, AvatarGroup, Box, Button, Card, Divider, Grid2, List, ListItemB import { makeStyles } from "@mui/styles"; import LoadingScreen from "app/LoadingScreen"; import Chat from "chat/Chat"; +import SmartBreadcrumb from "common/SmartBreadcrumb"; // import SmartBreadcrumb from "common/SmartBreadcrumb"; import { useMobile } from "hooks"; import { cloneDeep } from "lodash"; @@ -214,6 +215,8 @@ export default function TeamPage() { + + {title()} diff --git a/src/user/UserMenu.tsx b/src/user/UserMenu.tsx index e5d3364..825ba85 100644 --- a/src/user/UserMenu.tsx +++ b/src/user/UserMenu.tsx @@ -1,4 +1,4 @@ -import { Avatar, Box, Button, Checkbox, IconButton, ListItemIcon, ListItemText, Menu, MenuItem, PaletteColor, Theme, Tooltip, useTheme } from "@mui/material"; +import { Avatar, Box, Button, Checkbox, Divider, IconButton, ListItemIcon, ListItemText, Menu, MenuItem, PaletteColor, Theme, Tooltip, useTheme } from "@mui/material"; import { useGlobalState } from "../providers/StateContainer"; import { getSecondaryColour, getSignatureAccentColour } from "../services/whiteLabel"; import { makeStyles } from "@mui/styles"; @@ -270,6 +270,7 @@ export default function UserMenu() { )} + {hasAdmin && ( openAccessObject()} aria-label="Access Object" dense> @@ -280,6 +281,7 @@ export default function UserMenu() { )} +