fix: preserve userid when switching to template viewmodels

This commit is contained in:
Freek van de Ven 2024-07-18 16:35:50 +02:00 committed by FlutterJoey
parent c7c985be00
commit 498e51cfc0
2 changed files with 16 additions and 2 deletions

View file

@ -7,6 +7,7 @@ class DayTemplateViewModel {
const DayTemplateViewModel({ const DayTemplateViewModel({
this.data = const DayTemplateDataViewModel(), this.data = const DayTemplateDataViewModel(),
this.id, this.id,
this.userId,
this.name, this.name,
this.color, this.color,
}); });
@ -18,6 +19,7 @@ class DayTemplateViewModel {
var data = template.templateData as DayTemplateData; var data = template.templateData as DayTemplateData;
return DayTemplateViewModel( return DayTemplateViewModel(
id: template.id, id: template.id,
userId: template.userId,
name: template.name, name: template.name,
color: template.color, color: template.color,
data: DayTemplateDataViewModel.fromDayTemplateData(data), data: DayTemplateDataViewModel.fromDayTemplateData(data),
@ -27,6 +29,9 @@ class DayTemplateViewModel {
/// The identifier for this template /// The identifier for this template
final String? id; final String? id;
/// The user id for which the template is created
final String? userId;
/// The name by which the template can be visually identified /// The name by which the template can be visually identified
final String? name; final String? name;
@ -46,7 +51,7 @@ class DayTemplateViewModel {
/// Convert to [AvailabilityTemplateModel] for saving /// Convert to [AvailabilityTemplateModel] for saving
AvailabilityTemplateModel toTemplate() => AvailabilityTemplateModel( AvailabilityTemplateModel toTemplate() => AvailabilityTemplateModel(
id: id, id: id,
userId: "", userId: userId ?? "",
name: name!, name: name!,
color: color!, color: color!,
templateType: AvailabilityTemplateType.day, templateType: AvailabilityTemplateType.day,
@ -56,12 +61,14 @@ class DayTemplateViewModel {
/// Create a copy with new values /// Create a copy with new values
DayTemplateViewModel copyWith({ DayTemplateViewModel copyWith({
String? id, String? id,
String? userId,
String? name, String? name,
int? color, int? color,
DayTemplateDataViewModel? data, DayTemplateDataViewModel? data,
}) => }) =>
DayTemplateViewModel( DayTemplateViewModel(
id: id ?? this.id, id: id ?? this.id,
userId: userId ?? this.userId,
name: name ?? this.name, name: name ?? this.name,
color: color ?? this.color, color: color ?? this.color,
data: data ?? this.data, data: data ?? this.data,

View file

@ -6,6 +6,7 @@ class WeekTemplateViewModel {
/// Constructor /// Constructor
const WeekTemplateViewModel({ const WeekTemplateViewModel({
this.data = const {}, this.data = const {},
this.userId,
this.id, this.id,
this.name, this.name,
this.color, this.color,
@ -18,6 +19,7 @@ class WeekTemplateViewModel {
var data = template.templateData as WeekTemplateData; var data = template.templateData as WeekTemplateData;
return WeekTemplateViewModel( return WeekTemplateViewModel(
id: template.id, id: template.id,
userId: template.userId,
name: template.name, name: template.name,
color: template.color, color: template.color,
data: { data: {
@ -34,6 +36,9 @@ class WeekTemplateViewModel {
/// The identifier for this template /// The identifier for this template
final String? id; final String? id;
/// The user id for which the template is created
final String? userId;
/// The name by which the template can be visually identified /// The name by which the template can be visually identified
final String? name; final String? name;
@ -55,7 +60,7 @@ class WeekTemplateViewModel {
/// Convert to [AvailabilityTemplateModel] for saving /// Convert to [AvailabilityTemplateModel] for saving
AvailabilityTemplateModel toTemplate() => AvailabilityTemplateModel( AvailabilityTemplateModel toTemplate() => AvailabilityTemplateModel(
id: id, id: id,
userId: "", userId: userId ?? "",
name: name!, name: name!,
color: color!, color: color!,
templateType: AvailabilityTemplateType.week, templateType: AvailabilityTemplateType.week,
@ -70,12 +75,14 @@ class WeekTemplateViewModel {
/// Create a copy with new values /// Create a copy with new values
WeekTemplateViewModel copyWith({ WeekTemplateViewModel copyWith({
String? id, String? id,
String? userId,
String? name, String? name,
int? color, int? color,
Map<WeekDay, DayTemplateDataViewModel>? data, Map<WeekDay, DayTemplateDataViewModel>? data,
}) => }) =>
WeekTemplateViewModel( WeekTemplateViewModel(
id: id ?? this.id, id: id ?? this.id,
userId: userId ?? this.userId,
name: name ?? this.name, name: name ?? this.name,
color: color ?? this.color, color: color ?? this.color,
data: data ?? this.data, data: data ?? this.data,