Skip to content

Commit 8230773

Browse files
johanbookJohan Book
and
Johan Book
authored
feat(web-ui): use drawer to show organization list menu on mobile (#922)
* fix(web-ui): small styling fixes for guard pages * feat(web-ui): use drawer to show organization list on mobile --------- Co-authored-by: Johan Book <{ID}+{username}@users.noreply.github.com>
1 parent 2f18586 commit 8230773

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

services/web-ui/src/components/nav/AppBar/CurrentOrganizationAvatar.tsx

+68-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { ReactElement } from "react";
1+
import { ReactElement, useState } from "react";
22

33
import { ErrorOutline } from "@mui/icons-material";
44
import {
55
Avatar,
6+
Box,
67
ButtonBase,
78
CircularProgress,
9+
Divider,
10+
Drawer,
811
MenuItem,
912
Skeleton,
13+
Typography,
1014
} from "@mui/material";
1115

1216
import { OrganizationDetails, SwitchOrganizationCommand } from "src/api";
@@ -21,6 +25,7 @@ import {
2125
useQueryClient,
2226
} from "src/core/query";
2327
import { useSnackbar } from "src/core/snackbar";
28+
import { useIsMobile } from "src/hooks/useIsMobile";
2429

2530
interface MenuContentProps {
2631
currentOrganizationId: number;
@@ -64,22 +69,42 @@ function MenuContent({ currentOrganizationId }: MenuContentProps) {
6469
);
6570
}
6671

72+
const filteredOrganizations = query.data.filter(
73+
(organization) => organization.id !== currentOrganizationId
74+
);
75+
6776
return (
6877
<>
69-
{query.data.map((organization) => (
78+
{filteredOrganizations.map((organization) => (
7079
<MenuItem
80+
sx={{ maxWidth: "65vw" }}
7181
key={organization.id}
7282
onClick={() => handleClick(organization)}
7383
selected={organization.id === currentOrganizationId}
7484
>
75-
{organization.name}
85+
<Avatar sx={{ height: 30, width: 30, mr: 2 }}>
86+
{organization.name[0]}
87+
</Avatar>
88+
<Typography
89+
sx={{
90+
overflow: "hidden",
91+
textOverflow: "ellipsis",
92+
whiteSpace: "nowrap",
93+
}}
94+
>
95+
{organization.name}
96+
</Typography>
7697
</MenuItem>
7798
))}
7899
</>
79100
);
80101
}
81102

82103
export function CurrentOrganizationAvatar(): ReactElement {
104+
const isMobile = useIsMobile();
105+
106+
const [drawerIsOpen, setIsDrawerOpen] = useState(false);
107+
83108
const query = useQuery({
84109
queryKey: [CacheKeysConstants.CurrentOrganization],
85110
queryFn: () => organizationsApi.getCurrentOrganization(),
@@ -93,6 +118,46 @@ export function CurrentOrganizationAvatar(): ReactElement {
93118
return <ErrorOutline color="error" sx={{ height: 30, width: 30 }} />;
94119
}
95120

121+
if (isMobile) {
122+
return (
123+
<>
124+
<ButtonBase onClick={() => setIsDrawerOpen(true)}>
125+
<Avatar sx={{ height: 30, width: 30 }}>{query.data.name[0]}</Avatar>
126+
</ButtonBase>
127+
128+
<Drawer
129+
onClose={() => setIsDrawerOpen(false)}
130+
open={drawerIsOpen}
131+
sx={{ zIndex: (theme) => theme.zIndex.drawer + 2 }}
132+
>
133+
<Box
134+
sx={{
135+
display: "flex",
136+
alignItems: "center",
137+
p: 2,
138+
gap: 2,
139+
width: "65vw",
140+
}}
141+
>
142+
<Avatar sx={{ height: 30, width: 30 }}>{query.data.name[0]}</Avatar>
143+
<Typography
144+
sx={{
145+
overflow: "hidden",
146+
textOverflow: "ellipsis",
147+
whiteSpace: "nowrap",
148+
}}
149+
variant="h6"
150+
>
151+
{query.data.name}
152+
</Typography>
153+
</Box>
154+
<Divider sx={{ mb: 1 }} />
155+
<MenuContent currentOrganizationId={query.data.id} />
156+
</Drawer>
157+
</>
158+
);
159+
}
160+
96161
return (
97162
<Menu
98163
anchorOrigin={{

services/web-ui/src/pages/AuthenticationGuard/AuthenticationGuard.nav.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export interface AuthenticationGuardNavProps {
99
export function AuthenticationGuardNav({
1010
children,
1111
}: AuthenticationGuardNavProps): React.ReactElement {
12-
return <Box sx={{ height: "100vh" }}>{children}</Box>;
12+
return <Box sx={{ height: "100vh", px: 3 }}>{children}</Box>;
1313
}

services/web-ui/src/pages/ProfileGuard/ProfileGuard.nav.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ interface ProfileGuardNavProps {
99
export function ProfileGuardNav({
1010
children,
1111
}: ProfileGuardNavProps): React.ReactElement {
12-
return <Box sx={{ height: "100vh" }}>{children}</Box>;
12+
return <Box sx={{ height: "100vh", px: 3 }}>{children}</Box>;
1313
}

0 commit comments

Comments
 (0)