init commit, ui functional

This commit is contained in:
Phani Pavan K
2025-08-25 09:31:17 +05:30
parent f4bdff959e
commit d9b9925d0b
8 changed files with 1479 additions and 0 deletions

38
src/app/settings.rs Normal file
View File

@@ -0,0 +1,38 @@
use crate::app::entry::Entry;
use serde::{Deserialize, Serialize};
use std::fmt::Display;
#[derive(Debug, Serialize, Deserialize)]
pub struct Settings {
pub entries: Vec<Entry>,
}
impl Display for Settings {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Total Entries: {}", self.entries.len())
}
}
impl Settings {
pub fn new(config: &String) -> Self {
let data = std::fs::read_to_string(config);
match data {
Ok(data) => {
let settings =
serde_json::from_str::<Settings>(&data).expect("Settings file corrupted");
settings
}
Err(_) => {
let newSet = Settings { entries: vec![] };
let payload = serde_json::to_string_pretty(&newSet).unwrap();
std::fs::write(config, payload);
newSet
}
}
}
pub fn save(&self, config: &String) {
let payload = serde_json::to_string(self).unwrap();
std::fs::write(config, payload);
}
}