From 0cc78b881d8d949efc5a567d26caf60199dafbdd Mon Sep 17 00:00:00 2001 From: JieningYu Date: Sat, 18 May 2024 17:02:24 +0800 Subject: [PATCH] optional color field --- src/main.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 609c477..37386ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fs::File, io::Read, sync::Arc, time::Duration}; +use std::{collections::HashMap, fs::File, io::Read, str::FromStr, sync::Arc, time::Duration}; use chrono::DateTime; @@ -446,7 +446,17 @@ impl Application for App { .selected_paper .and_then(|value| self.papers.get(&value)) { - let hex_color = HexColor::parse_rgb(&paper.color).unwrap_or_default(); + const YELLOW: HexColor = HexColor { + r: 255, + g: 255, + b: 204, + a: u8::MAX, + }; + let hex_color = paper + .color + .as_ref() + .and_then(|str| HexColor::from_str(str).ok()) + .unwrap_or(YELLOW); right = right.push( Scrollable::new({ @@ -587,7 +597,8 @@ struct Paper { time: DateTime, name: String, email: Option, - color: String, + #[serde(default)] + color: Option, #[serde(default)] processed: Option,