import { List as ImmutableList } from 'immutable'; import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; import { openModal } from 'soapbox/actions/modals'; import StillImage from 'soapbox/components/still-image'; import { Avatar, Button, HStack, IconButton, Menu, MenuButton, MenuDivider, MenuItem, MenuLink, MenuList } from 'soapbox/components/ui'; import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; import { useAppDispatch, useOwnAccount } from 'soapbox/hooks'; import { normalizeAttachment } from 'soapbox/normalizers'; import type { Menu as MenuType } from 'soapbox/components/dropdown-menu'; import type { Group } from 'soapbox/types/entities'; const messages = defineMessages({ header: { id: 'group.header.alt', defaultMessage: 'Group header' }, }); interface IGroupHeader { group?: Group | false | null, } const GroupHeader: React.FC = ({ group }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const ownAccount = useOwnAccount(); if (!group) { return (
); } const onAvatarClick = () => { const avatar = normalizeAttachment({ type: 'image', url: group.avatar, }); dispatch(openModal('MEDIA', { media: ImmutableList.of(avatar), index: 0 })); }; const handleAvatarClick: React.MouseEventHandler = (e) => { if (e.button === 0 && !(e.ctrlKey || e.metaKey)) { e.preventDefault(); onAvatarClick(); } }; const onHeaderClick = () => { const header = normalizeAttachment({ type: 'image', url: group.header, }); dispatch(openModal('MEDIA', { media: ImmutableList.of(header), index: 0 })); }; const handleHeaderClick: React.MouseEventHandler = (e) => { if (e.button === 0 && !(e.ctrlKey || e.metaKey)) { e.preventDefault(); onHeaderClick(); } }; const makeMenu = () => { const menu: MenuType = []; return menu; }; const makeActionButton = () => { if (group.relationship?.role === 'admin') { return ( ); } return null; }; const menu = makeMenu(); const actionButton = makeActionButton(); return (
{group.header && ( )}
{/* {info} */}
{ownAccount && ( {menu.map((menuItem, idx) => { if (typeof menuItem?.text === 'undefined') { return ; } else { const Comp = (menuItem.action ? MenuItem : MenuLink) as any; const itemProps = menuItem.action ? { onSelect: menuItem.action } : { to: menuItem.to, as: Link, target: menuItem.newTab ? '_blank' : '_self' }; return ( {menuItem.icon && ( )}
{menuItem.text}
); } })}
)} {actionButton}
); }; export default GroupHeader;