2022-01-10 14:17:52 -08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import React from 'react';
|
2022-03-21 11:09:01 -07:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2022-06-07 09:25:53 -07:00
|
|
|
import { spring } from 'react-motion';
|
|
|
|
|
|
|
|
import Icon from 'soapbox/components/icon';
|
|
|
|
import StatusContent from 'soapbox/components/status_content';
|
|
|
|
import { Stack } from 'soapbox/components/ui';
|
|
|
|
import AccountContainer from 'soapbox/containers/account_container';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2021-11-04 08:37:16 -07:00
|
|
|
import Motion from '../util/optional_motion';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-07 09:25:53 -07:00
|
|
|
import type { Menu, MenuItem } from 'soapbox/components/dropdown_menu';
|
|
|
|
import type { Status as StatusEntity } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
interface IActionsModal {
|
|
|
|
status: StatusEntity,
|
|
|
|
actions: Menu,
|
|
|
|
onClick: () => void,
|
|
|
|
onClose: () => void,
|
|
|
|
}
|
|
|
|
|
|
|
|
const ActionsModal: React.FC<IActionsModal> = ({ status, actions, onClick, onClose }) => {
|
|
|
|
const renderAction = (action: MenuItem | null, i: number) => {
|
2020-03-27 13:59:38 -07:00
|
|
|
if (action === null) {
|
|
|
|
return <li key={`sep-${i}`} className='dropdown-menu__separator' />;
|
|
|
|
}
|
|
|
|
|
2021-11-08 08:21:33 -08:00
|
|
|
const { icon = null, text, meta = null, active = false, href = '#', isLogout, destructive } = action;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
const Comp = href === '#' ? 'button' : 'a';
|
|
|
|
const compProps = href === '#' ? { onClick: onClick } : { href: href };
|
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
return (
|
|
|
|
<li key={`${text}-${i}`}>
|
2022-03-21 11:09:01 -07:00
|
|
|
<Comp
|
|
|
|
{...compProps}
|
2020-03-27 13:59:38 -07:00
|
|
|
rel='noopener'
|
|
|
|
data-index={i}
|
2021-11-08 08:21:33 -08:00
|
|
|
className={classNames({ active, destructive })}
|
2020-03-27 13:59:38 -07:00
|
|
|
data-method={isLogout ? 'delete' : null}
|
|
|
|
>
|
2022-06-30 07:51:36 -07:00
|
|
|
{icon && <Icon title={text} src={icon} role='presentation' tabIndex={-1} />}
|
2020-03-27 13:59:38 -07:00
|
|
|
<div>
|
|
|
|
<div className={classNames({ 'actions-modal__item-label': !!meta })}>{text}</div>
|
|
|
|
<div>{meta}</div>
|
|
|
|
</div>
|
2022-03-21 11:09:01 -07:00
|
|
|
</Comp>
|
2020-03-27 13:59:38 -07:00
|
|
|
</li>
|
|
|
|
);
|
2022-03-21 11:09:01 -07:00
|
|
|
};
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
return (
|
|
|
|
<Motion defaultStyle={{ top: 100 }} style={{ top: spring(0) }}>
|
|
|
|
{({ top }) => (
|
|
|
|
<div className='modal-root__modal actions-modal' style={{ top: `${top}%` }}>
|
|
|
|
{status && (
|
2022-04-14 13:20:53 -07:00
|
|
|
<Stack space={2} className='p-4 bg-gray-50 dark:bg-slate-800 border-b border-solid border-gray-200 dark:border-gray-700'>
|
2022-03-21 11:09:01 -07:00
|
|
|
<AccountContainer
|
2022-06-07 09:25:53 -07:00
|
|
|
key={status.account as string}
|
|
|
|
id={status.account as string}
|
2022-03-21 11:09:01 -07:00
|
|
|
showProfileHoverCard={false}
|
2022-07-01 13:07:01 -07:00
|
|
|
withLinkToProfile={false}
|
2022-06-07 09:25:53 -07:00
|
|
|
timestamp={status.created_at}
|
2022-03-21 11:09:01 -07:00
|
|
|
/>
|
|
|
|
<StatusContent status={status} />
|
|
|
|
</Stack>
|
|
|
|
)}
|
2021-11-04 08:37:16 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
<ul className={classNames({ 'with-status': !!status })}>
|
|
|
|
{actions && actions.map(renderAction)}
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
<li className='dropdown-menu__separator' />
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
<li>
|
|
|
|
<button type='button' onClick={onClose}>
|
|
|
|
<FormattedMessage id='lightbox.close' defaultMessage='Cancel' />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2020-03-27 13:59:38 -07:00
|
|
|
</div>
|
2022-03-21 11:09:01 -07:00
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
);
|
|
|
|
};
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
export default ActionsModal;
|