({ items, removeItem, updateItem, weightUnit })
| 21 | } |
| 22 | |
| 23 | const PackItems: React.FC<PackItemProps> = ({ items, removeItem, updateItem, weightUnit }) => { |
| 24 | const [updateId, setUpdateId] = React.useState<number | null>(null); |
| 25 | const categories = getCategories(items); |
| 26 | const weightByCategory = getWeightByCategory(weightUnit, items); |
| 27 | |
| 28 | const renderEmptyList = () => ( |
| 29 | <MessageArea> |
| 30 | Select items from your inventory to begin<br/> building your packing list. |
| 31 | </MessageArea> |
| 32 | ); |
| 33 | |
| 34 | const update = (id: number, field: string, value: string | number | boolean) => { |
| 35 | updateItem(id, field, value); |
| 36 | setUpdateId(id); |
| 37 | }; |
| 38 | |
| 39 | const renderGroupedItems = () => ( |
| 40 | categories.map(cat => { |
| 41 | const catItems = items.filter(i => i.categoryId === cat.id); |
| 42 | const catWeight = weightByCategory.find(c => c.id === cat.id); |
| 43 | const Header = ( |
| 44 | <> |
| 45 | <h3>{cat.name}</h3> |
| 46 | <strong>{catWeight!.total.label} {weightUnit}</strong> |
| 47 | </> |
| 48 | ); |
| 49 | return ( |
| 50 | <CategoryGroup key={cat.id}> |
| 51 | <ExpandablePanel Header={Header}> |
| 52 | <div style={{ padding: '0 8px' }}> |
| 53 | {catItems.map(item => ( |
| 54 | <Item key={item.id} |
| 55 | item={item} |
| 56 | updateId={updateId} |
| 57 | removeItem={removeItem} |
| 58 | updateItem={update}/>) |
| 59 | )} |
| 60 | </div> |
| 61 | </ExpandablePanel> |
| 62 | </CategoryGroup> |
| 63 | ) |
| 64 | }) |
| 65 | ); |
| 66 | |
| 67 | return ( |
| 68 | <div style={{ marginTop: '8px' }}> |
| 69 | {items.length ? renderGroupedItems() : renderEmptyList()} |
| 70 | </div> |
| 71 | ) |
| 72 | }; |
| 73 | |
| 74 | export default PackItems; |
nothing calls this directly
no test coverage detected