Skip to content

Commit

Permalink
optional color field
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed May 18, 2024
1 parent f143a20 commit 0cc78b8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -587,7 +597,8 @@ struct Paper {
time: DateTime<chrono::Local>,
name: String,
email: Option<String>,
color: String,
#[serde(default)]
color: Option<String>,

#[serde(default)]
processed: Option<bool>,
Expand Down

0 comments on commit 0cc78b8

Please sign in to comment.