docbrown/app/javascript/articles/components/PublishDate.jsx
Suzanne Aitchison dcecc8bf00
Log prop-types warnings to console in development (#14635)
* enable debug for warnings in dev env

* remove preact/devtools call no longer needed

* fix majority of proptype errors on home page

* sweep up proptype errors from listings page

* fix article form error
2021-09-01 09:27:58 +01:00

43 lines
865 B
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
/* global timeAgo */
export const PublishDate = ({
readablePublishDate,
publishedTimestamp,
publishedAtInt,
}) => {
const timeAgoIndicator = timeAgo({
oldTimeInSeconds: publishedAtInt,
formatter: (x) => x,
maxDisplayedAge: 60 * 60 * 24 * 7,
});
const timeAgoText = () => {
if (timeAgoIndicator) {
return ` (${timeAgoIndicator})`;
}
return '';
};
return (
<time dateTime={publishedTimestamp}>
{readablePublishDate}
{timeAgoText()}
</time>
);
};
PublishDate.defaultProps = {
publishedTimestamp: null,
publishedAtInt: null,
};
PublishDate.propTypes = {
readablePublishDate: PropTypes.string.isRequired,
publishedTimestamp: PropTypes.string,
publishedAtInt: PropTypes.number,
};
PublishDate.displayName = 'PublishDate';