Skip to content

Commit

Permalink
plans: add lastDate to the Plan entity (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
wfleischer authored Nov 20, 2024
1 parent 0733c20 commit 1be11ff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/src/plans/entities/plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class PlanNotifier extends AutoDisposeFamilyNotifier<Plan, String> {
plansNotifier?.updatePlan(state.copyWith(
bookmark: newBookmark,
startDate: _getStartDate(newBookmark),
lastDate: DateUtils.dateOnly(DateTime.now()),
targetDate: state.targetDate ?? calcTargetDate(newBookmark),
));
}
Expand Down Expand Up @@ -133,6 +134,7 @@ class Plan extends Equatable {
required this.language,
required this.bookmark,
this.startDate,
this.lastDate,
this.targetDate,
required this.withTargetDate,
required this.showEvents,
Expand All @@ -145,6 +147,7 @@ class Plan extends Equatable {
final String language;
final Bookmark bookmark;
final DateTime? startDate;
final DateTime? lastDate;
final DateTime? targetDate;
final bool withTargetDate;
final bool showEvents;
Expand All @@ -157,11 +160,13 @@ class Plan extends Equatable {
String? language,
Bookmark? bookmark,
DateTime? startDate,
DateTime? lastDate,
DateTime? targetDate,
bool? withTargetDate,
bool? showEvents,
bool? showLocations,
bool? nullStartDate,
bool? nullLastDate,
bool? nullTargetDate,
}) =>
Plan(
Expand All @@ -171,6 +176,7 @@ class Plan extends Equatable {
language: language ?? this.language,
bookmark: bookmark ?? this.bookmark,
startDate: nullStartDate == true ? null : startDate ?? this.startDate,
lastDate: nullLastDate == true ? null : lastDate ?? this.lastDate,
targetDate:
nullTargetDate == true ? null : targetDate ?? this.targetDate,
withTargetDate: withTargetDate ?? this.withTargetDate,
Expand All @@ -185,6 +191,7 @@ class Plan extends Equatable {
language,
bookmark,
startDate,
lastDate,
targetDate,
withTargetDate,
showEvents,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/plans/repositories/plans_deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class PlansDeserializer {
final startDate = planMap['startDate'] == null
? null
: DateTime.parse(planMap['startDate'] as String);
final lastDate = planMap['lastDate'] == null
? null
: DateTime.parse(planMap['lastDate'] as String);
final targetDate = planMap['targetDate'] == null
? null
: DateTime.parse(planMap['targetDate'] as String);
Expand All @@ -48,6 +51,7 @@ class PlansDeserializer {
language: language,
bookmark: bookmark,
startDate: startDate,
lastDate: lastDate,
targetDate: targetDate,
withTargetDate: withTargetDate,
showEvents: showEvents,
Expand Down
1 change: 1 addition & 0 deletions lib/src/plans/repositories/plans_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PlansSerializer {
'bookmark': _convertBookmarkToMap(plan.bookmark),
if (plan.startDate != null)
'startDate': plan.startDate!.toIso8601String(),
if (plan.lastDate != null) 'lastDate': plan.lastDate!.toIso8601String(),
if (plan.targetDate != null)
'targetDate': plan.targetDate!.toIso8601String(),
'withTargetDate': plan.withTargetDate,
Expand Down
1 change: 1 addition & 0 deletions lib/src/plans/stories/plan_edit_story.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PlanEdit extends AutoDisposeFamilyNotifier<Plan, String?> {
scheduleKey: newScheduleKey,
bookmark: Bookmark(dayIndex: newDayIndex, sectionIndex: -1),
nullStartDate: true,
nullLastDate: true,
nullTargetDate: true,
);
}
Expand Down

0 comments on commit 1be11ff

Please sign in to comment.