mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 13:13:44 +02:00
feat: apply template instead of creating base availabilities
This commit is contained in:
parent
c8348be746
commit
9dcb3950df
2 changed files with 26 additions and 8 deletions
|
@ -62,6 +62,20 @@ class AvailabilityService {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a set of availabilities for the given [range] by applying the
|
||||
/// [template] to each day in the range
|
||||
Future<void> applyTemplate({
|
||||
required AvailabilityTemplateModel template,
|
||||
required DateTimeRange range,
|
||||
}) async {
|
||||
await dataInterface.applyTemplateForUser(
|
||||
userId,
|
||||
template,
|
||||
range.start,
|
||||
range.end,
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a stream where data from availabilities and templates are merged
|
||||
Stream<List<AvailabilityWithTemplate>> getOverviewDataForMonth(
|
||||
DateTime dayInMonth,
|
||||
|
|
|
@ -72,16 +72,17 @@ class _AvailabilitiesModificationScreenState
|
|||
widget.onExit();
|
||||
return;
|
||||
}
|
||||
if (widget.initialAvailabilities.isNotEmpty) {
|
||||
await service.clearAvailabilities(
|
||||
widget.initialAvailabilities.getAvailabilities(),
|
||||
if (_availabilityViewModel.templateSelected) {
|
||||
await service.applyTemplate(
|
||||
template: _availabilityViewModel.templates.first,
|
||||
range: widget.dateRange,
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
await service.createAvailability(
|
||||
availability: _availabilityViewModel.toModel(),
|
||||
range: widget.dateRange,
|
||||
);
|
||||
}
|
||||
widget.onExit();
|
||||
}
|
||||
|
||||
|
@ -135,6 +136,7 @@ class _AvailabilitiesModificationScreenState
|
|||
setState(() {
|
||||
_availabilityViewModel = _availabilityViewModel.copyWith(
|
||||
startTime: start,
|
||||
templateSelected: false,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -143,6 +145,7 @@ class _AvailabilitiesModificationScreenState
|
|||
setState(() {
|
||||
_availabilityViewModel = _availabilityViewModel.copyWith(
|
||||
endTime: end,
|
||||
templateSelected: false,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -151,6 +154,7 @@ class _AvailabilitiesModificationScreenState
|
|||
setState(() {
|
||||
_availabilityViewModel = _availabilityViewModel.copyWith(
|
||||
breaks: breaks,
|
||||
templateSelected: false,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue