Prevent zero-length metadata to be created

This isn't the most idiomatic way, but I'll change it in another moment.
This commit is contained in:
Sofía Aritz 2023-03-08 21:39:19 +01:00
parent 0e2d79fc72
commit c92e73328d

View file

@ -235,6 +235,17 @@ impl eframe::App for App {
ui.add_space(10.0); ui.add_space(10.0);
if ui.button("add note").clicked() { if ui.button("add note").clicked() {
// FIXME(sofia@git.sofiaritz.com): Use a more idiomatic way
let metadata = if let Some(metadata) = self.metadata_buffer.clone() {
if metadata.is_empty() {
None
} else {
Some(metadata)
}
} else {
None
};
let note = Note::Decrypted { let note = Note::Decrypted {
id: SystemTime::now() id: SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH) .duration_since(SystemTime::UNIX_EPOCH)
@ -244,7 +255,7 @@ impl eframe::App for App {
title: self.title_buffer.clone(), title: self.title_buffer.clone(),
metadata: NoteMetadata { metadata: NoteMetadata {
date: SystemTime::now(), date: SystemTime::now(),
arbitrary: self.metadata_buffer.clone(), arbitrary: metadata,
}, },
text: self.text_buffer.clone(), text: self.text_buffer.clone(),
}; };