Skip to content

Feature: Cache loaded lessons to prevent flickering when switching between lessons #9

Description

Problem

When a user switches between lessons in a course, the lesson details panel shows a loading skeleton every time, even if the lesson was previously loaded. This creates a poor UX with constant flickering and delays.

Current Behavior

In CourseCubit.selectLesson():

  1. Sets isLessonDetailsLoading = true (shows skeleton)
  2. Calls _lessonsRepository.getLesson(lessonId) (always network call)
  3. Waits for response
  4. Sets isLessonDetailsLoading = false

This happens every time the user clicks on a lesson, even if they just viewed it.

Expected Behavior

  • Once a lesson is loaded, it should be cached in memory for the session
  • Switching back to a previously viewed lesson should be instant (no loading state)
  • Cache is per-course and per-session (cleared when leaving the course)

Proposed Solution

Add an in-memory cache in CourseCubit:

dart // Cache for loaded lessons: lessonId -> Lesson static final _lessonsCache = <String, Lesson>{};

Modify selectLesson() to check cache first:
`dart
Future selectLesson(String lessonId) async {
// Check cache first
final cachedLesson = _lessonsCache[lessonId];
if (cachedLesson != null) {
emit(state.copyWith(selectedLesson: cachedLesson));
// Optionally refresh in background
_refreshLessonInBackground(lessonId);
return;
}

// Show loading only if not in cache
emit(state.copyWith(isLessonDetailsLoading: true));
// ... existing loading logic
}
`

Additional Context

The lessons list already has caching (_lessonsCache for List), but the lesson details don't.

Acceptance Criteria

  • First load of a lesson shows loading skeleton (as now)
  • Second visit to the same lesson is instant (no loading)
  • Tasks existence is also cached to avoid extra network calls
  • Cache is cleared when leaving the course (optional: keep for browser back navigation)

Files to Modify

  • �pps/condor_code_app/lib/ui/screens/course/course_cubit/course_cubit.dart
  • �pps/condor_code_app/lib/ui/screens/course/course_cubit/course_state.dart (maybe, for tasks cache)

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions