|
1 | 1 | import { useState } from 'react'; |
2 | 2 | import SoftwareCard from './SoftwareCard'; |
| 3 | +import { useSelection } from '../../context/SelectionContext'; |
3 | 4 |
|
4 | 5 | const CategorySection = ({ category, software }) => { |
5 | 6 | const [expanded, setExpanded] = useState(true); |
| 7 | + const { isAllCategorySelected, selectAllInCategory, deselectAllInCategory } = useSelection(); |
| 8 | + |
| 9 | + const allSelected = isAllCategorySelected(category.id); |
| 10 | + |
| 11 | + const handleSelectAll = (e) => { |
| 12 | + e.stopPropagation(); |
| 13 | + if (allSelected) { |
| 14 | + deselectAllInCategory(category.id); |
| 15 | + } else { |
| 16 | + selectAllInCategory(category.id); |
| 17 | + } |
| 18 | + }; |
6 | 19 |
|
7 | 20 | return ( |
8 | 21 | <section id={`category-${category.id}`} style={{ marginBottom: '16px' }}> |
9 | | - <div className="win98-raised" style={{ padding: '8px', marginBottom: '8px' }}> |
| 22 | + <div className="win98-raised" style={{ padding: '6px', marginBottom: '8px', display: 'flex', gap: '6px', alignItems: 'stretch' }}> |
10 | 23 | <button |
11 | 24 | onClick={() => setExpanded(!expanded)} |
12 | 25 | className="win98-button" |
13 | 26 | style={{ |
14 | | - width: '100%', |
15 | | - minHeight: '50px', |
| 27 | + flex: 1, |
| 28 | + minHeight: '52px', |
16 | 29 | display: 'flex', |
17 | 30 | alignItems: 'center', |
18 | | - gap: '8px', |
| 31 | + gap: '10px', |
19 | 32 | justifyContent: 'flex-start', |
20 | | - padding: '8px 12px' |
| 33 | + padding: '8px 12px', |
| 34 | + textAlign: 'left' |
21 | 35 | }} |
22 | 36 | aria-expanded={expanded} |
23 | 37 | aria-label={`${expanded ? 'Collapse' : 'Expand'} ${category.name} category`} |
24 | 38 | > |
25 | 39 | <span style={{ fontSize: '20px', flexShrink: 0 }}>{category.icon}</span> |
26 | | - <div style={{ textAlign: 'left', flex: 1, overflow: 'hidden' }}> |
27 | | - <div style={{ fontSize: '13px', fontWeight: 'bold', marginBottom: '3px', lineHeight: '1.2' }}> |
| 40 | + <div style={{ flex: 1, overflow: 'hidden' }}> |
| 41 | + <div style={{ fontSize: '13px', fontWeight: 'bold', marginBottom: '2px', lineHeight: '1.2' }}> |
28 | 42 | {category.name} |
| 43 | + <span style={{ fontSize: '10px', marginLeft: '8px', verticalAlign: 'middle', fontWeight: 'normal', color: 'var(--win98-gray-dark)' }}> |
| 44 | + {expanded ? '▼' : '▶'} |
| 45 | + </span> |
29 | 46 | </div> |
30 | 47 | <div className="category-description" style={{ fontSize: '11px', fontWeight: 'normal', color: 'var(--win95-black)', lineHeight: '1.3' }}> |
31 | 48 | {category.description} |
32 | 49 | </div> |
33 | 50 | </div> |
34 | | - <span style={{ fontSize: '10px', marginLeft: 'auto', flexShrink: 0 }}> |
35 | | - {expanded ? '▼' : '▶'} |
| 51 | + </button> |
| 52 | + |
| 53 | + <button |
| 54 | + onClick={handleSelectAll} |
| 55 | + className={`win98-button ${allSelected ? 'win98-button-danger' : ''}`} |
| 56 | + style={{ |
| 57 | + minWidth: '100px', |
| 58 | + minHeight: '52px', |
| 59 | + display: 'flex', |
| 60 | + flexDirection: 'column', |
| 61 | + alignItems: 'center', |
| 62 | + justifyContent: 'center', |
| 63 | + gap: '4px', |
| 64 | + padding: '4px 12px', |
| 65 | + flexShrink: 0 |
| 66 | + }} |
| 67 | + title={allSelected ? "Deselect all items in this category" : "Select all items in this category"} |
| 68 | + > |
| 69 | + <input |
| 70 | + type="checkbox" |
| 71 | + checked={allSelected} |
| 72 | + readOnly |
| 73 | + className="win98-checkbox" |
| 74 | + style={{ pointerEvents: 'none', marginBottom: '2px' }} |
| 75 | + /> |
| 76 | + <span style={{ fontSize: '10px', fontWeight: 'bold', textTransform: 'uppercase', letterSpacing: '0.5px' }}> |
| 77 | + {allSelected ? 'Deselect All' : 'Select All'} |
36 | 78 | </span> |
37 | 79 | </button> |
38 | 80 | </div> |
|
0 commit comments