Skip to content

Commit

Permalink
fix: set proper active course having alias in url (#2600)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlovich authored Feb 20, 2025
1 parent dda094c commit b3cb96e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions client/src/modules/Course/contexts/ActiveCourseContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ export const ActiveCourseProvider = ({ children }: Props) => {
const alias = router.query.course;
const [storageCourseId] = useLocalStorage('activeCourseId');
const [activeCourse, setActiveCourse] = useState<ProfileCourseDto>();
const [loading, setLoading] = useState(true);

const { error, loading } = useAsync(async () => {
if (!coursesCache) {
coursesCache = await new UserService().getCourses();
}

const course =
coursesCache.find(course => course.alias === alias) ??
coursesCache.find(course => course.id === storageCourseId) ??
coursesCache[0];
const { error } = useAsync(async () => {
if (router.isReady) {
if (!coursesCache) {
coursesCache = await new UserService().getCourses();
}

setActiveCourse(course);
const course =
coursesCache.find(course => course.alias === alias) ??
coursesCache.find(course => course.id === storageCourseId) ??
coursesCache[0];

return course;
}, []);
setCourse(course);
setLoading(false);
}
}, [router.isReady]);

const setCourse = (course: ProfileCourseDto) => {
setActiveCourse(course);
Expand Down

0 comments on commit b3cb96e

Please sign in to comment.