Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1055 dashboard display reminders for session events in dashboard #1100

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,10 @@
"ticket_status_closed": "Closed",
"loading": "Loading...",

"no_schedule_available": "There are no events scheduled at the moment"
"no_schedule_available": "There are no events scheduled at the moment",

"upcoming_events": "Upcoming events",
"semester_start_date": "Semester start date",
"semester_end_date": "Semester end date",
"registration_start_date": "Registration start date"
}
7 changes: 6 additions & 1 deletion l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,10 @@
"ticket_status_closed": "Fermé",
"loading": "Chargement...",

"no_schedule_available": "Il n'y a aucun événement à l'horaire pour l'instant"
"no_schedule_available": "Il n'y a aucun événement à l'horaire pour l'instant",

"upcoming_events": "Évènements à venir",
"semester_start_date": "Début de la session",
"semester_end_date": "Fin de la session",
"registration_start_date": "Début des inscriptions"
}
50 changes: 48 additions & 2 deletions lib/features/dashboard/dashboard_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:skeletonizer/skeletonizer.dart';
import 'package:stacked/stacked.dart';
import 'package:intl/intl.dart';

// Project imports:
import 'package:notredame/constants/preferences_flags.dart';
Expand Down Expand Up @@ -201,7 +202,7 @@ class _DashboardViewState extends State<DashboardView>
);

Widget _buildProgressBarCard(
DashboardViewModel model, PreferencesFlag flag) =>
DashboardViewModel model, PreferencesFlag flag) =>
DismissibleCard(
key: UniqueKey(),
onDismissed: (DismissDirection direction) {
Expand All @@ -226,7 +227,7 @@ class _DashboardViewState extends State<DashboardView>
borderRadius: const BorderRadius.all(Radius.circular(10)),
child: GestureDetector(
onTap: () => setState(
() => setState(() {
() => setState(() {
model.changeProgressBarText();
setText(model);
}),
Expand Down Expand Up @@ -267,6 +268,51 @@ class _DashboardViewState extends State<DashboardView>
child: Text(AppIntl.of(context)!.session_without),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: Builder(
builder: (context) {
if (model.upcomingEvents.isEmpty) return const SizedBox.shrink();
final currentLocale = AppIntl.of(context)!.localeName;

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppIntl.of(context)!.upcoming_events,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Align(
alignment: Alignment.centerLeft,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: model.upcomingEvents.map((entry) {
int index = entry.key;
DateTime date = entry.value;

List<String> labels = [
AppIntl.of(context)!.semester_start_date,
AppIntl.of(context)!.semester_end_date,
AppIntl.of(context)!.registration_start_date
];

String formattedDate = DateFormat('dd MMMM yyyy', currentLocale).format(date);

return Text(
"${labels[index]}: $formattedDate",
style: const TextStyle(color: Colors.black),
);
}).toList(),
),
),
],
);
},
),
)
]),
);

Expand Down
19 changes: 19 additions & 0 deletions lib/features/dashboard/dashboard_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {
/// Percentage of completed days for the session
double _progress = 0.0;

/// Session important days
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 @@ -60,6 +63,8 @@ class DashboardViewModel extends FutureViewModel<Map<PreferencesFlag, int>> {

List<int> get sessionDays => _sessionDays;

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

/// Activities for today
List<CourseActivity> _todayDateEvents = [];

Expand Down Expand Up @@ -298,8 +303,22 @@ 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();

_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();

_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) {
onError(error);
Expand Down
Loading