Skip to content

Commit 67648d3

Browse files
Only skip scroll-to-top when staying on course introduction
Scroll the course page to top on route change except when both from and to are course.introduction (e.g. language selection updating repo/track query params). Keeps scroll reset when entering/leaving stages. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 60cb760 commit 67648d3

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

app/routes/course/stage.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BaseRoute from 'codecrafters-frontend/utils/base-route';
22
import scrollToTop from 'codecrafters-frontend/utils/scroll-to-top';
33
import { service } from '@ember/service';
4+
import type Transition from '@ember/routing/transition';
45
import type RouterService from '@ember/routing/router-service';
56
import type CoursePageStateService from 'codecrafters-frontend/services/course-page-state';
67
import type { ModelType as CourseRouteModelType } from 'codecrafters-frontend/routes/course';
@@ -17,7 +18,14 @@ export default class CourseStageRoute extends BaseRoute {
1718
constructor(...args: object[]) {
1819
super(...args);
1920

20-
this.router.on('routeDidChange', () => {
21+
this.router.on('routeDidChange', (transition: Transition) => {
22+
if (
23+
transition?.from?.name === 'course.introduction' &&
24+
transition?.to?.name === 'course.introduction'
25+
) {
26+
return;
27+
}
28+
2129
const element = document.querySelector('#course-page-scrollable-area');
2230

2331
if (element) {

0 commit comments

Comments
 (0)