Skip to content

Commit

Permalink
Remove model from view
Browse files Browse the repository at this point in the history
  • Loading branch information
chababeric committed Nov 30, 2024
1 parent 25e15a7 commit e0f8594
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 2 additions & 10 deletions lib/features/dashboard/dashboard_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,7 @@ class _DashboardViewState extends State<DashboardView>
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: Builder(
builder: (context) {
final upcomingEvents = model.importantDates.asMap().entries.where((entry) {
DateTime date = entry.value;
DateTime now = DateTime.now();

return now.isAfter(date.subtract(const Duration(days: 3))) &&
now.isBefore(date.add(const Duration(days: 1)));
}).toList();

if (upcomingEvents.isEmpty) return const SizedBox.shrink();
if (model.upcomingEvents.isEmpty) return const SizedBox.shrink();
final currentLocale = AppIntl.of(context)!.localeName;

return Column(
Expand All @@ -298,7 +290,7 @@ class _DashboardViewState extends State<DashboardView>
alignment: Alignment.centerLeft,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: upcomingEvents.map((entry) {
children: model.upcomingEvents.map((entry) {
int index = entry.key;
DateTime date = entry.value;

Expand Down
13 changes: 10 additions & 3 deletions lib/features/dashboard/dashboard_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {
double _progress = 0.0;

/// Session important days
List<DateTime> _importantDates = [];
List<MapEntry<int, DateTime>> _upcomingEvents = [];

/// Numbers of days elapsed and total number of days of the current session
List<int> _sessionDays = [0, 0];
Expand All @@ -63,7 +63,7 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {

List<int> get sessionDays => _sessionDays;

List<DateTime> get importantDates => _importantDates;
List<MapEntry<int, DateTime>> get upcomingEvents => _upcomingEvents;

/// Activities for today
List<CourseActivity> _todayDateEvents = [];
Expand Down Expand Up @@ -303,9 +303,16 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {

setBusyForObject(progress, true);
final sessions = await _courseRepository.getSessions();
final List<DateTime> importantDates = [sessions[1].startDate, sessions[1].endDate, sessions[1].startDateRegistration];
_sessionDays = getSessionDays();
_progress = getSessionProgress();
_importantDates = [sessions[1].startDate, sessions[1].endDate, sessions[1].startDateRegistration];

_upcomingEvents = importantDates.asMap().entries.where((entry) {
DateTime date = entry.value;
DateTime now = DateTime.now();

return now.isAfter(date.subtract(const Duration(days: 3))) && now.isBefore(date.add(const Duration(days: 1)));
}).toList();

return sessions;
} catch (error) {
Expand Down

0 comments on commit e0f8594

Please sign in to comment.