// Item list item import { h } from 'preact'; import PropTypes from 'prop-types'; export const ItemListItem = ({ item, children }) => { const adaptedItem = { path: item.reactable.path, title: item.reactable.title, user: item.reactable.user, publishedDate: item.reactable.readable_publish_date_string, readingTime: item.reactable.reading_time, tags: item.reactable.tags, }; // update readingTime to 1 min if the reading time is less than 1 min adaptedItem.readingTime = Math.max(1, adaptedItem.readingTime || null); return (
{adaptedItem.user.name}

{adaptedItem.user.name} {adaptedItem.publishedDate} {`${adaptedItem.readingTime} min read`} {adaptedItem.tags.length > 0 ? ( {adaptedItem.tags.map((tag) => ( {`#${tag.name}`} ))} ) : ( '' )}

{children}
); }; const readingListItemPropTypes = PropTypes.shape({ reactable: { path: PropTypes.string.isRequired, title: PropTypes.string.isRequired, reading_time: PropTypes.number.isRequired, readable_publish_date_string: PropTypes.string.isRequired, user: PropTypes.shape({ username: PropTypes.string.isRequired, profile_image_90: PropTypes.string.isRequired, name: PropTypes.string.isRequired, }), tags: PropTypes.arrayOf(PropTypes.string).isRequired, }, }); ItemListItem.propTypes = { item: PropTypes.oneOfType([readingListItemPropTypes]).isRequired, };