Skip to content

Commit

Permalink
fix livenow all views
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityDarkLab committed Jan 27, 2024
1 parent 69e3f1b commit 3a08b2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/views/course_view/list_courses_view/courses_list_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pbgrpc.dart';
import 'package:gocast_mobile/providers.dart';
import 'package:gocast_mobile/utils/constants.dart';

import 'package:gocast_mobile/views/course_view/components/course_card.dart';
Expand Down Expand Up @@ -29,7 +30,7 @@ class CoursesList extends ConsumerWidget {
bool isTablet = MediaQuery.of(context).size.width >= 600;
return courses.isEmpty
? _buildPlaceholder()
: _buildCourseListView(context, isTablet);
: _buildCourseListView(context, isTablet, ref);
}

Padding _buildPlaceholder() {
Expand All @@ -39,7 +40,10 @@ class CoursesList extends ConsumerWidget {
);
}

Widget _buildCourseListView(BuildContext context, bool isTablet) {
Widget _buildCourseListView(BuildContext context, bool isTablet, WidgetRef ref) {
final liveStreams = ref.watch(videoViewModelProvider).liveStreams ?? [];
var liveCourseIds = liveStreams.map((stream) => stream.courseID).toSet();
List<Course> liveCourses = courses.where((course) => liveCourseIds.contains(course.id)).toList();
return ConstrainedBox(
constraints: BoxConstraints(maxHeight: isTablet ? 600 : 400),
child: ListView.builder(
Expand All @@ -53,7 +57,7 @@ class CoursesList extends ConsumerWidget {
title: course.name,
tumID: course.tUMOnlineIdentifier,
path: 'assets/images/course2.png',
live: course.streams.any((stream) => stream.liveNow),
live: liveCourses.contains(course),
courseId: course.id,
semester:
course.semester.teachingTerm + course.semester.year.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class PinnedCoursesState extends ConsumerState<PinnedCourses> {
@override
Widget build(BuildContext context) {
final userPinned = ref.watch(userViewModelProvider).displayedCourses ?? [];
final liveStreams = ref.watch(videoViewModelProvider).liveStreams ?? [];
var liveCourseIds = liveStreams.map((stream) => stream.courseID).toSet();
List<Course> liveCourses = userPinned.where((course) => liveCourseIds.contains(course.id)).toList();
final filterOptions =
ref.watch(userViewModelProvider).semestersAsString ?? [];
return Scaffold(
Expand All @@ -85,6 +88,7 @@ class PinnedCoursesState extends ConsumerState<PinnedCourses> {
final isPinned =
userPinned.any((pinnedCourse) => pinnedCourse.id == course.id);
return CourseCard(
live: liveCourses.contains(course),
isCourse: true,
title: course.name,
courseId: course.id,
Expand All @@ -110,15 +114,15 @@ class PinnedCoursesState extends ConsumerState<PinnedCourses> {
);
}

Future<void> _togglePin(Course course, bool isPinned) async {
/*Future<void> _togglePin(Course course, bool isPinned) async {
final viewModel = ref.read(userViewModelProvider.notifier);
if (isPinned) {
await viewModel.unpinCourse(course.id);
} else {
await viewModel.pinCourse(course.id);
}
await _refreshPinnedCourses();
}
}*/

VideoSourceType determineSourceType(String videoSource) {
return videoSource.startsWith('http')
Expand Down

0 comments on commit 3a08b2c

Please sign in to comment.