diff --git a/crates/hyperlog-tui/src/commands/update_graph.rs b/crates/hyperlog-tui/src/commands/update_graph.rs index 93074de..907b240 100644 --- a/crates/hyperlog-tui/src/commands/update_graph.rs +++ b/crates/hyperlog-tui/src/commands/update_graph.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use crate::{ - models::{GraphUpdatedEvent, Msg}, + models::{IOEvent, Msg}, querier::Querier, state::SharedState, }; @@ -22,27 +22,23 @@ impl UpdateGraphCommand { super::Command::new(|dispatch| { tokio::spawn(async move { let now = std::time::SystemTime::now(); - dispatch.send(Msg::GraphUpdated(GraphUpdatedEvent::Initiated)); + dispatch.send(Msg::GraphUpdated(IOEvent::Initialized)); match self.querier.get_async(&root, path).await { Ok(Some(graph)) => { - dispatch.send(Msg::GraphUpdated(GraphUpdatedEvent::Optimistic( - graph.clone(), - ))); + dispatch.send(Msg::GraphUpdated(IOEvent::Optimistic(graph.clone()))); #[cfg(debug_assertions)] { tokio::time::sleep(std::time::Duration::from_secs(1)).await; } - dispatch.send(Msg::GraphUpdated(GraphUpdatedEvent::Success(graph))) + dispatch.send(Msg::GraphUpdated(IOEvent::Success(graph))) } - Ok(None) => dispatch.send(Msg::GraphUpdated(GraphUpdatedEvent::Failure( + Ok(None) => dispatch.send(Msg::GraphUpdated(IOEvent::Failure( "graph was not found user root".into(), ))), - Err(e) => dispatch.send(Msg::GraphUpdated(GraphUpdatedEvent::Failure( - format!("{e}"), - ))), + Err(e) => dispatch.send(Msg::GraphUpdated(IOEvent::Failure(format!("{e}")))), } let elapsed = now.elapsed().expect("to be able to get time"); diff --git a/crates/hyperlog-tui/src/components/graph_explorer.rs b/crates/hyperlog-tui/src/components/graph_explorer.rs index a3d2087..9041f76 100644 --- a/crates/hyperlog-tui/src/components/graph_explorer.rs +++ b/crates/hyperlog-tui/src/components/graph_explorer.rs @@ -11,7 +11,7 @@ use crate::{ IntoCommand, }, components::movement_graph::GraphItemType, - models::{GraphUpdatedEvent, Msg}, + models::{IOEvent, Msg}, state::SharedState, }; @@ -58,17 +58,17 @@ impl<'a> GraphExplorerState<'a> { pub fn update(&mut self, msg: &Msg) -> Option { if let Msg::GraphUpdated(graph_update) = msg { match graph_update { - GraphUpdatedEvent::Initiated => { + IOEvent::Initialized => { tracing::trace!("initialized graph"); } - GraphUpdatedEvent::Success(graph) => { + IOEvent::Success(graph) => { tracing::trace!("graph updated successfully"); self.graph = Some(graph.clone()); } - GraphUpdatedEvent::Failure(e) => { + IOEvent::Failure(e) => { tracing::error!("graph update failed: {}", e); } - GraphUpdatedEvent::Optimistic(graph) => { + IOEvent::Optimistic(graph) => { tracing::trace!("graph updated optimistically"); self.graph = Some(graph.clone()); } diff --git a/crates/hyperlog-tui/src/models.rs b/crates/hyperlog-tui/src/models.rs index 45abcda..65f3036 100644 --- a/crates/hyperlog-tui/src/models.rs +++ b/crates/hyperlog-tui/src/models.rs @@ -21,8 +21,7 @@ pub enum Msg { Edit(EditMsg), - GraphUpdated(GraphUpdatedEvent), - + GraphUpdated(IOEvent), ItemCreated(IOEvent<()>), ItemUpdated(IOEvent<()>), SectionCreated(IOEvent<()>), @@ -37,14 +36,6 @@ pub enum IOEvent { Failure(String), } -#[derive(Debug)] -pub enum GraphUpdatedEvent { - Initiated, - Optimistic(GraphItem), - Success(GraphItem), - Failure(String), -} - impl IntoCommand for Msg { fn into_command(self) -> crate::commands::Command { Command::new(|_| Some(self))