Skip to content

Commit

Permalink
fix: missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Grizelj committed Sep 4, 2024
1 parent a456f02 commit dbcdc2d
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/gui/preset/history.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use crate::{cli::Arguments, db, json::Preset};

use chrono::DateTime;
use dioxus::prelude::*;

#[component]
pub fn history() -> Element {
let mut preset_state = use_context::<Signal<Preset>>();
let mut args_state = use_context::<Signal<Arguments>>();

let history = db::history().ok()?;

let history_mapped: Vec<_> = history
.iter()
.map(|history| {
let preset: Preset = serde_json::from_str(&history.preset).unwrap();
let timestamp = DateTime::from_timestamp(history.created_at, 0)
.expect("invalid timestamt")
.naive_local();

(
history.created_at,
timestamp,
preset.randomizer.seed,
preset,
)
})
.collect();

rsx! {
div {
class: "tooltip",
span {
class: "tooltiptext",
"Show previous randomizations"
},
label {
r#for: "history",
class: "file-upload",
"History"
},
input {
r#type: "button",
id: "history",
onclick: |_| {
eval("document.getElementById(\"history_dialog\").showModal();");
}
}
},
dialog {
id: "history_dialog",
div {
class: "center",
table {
tr {
th { "Timestamp" },
th { "Seed" },
}
for entry in history_mapped {
tr {
onclick: move |_| {
eval(format!("document.getElementById(\"history_dialog\").close();").as_str());
preset_state.set(entry.3.clone());
args_state.write().seed = Some(entry.2);
},
td {
"{entry.1}"
},
td {
"{entry.2}"
}
}
}
}
}
}
}
}

0 comments on commit dbcdc2d

Please sign in to comment.