Skip to content

Commit

Permalink
extract tumID
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityDarkLab committed Feb 2, 2024
1 parent 3504ea8 commit b0a5026
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
60 changes: 57 additions & 3 deletions lib/views/course_view/components/course_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,50 @@ class CourseCard extends StatelessWidget {
//for displaying livestreams
final String? subtitle;

const CourseCard({
const CourseCard._({
super.key,
required this.title,
this.subtitle,
required this.tumID,
required this.courseId,
required this.onTap,
required this.courseId,
// Pass other fields as before
this.live,
this.course,
this.onPinUnpin,
this.isPinned,
required this.isLoggedIn,
this.subtitle,
});

factory CourseCard({
Key? key,
required String title,
String? subtitle,
required int courseId,
required VoidCallback onTap,
bool? live,
Course? course,
Function(Course)? onPinUnpin,
bool? isPinned,
required bool isLoggedIn,
}) {
final tumID = _extractCourseIds(title);
return CourseCard._(
key: key,
title: title,
tumID: tumID,
courseId: courseId,
onTap: onTap,
live: live,
course: course,
onPinUnpin: onPinUnpin,
isPinned: isPinned,
isLoggedIn: isLoggedIn,
subtitle: subtitle,
);
}


@override
Widget build(BuildContext context) {
ThemeData themeData = Theme.of(context);
Expand Down Expand Up @@ -227,6 +257,8 @@ class CourseCard extends StatelessWidget {
return Colors.red;
case 'EL':
return Colors.black87;
case 'CI':
return Colors.teal;
default:
return Colors.grey;
}
Expand Down Expand Up @@ -258,4 +290,26 @@ class CourseCard extends StatelessWidget {
),
);
}

static String _extractCourseIds(String title) {
// This pattern is designed to repeatedly capture course IDs with specified prefixes,
// followed by alphanumeric characters and possibly separated by commas within brackets or parentheses.
// It uses a global search to find all occurrences of such patterns.
final pattern = RegExp(r'(?:CIT|IN|MA|CH|MW|PH)\d[\w-]*');
final matches = pattern.allMatches(title);

// Initialize an empty list to collect IDs.
List<String> ids = [];

// Iterate over all matches and add the matched ID to the list.
for (var match in matches) {
ids.add(match.group(0)!); // Safe to use `!` as allMatches() only returns non-null matches.
}

// Join extracted IDs with a dash.
return ids.join(' , ');
}



}
1 change: 0 additions & 1 deletion lib/views/course_view/components/course_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class CourseSection extends StatelessWidget {
isPinned: isPinned,
onPinUnpin: (course) => _togglePin(course, isPinned),
title: course.name,
tumID: course.slug,
live: streams.any((stream) => stream.courseID == course.id),
courseId: course.id,
onTap: () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class CoursesList extends ConsumerWidget {
}
},
title: course.name,
tumID: course.tUMOnlineIdentifier,
live: liveCourses.contains(course),
courseId: course.id,
onTap: () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class PinnedCoursesState extends ConsumerState<PinnedCourses> {
title: course.name,
courseId: course.id,
subtitle: course.tUMOnlineIdentifier,
tumID: course.tUMOnlineIdentifier,
onTap: () => _handleCourseTap(course, context),
);
}).toList(),
Expand Down

0 comments on commit b0a5026

Please sign in to comment.