Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -104,7 +104,28 @@ impl Commander {
|
||||
description,
|
||||
state,
|
||||
} => {
|
||||
todo!()
|
||||
let channel = self.channel.clone();
|
||||
|
||||
let mut client = GraphClient::new(channel);
|
||||
|
||||
let request = tonic::Request::new(UpdateItemRequest {
|
||||
root,
|
||||
path,
|
||||
item: Some(ItemGraphItem {
|
||||
title,
|
||||
description,
|
||||
item_state: Some(match state {
|
||||
hyperlog_core::log::ItemState::NotDone => {
|
||||
item_graph_item::ItemState::NotDone(ItemStateNotDone {})
|
||||
}
|
||||
hyperlog_core::log::ItemState::Done => {
|
||||
item_graph_item::ItemState::Done(ItemStateDone {})
|
||||
}
|
||||
}),
|
||||
}),
|
||||
});
|
||||
let response = client.update_item(request).await?;
|
||||
let res = response.into_inner();
|
||||
// self.engine.update_item(
|
||||
// &root,
|
||||
// &path.iter().map(|p| p.as_str()).collect::<Vec<_>>(),
|
||||
|
@@ -4,6 +4,7 @@ pub mod batch;
|
||||
|
||||
pub mod create_item;
|
||||
pub mod create_section;
|
||||
pub mod open_update_item_dialog;
|
||||
pub mod toggle_item;
|
||||
pub mod update_graph;
|
||||
pub mod update_item;
|
||||
|
61
crates/hyperlog-tui/src/commands/open_update_item_dialog.rs
Normal file
61
crates/hyperlog-tui/src/commands/open_update_item_dialog.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
models::{IOEvent, Msg},
|
||||
querier::Querier,
|
||||
state::SharedState,
|
||||
};
|
||||
|
||||
pub struct OpenUpdateItemDialogCommand {
|
||||
querier: Querier,
|
||||
}
|
||||
|
||||
impl OpenUpdateItemDialogCommand {
|
||||
pub fn new(querier: Querier) -> Self {
|
||||
Self { querier }
|
||||
}
|
||||
|
||||
pub fn command(self, root: &str, path: Vec<String>) -> super::Command {
|
||||
let root = root.to_string();
|
||||
|
||||
super::Command::new(|dispatch| {
|
||||
tokio::spawn(async move {
|
||||
dispatch.send(Msg::OpenUpdateItemDialog(IOEvent::Initialized));
|
||||
|
||||
let item = match self.querier.get_async(&root, path).await {
|
||||
Ok(item) => match item {
|
||||
Some(item) => {
|
||||
dispatch.send(Msg::OpenUpdateItemDialog(IOEvent::Success(())));
|
||||
item
|
||||
}
|
||||
None => {
|
||||
dispatch.send(Msg::OpenUpdateItemDialog(IOEvent::Failure(
|
||||
"failed to find a valid item for path".into(),
|
||||
)));
|
||||
|
||||
return;
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
dispatch.send(Msg::OpenUpdateItemDialog(IOEvent::Failure(e.to_string())));
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
dispatch.send(Msg::OpenEditItemDialog { item });
|
||||
});
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OpenUpdateItemDialogCommandExt {
|
||||
fn open_update_item_dialog_command(&self) -> OpenUpdateItemDialogCommand;
|
||||
}
|
||||
|
||||
impl OpenUpdateItemDialogCommandExt for SharedState {
|
||||
fn open_update_item_dialog_command(&self) -> OpenUpdateItemDialogCommand {
|
||||
OpenUpdateItemDialogCommand::new(self.querier.clone())
|
||||
}
|
||||
}
|
@@ -7,8 +7,8 @@ use crate::{
|
||||
command_parser::Commands,
|
||||
commands::{
|
||||
batch::BatchCommand, create_section::CreateSectionCommandExt,
|
||||
toggle_item::ToggleItemCommandExt, update_graph::UpdateGraphCommandExt, Command,
|
||||
IntoCommand,
|
||||
open_update_item_dialog::OpenUpdateItemDialogCommandExt, toggle_item::ToggleItemCommandExt,
|
||||
update_graph::UpdateGraphCommandExt, Command, IntoCommand,
|
||||
},
|
||||
components::movement_graph::GraphItemType,
|
||||
models::{IOEvent, Msg},
|
||||
@@ -272,13 +272,11 @@ impl<'a> GraphExplorer<'a> {
|
||||
todo!("cannot edit section at the moment")
|
||||
}
|
||||
GraphItemType::Item { .. } => {
|
||||
if let Some(item) = self.state.querier.get(&self.inner.root, path) {
|
||||
if let GraphItem::Item { .. } = item {
|
||||
return Ok(Some(
|
||||
Msg::OpenEditItemDialog { item }.into_command(),
|
||||
));
|
||||
}
|
||||
}
|
||||
batch.with(
|
||||
self.state
|
||||
.open_update_item_dialog_command()
|
||||
.command(&self.inner.root, path),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,8 @@ pub enum Msg {
|
||||
ItemUpdated(IOEvent<()>),
|
||||
SectionCreated(IOEvent<()>),
|
||||
ItemToggled(IOEvent<()>),
|
||||
|
||||
OpenUpdateItemDialog(IOEvent<()>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
Reference in New Issue
Block a user