Skip to content

Commit 0ea7ef9

Browse files
authored
Merge pull request #92 from CrackCode-dev/nadeesha-backup3
fix(RecommendedChallenges): correct state initialization and enhance …
2 parents f518f4d + d5d3c3d commit 0ea7ef9

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

crackcode/client/src/components/home/RecommendedChallenges.jsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ const PLACEHOLDER = [
1313
];
1414

1515
export default function RecommendedChallenges() {
16-
useTheme();
16+
const { theme } = useTheme();
1717
const [hoveredId, setHoveredId] = useState(null);
18-
const [savedIds] = useState(new Set());
18+
const [savedIds, setSavedIds] = useState(new Set());
1919
const [cards, setCards] = useState(PLACEHOLDER);
2020
const [loading, setLoading] = useState(false);
21-
const [setError] = useState(null);
21+
const [error, setError] = useState(null);
2222
const navigate = useNavigate();
2323

2424
useEffect(() => {
@@ -65,6 +65,16 @@ export default function RecommendedChallenges() {
6565
return () => { mounted = false }
6666
}, [])
6767

68+
const toggleSaved = (id, e) => {
69+
e.stopPropagation();
70+
const newSet = new Set(savedIds);
71+
if (newSet.has(id)) {
72+
newSet.delete(id);
73+
} else {
74+
newSet.add(id);
75+
}
76+
setSavedIds(newSet);
77+
};
6878

6979
return (
7080
<div className='w-full' style={{ color: 'var(--text)' }}>
@@ -87,7 +97,7 @@ export default function RecommendedChallenges() {
8797

8898
<div className='grid grid-cols-1 md:grid-cols-3 gap-6'>
8999
{loading && <div className='text-sm text-gray-300'>Loading recommendations…</div>}
90-
{!loading && cards.map((challenge) => (
100+
{!loading && cards.map((challenge, index) => (
91101
<div
92102
key={challenge.id}
93103
onMouseEnter={() => setHoveredId(challenge.id)}
@@ -201,11 +211,11 @@ export default function RecommendedChallenges() {
201211
View All Recommendations
202212
<ArrowRight className='w-4 h-4' />
203213
</button> */}
204-
<Button variant='primary' size='md' icon={ArrowRight} iconPosition='right' onClick={() => navigate("/caselog")}>
214+
<Button variant='primary' size='md' icon={ArrowRight} iconPosition='right'>
205215
View All Recommendations
206216
</Button>
207217
</div>
208218
</div>
209219
</div>
210220
);
211-
}
221+
}

0 commit comments

Comments
 (0)