import PropTypes from 'prop-types'; import Container from 'react-bootstrap/Container'; import Row from 'react-bootstrap/Row'; import Col from 'react-bootstrap/Col'; import Button from 'react-bootstrap/Button'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faTrash } from '@fortawesome/free-solid-svg-icons/faTrash'; import faCheckSquare from '@fortawesome/fontawesome-free-regular/faCheckSquare'; import faSquare from '@fortawesome/fontawesome-free-regular/faSquare'; import './ItemDisplay.scss'; export function ItemDisplay({ item, onItemUpdate, onItemRemoval }) { const toggleCompletion = () => { fetch(`/api/items/${item.id}`, { method: 'PUT', body: JSON.stringify({ name: item.name, completed: !item.completed, }), headers: { 'Content-Type': 'application/json' }, }) .then((r) => r.json()) .then(onItemUpdate); }; const removeItem = () => { fetch(`/api/items/${item.id}`, { method: 'DELETE' }).then(() => onItemRemoval(item), ); }; return ( {item.name} ); } ItemDisplay.propTypes = { item: PropTypes.shape({ id: PropTypes.string, name: PropTypes.string, completed: PropTypes.bool, }), onItemUpdate: PropTypes.func, onItemRemoval: PropTypes.func, };