Skip to content

Commit

Permalink
Merge branch 'main' into feat-export-document
Browse files Browse the repository at this point in the history
  • Loading branch information
minai621 authored Jul 20, 2024
2 parents 1d6e835 + cd36e26 commit 8bbdd51
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions frontend/src/components/headers/DocumentHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ import {
ToggleButtonGroup,
Toolbar,
Tooltip,
Popover,
Typography,
List,
ListItem,
ListItemAvatar,
ListItemText,
} from "@mui/material";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
import { useList } from "react-use";
Expand Down Expand Up @@ -45,6 +51,8 @@ function DocumentHeader() {
presence: YorkieCodeMirrorPresenceType;
}>([]);

const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);

useEffect(() => {
if (editorState.shareRole === "READ") {
dispatch(setMode("read"));
Expand Down Expand Up @@ -88,6 +96,20 @@ function DocumentHeader() {
navigate(`/${workspaceState.data?.slug}`);
};

// Display additional users in a popover when there are more than 4 users
const handleOpenPopover = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};

// Display None additional users in a popover when there are more than 4 users
const handleClosePopover = () => {
setAnchorEl(null);
};

const popoverOpen = Boolean(anchorEl);

const hiddenAvatars = presenceList.slice(3);

return (
<AppBar position="static" sx={{ zIndex: 100 }}>
<Toolbar>
Expand Down Expand Up @@ -129,7 +151,7 @@ function DocumentHeader() {
<DownloadMenu />
</Stack>
<Stack direction="row" alignItems="center" gap={1}>
<AvatarGroup max={4}>
<AvatarGroup max={4} onClick={handleOpenPopover}>
{presenceList?.map((presence) => (
<Tooltip key={presence.clientID} title={presence.presence.name}>
<Avatar
Expand All @@ -141,6 +163,43 @@ function DocumentHeader() {
</Tooltip>
))}
</AvatarGroup>
<Popover
open={popoverOpen}
anchorEl={anchorEl}
onClose={handleClosePopover}
anchorOrigin={{
vertical: "bottom",
horizontal: "left",
}}
>
<Paper sx={{ padding: 2 }}>
<Typography variant="subtitle2">Additional Users</Typography>
<List>
{hiddenAvatars.map((presence) => (
<ListItem key={presence.clientID} sx={{ paddingY: 0.5 }}>
<ListItemAvatar>
<Avatar
sx={{
bgcolor: presence.presence.color,
width: 24,
height: 24,
fontSize: 12,
}}
>
{presence.presence.name[0]}
</Avatar>
</ListItemAvatar>
<ListItemText
primary={presence.presence.name}
primaryTypographyProps={{
variant: "body2",
}}
/>
</ListItem>
))}
</List>
</Paper>
</Popover>
{!editorState.shareRole && <ShareButton />}
<ThemeButton />
</Stack>
Expand Down

0 comments on commit 8bbdd51

Please sign in to comment.