Skip to content

Commit

Permalink
use enum for section kind
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainaamr committed Jan 28, 2024
1 parent df404b1 commit f6f27fd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 49 deletions.
1 change: 1 addition & 0 deletions lib/utils/section_kind.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum SectionKind { livestreams, myCourses, publicCourses }
18 changes: 11 additions & 7 deletions lib/views/course_view/components/course_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pb.dart';
import 'package:gocast_mobile/providers.dart';
import 'package:gocast_mobile/utils/constants.dart';
import 'package:gocast_mobile/utils/section_kind.dart';
import 'package:gocast_mobile/views/components/view_all_button.dart';
import 'package:gocast_mobile/views/course_view/components/course_card.dart';
import 'package:gocast_mobile/views/course_view/components/pulse_background.dart';
Expand All @@ -28,7 +29,7 @@ import 'package:gocast_mobile/views/video_view/video_player.dart';
/// different titles, courses and onViewAll actions.
class CourseSection extends StatelessWidget {
final String sectionTitle;
final int
final SectionKind
sectionKind; //0 for livestreams, 1 cor mycourses, 2 for puliccourses
final List<Course> courses;
final List<Stream> streams;
Expand Down Expand Up @@ -69,7 +70,7 @@ class CourseSection extends StatelessWidget {
required WidgetRef ref,
required BuildContext context,
required String title,
required int sectionKind,
required SectionKind sectionKind,
VoidCallback? onViewAll,
required List<Course> courses,
required List<Stream> streams,
Expand All @@ -94,24 +95,27 @@ class CourseSection extends StatelessWidget {
VoidCallback? onViewAll,
required List<Course> courses,
required List<Stream> streams,
required int sectionKind,
required SectionKind sectionKind,
}) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
sectionKind == 0
sectionKind == SectionKind.livestreams
? const PulsingBackground()
: _buildSectionTitle(
context,
title,
sectionKind == 1 ? Icons.school : Icons.public,
sectionKind == SectionKind.myCourses
? Icons.school
: Icons.public,
onViewAll,
),
if (sectionKind == 1 || sectionKind == 2)
if (sectionKind == SectionKind.myCourses ||
sectionKind == SectionKind.publicCourses)
_buildCourseList(context)
else if (sectionKind == 0)
else if (sectionKind == SectionKind.livestreams)
_buildStreamList(context),
],
),
Expand Down
14 changes: 8 additions & 6 deletions lib/views/course_view/courses_overview.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/providers.dart';
import 'package:gocast_mobile/utils/section_kind.dart';
import 'package:gocast_mobile/views/components/base_view.dart';
import 'package:gocast_mobile/views/course_view/components/course_section.dart';
import 'package:gocast_mobile/views/course_view/list_courses_view/my_courses_view.dart';
Expand Down Expand Up @@ -65,7 +66,7 @@ class CourseOverviewState extends ConsumerState<CourseOverview> {
Center(
child: _buildSection(
"Live Now",
0,
SectionKind.livestreams,
(userCourses ?? []) + (publicCourses ?? []),
liveStreams,
),
Expand All @@ -77,15 +78,15 @@ class CourseOverviewState extends ConsumerState<CourseOverview> {
Expanded(
child: _buildSection(
"My Courses",
1,
SectionKind.myCourses,
userCourses,
liveStreams,
),
),
Expanded(
child: _buildSection(
"Public Courses",
2,
SectionKind.publicCourses,
publicCourses,
liveStreams,
),
Expand All @@ -95,13 +96,13 @@ class CourseOverviewState extends ConsumerState<CourseOverview> {
else ...[
_buildSection(
"My Courses",
1,
SectionKind.myCourses,
userCourses,
liveStreams,
),
_buildSection(
"Public Courses",
2,
SectionKind.publicCourses,
publicCourses,
liveStreams,
),
Expand All @@ -113,7 +114,8 @@ class CourseOverviewState extends ConsumerState<CourseOverview> {
);
}

Widget _buildSection(String title, int sectionKind, courses, streams) {
Widget _buildSection(
String title, SectionKind sectionKind, courses, streams) {
return CourseSection(
ref: ref,
sectionTitle: title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PublicCoursesState extends ConsumerState<PublicCourses> {
final userViewModelNotifier = ref.read(userViewModelProvider.notifier);
Future.microtask(() async {
await userViewModelNotifier.fetchPublicCourses();
await userViewModelNotifier.fetchSemesters();
});
}

Expand Down
36 changes: 0 additions & 36 deletions lib/views/course_view/pinned_courses_view/pinned_card.dart

This file was deleted.

0 comments on commit f6f27fd

Please sign in to comment.