Skip to content

Commit 6c3fd70

Browse files
Fix TrackLeaderboard when switching language on course page
- Trigger load when leaderboard id changes via did-update so the new language's leaderboard contents load instead of staying in loading state - Catch and ignore TaskCancelation when the load task is restarted so switching leaderboards does not log an error to the console Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent bfe3f67 commit 6c3fd70

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

app/components/track-leaderboard.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div data-test-track-leaderboard {{did-insert this.handleDidInsert}} ...attributes>
1+
<div data-test-track-leaderboard {{did-insert this.handleDidInsert}} {{did-update this.handleDidInsert @leaderboard.id}} ...attributes>
22
<div class="items-center justify-between mb-2 ease-out transition-all duration-300 {{if @isCollapsed 'hidden' 'flex'}} ">
33
<LinkTo
44
@route="leaderboard"

app/components/track-leaderboard.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type LeaderboardEntriesCacheRegistryService from 'codecrafters-frontend/s
99
import type LeaderboardModel from 'codecrafters-frontend/models/leaderboard';
1010
import type RepositoryModel from 'codecrafters-frontend/models/repository';
1111
import type { LeaderboardEntryWithRank } from 'codecrafters-frontend/utils/leaderboard-entries-cache';
12+
import { didCancel } from 'ember-concurrency';
1213
import { action } from '@ember/object';
1314
import { fadeIn, fadeOut } from 'ember-animated/motions/opacity';
1415
import { service } from '@ember/service';
@@ -65,7 +66,13 @@ export default class TrackLeaderboard extends Component<Signature> {
6566

6667
@action
6768
async handleDidInsert() {
68-
await this.leaderboardEntriesCache.loadOrRefresh();
69+
try {
70+
await this.leaderboardEntriesCache.loadOrRefresh();
71+
} catch (error) {
72+
if (!didCancel(error)) {
73+
throw error;
74+
}
75+
}
6976
}
7077

7178
// eslint-disable-next-line require-yield

0 commit comments

Comments
 (0)