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
|
/// Returns a stream where data from availabilities and templates are merged
|
||||||
Stream<List<AvailabilityWithTemplate>> getOverviewDataForMonth(
|
Stream<List<AvailabilityWithTemplate>> getOverviewDataForMonth(
|
||||||
DateTime dayInMonth,
|
DateTime dayInMonth,
|
||||||
|
|
|
@ -72,16 +72,17 @@ class _AvailabilitiesModificationScreenState
|
||||||
widget.onExit();
|
widget.onExit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (widget.initialAvailabilities.isNotEmpty) {
|
if (_availabilityViewModel.templateSelected) {
|
||||||
await service.clearAvailabilities(
|
await service.applyTemplate(
|
||||||
widget.initialAvailabilities.getAvailabilities(),
|
template: _availabilityViewModel.templates.first,
|
||||||
|
range: widget.dateRange,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await service.createAvailability(
|
||||||
|
availability: _availabilityViewModel.toModel(),
|
||||||
|
range: widget.dateRange,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await service.createAvailability(
|
|
||||||
availability: _availabilityViewModel.toModel(),
|
|
||||||
range: widget.dateRange,
|
|
||||||
);
|
|
||||||
widget.onExit();
|
widget.onExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +136,7 @@ class _AvailabilitiesModificationScreenState
|
||||||
setState(() {
|
setState(() {
|
||||||
_availabilityViewModel = _availabilityViewModel.copyWith(
|
_availabilityViewModel = _availabilityViewModel.copyWith(
|
||||||
startTime: start,
|
startTime: start,
|
||||||
|
templateSelected: false,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -143,6 +145,7 @@ class _AvailabilitiesModificationScreenState
|
||||||
setState(() {
|
setState(() {
|
||||||
_availabilityViewModel = _availabilityViewModel.copyWith(
|
_availabilityViewModel = _availabilityViewModel.copyWith(
|
||||||
endTime: end,
|
endTime: end,
|
||||||
|
templateSelected: false,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -151,6 +154,7 @@ class _AvailabilitiesModificationScreenState
|
||||||
setState(() {
|
setState(() {
|
||||||
_availabilityViewModel = _availabilityViewModel.copyWith(
|
_availabilityViewModel = _availabilityViewModel.copyWith(
|
||||||
breaks: breaks,
|
breaks: breaks,
|
||||||
|
templateSelected: false,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue