tutu/src/timelines/ProfileMenuButton.tsx

124 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-07-14 20:28:44 +08:00
import {
Avatar,
ButtonBase,
Divider,
ListItemAvatar,
ListItemIcon,
ListItemText,
MenuItem,
} from "@suid/material";
2024-08-05 15:33:00 +08:00
import {
Show,
createUniqueId,
type ParentComponent,
} from "solid-js";
2024-07-14 20:28:44 +08:00
import {
Settings as SettingsIcon,
Bookmark as BookmarkIcon,
Star as LikeIcon,
FeaturedPlayList as ListIcon,
} from "@suid/icons-material";
2024-11-16 20:04:55 +08:00
import A from "../platform/A";
2024-11-19 17:03:56 +08:00
import Menu, { createManagedMenuState } from "../material/Menu";
2024-07-14 20:28:44 +08:00
const ProfileMenuButton: ParentComponent<{
2024-10-18 19:15:35 +08:00
profile?: {
account: {
site: string;
inf?: {
displayName: string;
avatar: string;
username: string;
id: string;
};
};
2024-10-18 19:15:35 +08:00
};
2024-07-14 20:28:44 +08:00
}> = (props) => {
const menuId = createUniqueId();
const buttonId = createUniqueId();
2024-11-19 17:03:56 +08:00
const [open, state] = createManagedMenuState();
2024-07-14 20:28:44 +08:00
const onClick = (
event: MouseEvent & { currentTarget: HTMLButtonElement },
) => {
2024-11-19 17:03:56 +08:00
open(event.currentTarget.getBoundingClientRect());
2024-07-14 20:28:44 +08:00
};
const inf = () => props.profile?.account.inf;
2024-07-14 20:28:44 +08:00
return (
<>
2024-10-18 19:15:35 +08:00
<ButtonBase
aria-haspopup="true"
sx={{ borderRadius: "50%" }}
id={buttonId}
onClick={onClick}
aria-controls={open() ? menuId : undefined}
aria-expanded={open() ? "true" : undefined}
>
<Avatar
alt={`${inf()?.displayName}'s avatar`}
src={inf()?.avatar}
2024-10-18 19:15:35 +08:00
></Avatar>
</ButtonBase>
<Menu
id={menuId}
MenuListProps={{
2024-11-19 17:03:56 +08:00
"aria-labelledby": menuId,
style: {
"min-width": "220px",
2024-10-18 19:15:35 +08:00
},
}}
2024-11-19 17:03:56 +08:00
{...state}
2024-10-18 19:15:35 +08:00
>
<MenuItem
component={A}
href={`/${encodeURIComponent(`${inf()?.username}@${props.profile?.account.site}`)}/profile/${inf()?.id}`}
2024-10-18 19:15:35 +08:00
disabled={!props.profile}
2024-08-05 15:33:00 +08:00
>
2024-10-18 19:15:35 +08:00
<ListItemAvatar>
<Avatar src={inf()?.avatar}></Avatar>
2024-10-18 19:15:35 +08:00
</ListItemAvatar>
<ListItemText
primary={inf()?.displayName}
secondary={`@${inf()?.username}`}
2024-10-18 19:15:35 +08:00
></ListItemText>
</MenuItem>
2024-07-14 20:28:44 +08:00
<MenuItem disabled>
2024-10-18 19:15:35 +08:00
<ListItemIcon>
<BookmarkIcon />
</ListItemIcon>
<ListItemText>Bookmarks</ListItemText>
</MenuItem>
<MenuItem disabled>
2024-10-18 19:15:35 +08:00
<ListItemIcon>
<LikeIcon />
</ListItemIcon>
<ListItemText>Likes</ListItemText>
</MenuItem>
<MenuItem disabled>
2024-10-18 19:15:35 +08:00
<ListItemIcon>
<ListIcon />
</ListItemIcon>
<ListItemText>Lists</ListItemText>
</MenuItem>
<Divider />
<Show when={props.children}>
{props.children}
2024-07-14 20:28:44 +08:00
<Divider />
2024-10-18 19:15:35 +08:00
</Show>
<MenuItem component={A} href="/settings">
2024-10-18 19:15:35 +08:00
<ListItemIcon>
<SettingsIcon />
</ListItemIcon>
<ListItemText>Settings</ListItemText>
</MenuItem>
</Menu>
2024-07-14 20:28:44 +08:00
</>
);
};
export default ProfileMenuButton;