feat: tie dialog to graph

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-05-09 14:10:43 +02:00
parent 7cead58ed3
commit 547d34782c
5 changed files with 143 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
use itertools::Itertools;
use ratatui::{prelude::*, widgets::*};
use crate::models::{EditMsg, Msg};
@@ -204,8 +205,10 @@ impl Default for CreateItemFocused {
}
}
#[derive(Default)]
pub struct CreateItemState {
root: String,
path: Vec<String>,
title: InputBuffer,
description: InputBuffer,
@@ -213,6 +216,20 @@ pub struct CreateItemState {
}
impl CreateItemState {
pub fn new(root: impl Into<String>, path: impl IntoIterator<Item = impl Into<String>>) -> Self {
let root = root.into();
let path = path.into_iter().map(|p| p.into()).collect_vec();
Self {
root,
path,
title: Default::default(),
description: Default::default(),
focused: Default::default(),
}
}
pub fn update(&mut self, msg: &Msg) -> anyhow::Result<()> {
match &msg {
Msg::MoveDown | Msg::MoveUp => match self.focused {
@@ -233,6 +250,26 @@ impl CreateItemState {
Ok(())
}
pub fn get_command(&self) -> Option<hyperlog_core::commander::Command> {
let title = self.title.string();
let description = self.description.string();
if !title.is_empty() {
let mut path = self.path.clone();
path.push(title.replace(' ', "").replace('.', "-"));
Some(hyperlog_core::commander::Command::CreateItem {
root: self.root.clone(),
path,
title: title.trim().into(),
description: description.trim().into(),
state: hyperlog_core::log::ItemState::NotDone,
})
} else {
None
}
}
}
#[derive(Default)]