Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions frontend/src/pages/ChallengeListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ const TYPE_LABEL = {

export default function ChallengeListPage() {
const [challenges, setChallenges] = useState([])
const [passedIds, setPassedIds] = useState(new Set())
const [error, setError] = useState(null)

useEffect(() => {
api.get('/challenges')
.then(res => setChallenges(res.data))
.catch(() => setError('Failed to load challenges.'))
Promise.all([
api.get('/challenges'),
api.get('/submissions/me/passed'),
]).then(([challengesRes, passedRes]) => {
setChallenges(challengesRes.data)
setPassedIds(new Set(passedRes.data))
}).catch(() => setError('Failed to load challenges.'))
}, [])

return (
Expand All @@ -37,6 +42,7 @@ export default function ChallengeListPage() {
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
<thead>
<tr style={{ borderBottom: '1px solid #2d3748', color: '#718096', fontSize: 13, textAlign: 'left' }}>
<th style={{ padding: '8px 12px', width: 32 }}></th>
<th style={{ padding: '8px 12px' }}>#</th>
<th style={{ padding: '8px 12px' }}>Title</th>
<th style={{ padding: '8px 12px' }}>Type</th>
Expand All @@ -49,6 +55,9 @@ export default function ChallengeListPage() {
key={c.id}
style={{ borderBottom: '1px solid #1a202c' }}
>
<td style={{ padding: '12px 12px', fontSize: 14, color: '#68d391' }}>
{passedIds.has(c.id) ? '✓' : ''}
</td>
<td style={{ padding: '12px 12px', color: '#718096', fontSize: 14 }}>{i + 1}</td>
<td style={{ padding: '12px 12px' }}>
<Link to={`/challenges/${c.id}`} style={{ fontWeight: 500 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@ public List<Submission> mySubmissions() {
.orElseThrow(() -> new RuntimeException("User not found"));
return submissionRepository.findByUser(user);
}

@GetMapping("/me/passed")
public List<Long> passedChallengeIds() {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
AppUser user = appUserRepository.findByUsername(username)
.orElseThrow(() -> new RuntimeException("User not found"));
return submissionRepository.findByUserAndStatus(user, "PASS")
.stream()
.map(s -> s.getChallenge().getId())
.distinct()
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

public interface SubmissionRepository extends JpaRepository<Submission, Long> {
List<Submission> findByUser(AppUser user);
List<Submission> findByUserAndStatus(AppUser user, String status);
}
Loading