import { h } from 'preact';
import PropTypes from 'prop-types';
// eslint-disable-next-line import/no-unresolved
import ThreeDotsIcon from 'images/overflow-horizontal.svg';
import { adjustTimestamp } from './util';
import { ErrorMessage } from './messages/errorMessage';
import { Button } from '@crayons';
export const Message = ({
currentUserId,
id,
user,
userID,
message,
color,
type,
editedAt,
timestamp,
profileImageUrl,
onContentTrigger,
onDeleteMessageTrigger,
onReportMessageTrigger,
onEditMessageTrigger,
}) => {
const spanStyle = { color };
if (type === 'error') {
return ;
}
const MessageArea = () => {
if (userID === currentUserId) {
message = message.replace(`@${user}`, `@${user}`);
}
return (
);
};
const dropdown = (
);
const dropdownReport = (
);
return (
{user}
{editedAt ? (
{`${adjustTimestamp(editedAt)}`}
(edited)
) : (
' '
)}
{timestamp && !editedAt ? (
{`${adjustTimestamp(timestamp)}`}
) : (
' '
)}
{userID === currentUserId ? dropdown : dropdownReport}
);
};
Message.propTypes = {
currentUserId: PropTypes.number.isRequired,
id: PropTypes.number.isRequired,
user: PropTypes.string.isRequired,
userID: PropTypes.number.isRequired,
color: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
type: PropTypes.string,
timestamp: PropTypes.string,
editedAt: PropTypes.number.isRequired,
profileImageUrl: PropTypes.string,
onContentTrigger: PropTypes.func.isRequired,
onDeleteMessageTrigger: PropTypes.func.isRequired,
onEditMessageTrigger: PropTypes.func.isRequired,
onReportMessageTrigger: PropTypes.func.isRequired,
};
Message.defaultProps = {
type: 'normalMessage',
timestamp: null,
profileImageUrl: '',
};