From c92e73328dfadcc08777ddc6763a2a489c34f961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Aritz?= Date: Wed, 8 Mar 2023 21:39:19 +0100 Subject: [PATCH] Prevent zero-length metadata to be created This isn't the most idiomatic way, but I'll change it in another moment. --- src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9615c3e..68a42fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -235,6 +235,17 @@ impl eframe::App for App { ui.add_space(10.0); 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 { id: SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) @@ -244,7 +255,7 @@ impl eframe::App for App { title: self.title_buffer.clone(), metadata: NoteMetadata { date: SystemTime::now(), - arbitrary: self.metadata_buffer.clone(), + arbitrary: metadata, }, text: self.text_buffer.clone(), };