@@ -126,29 +126,28 @@ impl YamlManager for NativeYamlManager {
126
126
Err ( "File save cancelled" . to_string ( ) )
127
127
}
128
128
}
129
-
130
129
fn update_yaml ( & self , yaml : & Yaml , yaml_file : & str ) -> Result < ( ) , String > {
131
130
let mut yaml_to_save = yaml. clone ( ) ;
132
-
133
- // Remove IDs before saving
131
+
132
+ // Remove IDs before saving by setting them to None
134
133
for period in & mut yaml_to_save. life_periods {
135
- period. id = Some ( Uuid :: nil ( ) ) ;
134
+ period. id = None ; // Set to None instead of nil UUID
136
135
for event in & mut period. events {
137
- event. id = Some ( Uuid :: nil ( ) ) ;
136
+ event. id = None ; // Set to None instead of nil UUID
138
137
}
139
138
}
140
-
139
+
141
140
let yaml_content = serde_yaml:: to_string ( & yaml_to_save)
142
141
. map_err ( |e| format ! ( "Failed to serialize YAML: {:?}" , e) ) ?;
143
-
142
+
144
143
let file_path = Path :: new ( & self . data_folder ) . join ( yaml_file) ;
145
144
fs:: create_dir_all ( file_path. parent ( ) . unwrap ( ) )
146
145
. map_err ( |e| format ! ( "Failed to create directory: {:?}" , e) ) ?;
147
-
146
+
148
147
fs:: write ( file_path, yaml_content)
149
148
. map_err ( |e| format ! ( "Failed to update YAML file: {:?}" , e) )
150
149
}
151
-
150
+
152
151
fn get_available_yamls ( & self ) -> Result < Vec < String > , String > {
153
152
let data_folder = Path :: new ( & self . data_folder ) ;
154
153
let yamls = fs:: read_dir ( data_folder)
@@ -264,17 +263,23 @@ impl YamlManager for WasmYamlManager {
264
263
}
265
264
266
265
fn update_yaml ( & self , yaml : & Yaml , yaml_file : & str ) -> Result < ( ) , String > {
267
- let yaml_content = serde_yaml:: to_string ( yaml)
266
+ let mut yaml_to_save = yaml. clone ( ) ;
267
+
268
+ // Remove IDs before saving
269
+ for period in & mut yaml_to_save. life_periods {
270
+ period. id = None ; // Clear period ID
271
+ for event in & mut period. events {
272
+ event. id = None ; // Clear event IDs
273
+ }
274
+ }
275
+
276
+ let yaml_content = serde_yaml:: to_string ( & yaml_to_save)
268
277
. map_err ( |e| format ! ( "Failed to serialize YAML: {:?}" , e) ) ?;
269
- let window = web_sys:: window ( ) . ok_or_else ( || "Failed to get window" . to_string ( ) ) ?;
270
- let storage = window
271
- . local_storage ( )
272
- . map_err ( |_| "Failed to get localStorage" . to_string ( ) ) ?
273
- . ok_or_else ( || "localStorage not available" . to_string ( ) ) ?;
274
-
275
- storage
276
- . set_item ( yaml_file, & yaml_content)
277
- . map_err ( |_| "Failed to set item in localStorage" . to_string ( ) )
278
+
279
+ // Save the YAML without IDs
280
+ let file_path = Path :: new ( & self . data_folder ) . join ( yaml_file) ;
281
+ fs:: write ( file_path, yaml_content)
282
+ . map_err ( |e| format ! ( "Failed to update YAML file: {:?}" , e) )
278
283
}
279
284
280
285
fn get_available_yamls ( & self ) -> Result < Vec < String > , String > {
0 commit comments