chore: refactor out graph created event
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
9bb5bc9e87
commit
64d59e069f
@ -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");
|
||||
|
@ -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<Command> {
|
||||
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());
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ pub enum Msg {
|
||||
|
||||
Edit(EditMsg),
|
||||
|
||||
GraphUpdated(GraphUpdatedEvent),
|
||||
|
||||
GraphUpdated(IOEvent<GraphItem>),
|
||||
ItemCreated(IOEvent<()>),
|
||||
ItemUpdated(IOEvent<()>),
|
||||
SectionCreated(IOEvent<()>),
|
||||
@ -37,14 +36,6 @@ pub enum IOEvent<T> {
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user