2024-07-14 20:28:44 +08:00
|
|
|
import {
|
|
|
|
Avatar,
|
|
|
|
ButtonBase,
|
|
|
|
Divider,
|
|
|
|
ListItemAvatar,
|
|
|
|
ListItemIcon,
|
|
|
|
ListItemText,
|
|
|
|
Menu,
|
|
|
|
MenuItem,
|
|
|
|
} from "@suid/material";
|
2024-08-05 15:33:00 +08:00
|
|
|
import {
|
|
|
|
ErrorBoundary,
|
|
|
|
Show,
|
|
|
|
createSignal,
|
|
|
|
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-07-14 20:28:44 +08:00
|
|
|
|
|
|
|
const ProfileMenuButton: ParentComponent<{
|
2024-10-18 19:15:35 +08:00
|
|
|
profile?: {
|
2024-11-04 18:21:22 +08:00
|
|
|
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
|
|
|
onClick?: () => void;
|
|
|
|
onClose?: () => void;
|
|
|
|
}> = (props) => {
|
|
|
|
const menuId = createUniqueId();
|
|
|
|
const buttonId = createUniqueId();
|
|
|
|
|
|
|
|
let [anchor, setAnchor] = createSignal<HTMLButtonElement | null>(null);
|
|
|
|
const open = () => !!anchor();
|
|
|
|
|
|
|
|
const onClick = (
|
|
|
|
event: MouseEvent & { currentTarget: HTMLButtonElement },
|
|
|
|
) => {
|
|
|
|
setAnchor(event.currentTarget);
|
|
|
|
props.onClick?.();
|
|
|
|
};
|
|
|
|
|
2024-11-16 22:26:16 +08:00
|
|
|
const inf = () => props.profile?.account.inf;
|
2024-11-04 18:21:22 +08:00
|
|
|
|
2024-07-14 20:28:44 +08:00
|
|
|
const onClose = () => {
|
|
|
|
props.onClick?.();
|
|
|
|
setAnchor(null);
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2024-11-04 18:21:22 +08:00
|
|
|
alt={`${inf()?.displayName}'s avatar`}
|
|
|
|
src={inf()?.avatar}
|
2024-10-18 19:15:35 +08:00
|
|
|
></Avatar>
|
|
|
|
</ButtonBase>
|
|
|
|
<Menu
|
|
|
|
id={menuId}
|
|
|
|
anchorEl={anchor()}
|
|
|
|
open={open()}
|
|
|
|
onClose={onClose}
|
|
|
|
MenuListProps={{
|
|
|
|
"aria-labelledby": buttonId,
|
|
|
|
sx: {
|
|
|
|
minWidth: "220px",
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
anchorOrigin={{
|
|
|
|
vertical: "top",
|
|
|
|
horizontal: "right",
|
|
|
|
}}
|
|
|
|
transformOrigin={{
|
|
|
|
vertical: "top",
|
|
|
|
horizontal: "right",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<MenuItem
|
|
|
|
component={A}
|
2024-11-04 18:21:22 +08:00
|
|
|
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>
|
2024-11-04 18:21:22 +08:00
|
|
|
<Avatar src={inf()?.avatar}></Avatar>
|
2024-10-18 19:15:35 +08:00
|
|
|
</ListItemAvatar>
|
|
|
|
<ListItemText
|
2024-11-04 18:21:22 +08:00
|
|
|
primary={inf()?.displayName}
|
|
|
|
secondary={`@${inf()?.username}`}
|
2024-10-18 19:15:35 +08:00
|
|
|
></ListItemText>
|
|
|
|
</MenuItem>
|
2024-07-14 20:28:44 +08:00
|
|
|
|
2024-11-04 18:21:22 +08:00
|
|
|
<MenuItem disabled>
|
2024-10-18 19:15:35 +08:00
|
|
|
<ListItemIcon>
|
|
|
|
<BookmarkIcon />
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText>Bookmarks</ListItemText>
|
|
|
|
</MenuItem>
|
2024-11-04 18:21:22 +08:00
|
|
|
<MenuItem disabled>
|
2024-10-18 19:15:35 +08:00
|
|
|
<ListItemIcon>
|
|
|
|
<LikeIcon />
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText>Likes</ListItemText>
|
|
|
|
</MenuItem>
|
2024-11-04 18:21:22 +08:00
|
|
|
<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>
|
2024-11-16 22:26:16 +08:00
|
|
|
<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;
|