TF-2638 Change logic of storing value for VacationPresentation
This commit is contained in:
committed by
Dat H. Pham
parent
1160338147
commit
c118affbcf
+18
-16
@@ -1,4 +1,6 @@
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
|
||||
@@ -6,7 +8,7 @@ import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/datetime_extension.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_responder_status.dart';
|
||||
|
||||
class VacationPresentation with EquatableMixin {
|
||||
class VacationPresentation with EquatableMixin, OptionParamMixin {
|
||||
final VacationResponderStatus status;
|
||||
final DateTime? startDate;
|
||||
final TimeOfDay? startTime;
|
||||
@@ -33,26 +35,26 @@ class VacationPresentation with EquatableMixin {
|
||||
return VacationPresentation();
|
||||
}
|
||||
|
||||
VacationPresentation copyWidth({
|
||||
VacationPresentation copyWith({
|
||||
VacationResponderStatus? status,
|
||||
DateTime? startDate,
|
||||
TimeOfDay? startTime,
|
||||
DateTime? endDate,
|
||||
TimeOfDay? endTime,
|
||||
String? messagePlainText,
|
||||
String? messageHtmlText,
|
||||
String? subject,
|
||||
Option<DateTime>? startDateOption,
|
||||
Option<TimeOfDay>? startTimeOption,
|
||||
Option<DateTime>? endDateOption,
|
||||
Option<TimeOfDay>? endTimeOption,
|
||||
Option<String>? messagePlainTextOption,
|
||||
Option<String>? messageHtmlTextOption,
|
||||
Option<String>? subjectOption,
|
||||
bool? vacationStopEnabled,
|
||||
}) {
|
||||
return VacationPresentation(
|
||||
status: status ?? this.status,
|
||||
startDate: startDate ?? this.startDate,
|
||||
startTime: startTime ?? this.startTime,
|
||||
endDate: endDate ?? this.endDate,
|
||||
endTime: endTime ?? this.endTime,
|
||||
messagePlainText: messagePlainText ?? this.messagePlainText,
|
||||
messageHtmlText: messageHtmlText ?? this.messageHtmlText,
|
||||
subject: subject ?? this.subject,
|
||||
startDate: getOptionParam(startDateOption, startDate),
|
||||
startTime: getOptionParam(startTimeOption, startTime),
|
||||
endDate: getOptionParam(endDateOption, endDate),
|
||||
endTime: getOptionParam(endTimeOption, endTime),
|
||||
messagePlainText: getOptionParam(messagePlainTextOption, messagePlainText),
|
||||
messageHtmlText: getOptionParam(messageHtmlTextOption, messageHtmlText),
|
||||
subject: getOptionParam(subjectOption, subject),
|
||||
vacationStopEnabled: vacationStopEnabled ?? this.vacationStopEnabled
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
|
||||
@@ -129,24 +130,25 @@ class VacationController extends BaseController {
|
||||
|
||||
void updateVacationPresentation({
|
||||
VacationResponderStatus? newStatus,
|
||||
DateTime? startDate,
|
||||
TimeOfDay? startTime,
|
||||
DateTime? endDate,
|
||||
TimeOfDay? endTime,
|
||||
Option<DateTime>? startDateOption,
|
||||
Option<TimeOfDay>? startTimeOption,
|
||||
Option<DateTime>? endDateOption,
|
||||
Option<TimeOfDay>? endTimeOption,
|
||||
bool? vacationStopEnabled,
|
||||
String? messagePlainText,
|
||||
String? messageHtmlText,
|
||||
Option<String>? messagePlainTextOption,
|
||||
Option<String>? messageHtmlTextOption,
|
||||
}) {
|
||||
final currentVacation = vacationPresentation.value;
|
||||
final newVacation = currentVacation.copyWidth(
|
||||
final stopEnabled = vacationStopEnabled ?? currentVacation.vacationStopEnabled;
|
||||
final newVacation = currentVacation.copyWith(
|
||||
status: newStatus,
|
||||
startDate: startDate,
|
||||
startTime: startTime,
|
||||
endDate: endDate,
|
||||
endTime: endTime,
|
||||
startDateOption: startDateOption,
|
||||
startTimeOption: startTimeOption,
|
||||
endDateOption: stopEnabled ? endDateOption : const None(),
|
||||
endTimeOption: stopEnabled ? endTimeOption : const None(),
|
||||
vacationStopEnabled: vacationStopEnabled,
|
||||
messagePlainText: messagePlainText,
|
||||
messageHtmlText: messageHtmlText
|
||||
messagePlainTextOption: messagePlainTextOption,
|
||||
messageHtmlTextOption: messageHtmlTextOption
|
||||
);
|
||||
log('VacationController::updateVacationPresentation():newVacation: $newVacation');
|
||||
vacationPresentation.value = newVacation;
|
||||
@@ -187,9 +189,9 @@ class VacationController extends BaseController {
|
||||
}
|
||||
|
||||
if (dateType == DateType.start) {
|
||||
updateVacationPresentation(startDate: datePicked);
|
||||
updateVacationPresentation(startDateOption: Some(datePicked));
|
||||
} else {
|
||||
updateVacationPresentation(endDate: datePicked);
|
||||
updateVacationPresentation(endDateOption: Some(datePicked));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,9 +223,9 @@ class VacationController extends BaseController {
|
||||
}
|
||||
|
||||
if (dateType == DateType.start) {
|
||||
updateVacationPresentation(startTime: timePicked);
|
||||
updateVacationPresentation(startTimeOption: Some(timePicked));
|
||||
} else {
|
||||
updateVacationPresentation(endTime: timePicked);
|
||||
updateVacationPresentation(endTimeOption: Some(timePicked));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,9 +283,9 @@ class VacationController extends BaseController {
|
||||
|
||||
final subjectVacation = subjectTextController.text;
|
||||
|
||||
final newVacationPresentation = vacationPresentation.value.copyWidth(
|
||||
messageHtmlText: messageHtmlText,
|
||||
subject: subjectVacation
|
||||
final newVacationPresentation = vacationPresentation.value.copyWith(
|
||||
messageHtmlTextOption: Some(messageHtmlText),
|
||||
subjectOption: Some(subjectVacation)
|
||||
);
|
||||
log('VacationController::saveVacation(): newVacationPresentation: $newVacationPresentation');
|
||||
final newVacationResponse = newVacationPresentation.toVacationResponse();
|
||||
|
||||
Reference in New Issue
Block a user