feat: add create section
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
0406fbe14d
commit
105ab41f19
@ -251,7 +251,7 @@ impl CreateItemState {
|
|||||||
|
|
||||||
if !title.is_empty() {
|
if !title.is_empty() {
|
||||||
let mut path = self.path.clone();
|
let mut path = self.path.clone();
|
||||||
path.push(title.replace(' ', "").replace('.', "-"));
|
path.push(title.replace([' ', '.'], "-"));
|
||||||
|
|
||||||
Some(hyperlog_core::commander::Command::CreateItem {
|
Some(hyperlog_core::commander::Command::CreateItem {
|
||||||
root: self.root.clone(),
|
root: self.root.clone(),
|
||||||
@ -270,18 +270,6 @@ impl CreateItemState {
|
|||||||
pub struct CreateItem {}
|
pub struct CreateItem {}
|
||||||
|
|
||||||
impl StatefulWidget for &mut CreateItem {
|
impl StatefulWidget for &mut CreateItem {
|
||||||
// fn render(self, area: Rect, buf: &mut Buffer)
|
|
||||||
// where
|
|
||||||
// Self: Sized,
|
|
||||||
// {
|
|
||||||
// //buf.reset();
|
|
||||||
|
|
||||||
// // let block = Block::bordered()
|
|
||||||
// // .title("create item")
|
|
||||||
// // .padding(Padding::proportional(1));
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
type State = CreateItemState;
|
type State = CreateItemState;
|
||||||
|
|
||||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||||
@ -306,9 +294,5 @@ impl StatefulWidget for &mut CreateItem {
|
|||||||
|
|
||||||
title_input.render(chunks[1], buf, &mut state.title);
|
title_input.render(chunks[1], buf, &mut state.title);
|
||||||
description_input.render(chunks[2], buf, &mut state.description);
|
description_input.render(chunks[2], buf, &mut state.description);
|
||||||
|
|
||||||
// let title = Paragraph::new("something"); //.block(block);
|
|
||||||
|
|
||||||
// title.render(area, buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ pub enum Commands {
|
|||||||
Quit,
|
Quit,
|
||||||
WriteQuit,
|
WriteQuit,
|
||||||
Archive,
|
Archive,
|
||||||
|
CreateSection { name: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Commands {
|
impl Commands {
|
||||||
@ -26,11 +27,14 @@ impl CommandParser {
|
|||||||
let parts = prepared.split_whitespace().collect_vec();
|
let parts = prepared.split_whitespace().collect_vec();
|
||||||
|
|
||||||
match parts.split_first() {
|
match parts.split_first() {
|
||||||
Some((command, _)) => match *command {
|
Some((command, rest)) => match *command {
|
||||||
"w" | "write" => Some(Commands::Write),
|
"w" | "write" => Some(Commands::Write),
|
||||||
"q" | "quit" => Some(Commands::Quit),
|
"q" | "quit" => Some(Commands::Quit),
|
||||||
"wq" | "write-quit" => Some(Commands::WriteQuit),
|
"wq" | "write-quit" => Some(Commands::WriteQuit),
|
||||||
"a" | "archive" => Some(Commands::Archive),
|
"a" | "archive" => Some(Commands::Archive),
|
||||||
|
"cs" | "create-section" => rest.first().map(|name| Commands::CreateSection {
|
||||||
|
name: name.to_string(),
|
||||||
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
None => None,
|
None => None,
|
||||||
|
@ -36,6 +36,8 @@ impl<'a> GraphExplorer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_graph(&mut self) -> Result<&mut Self> {
|
pub fn update_graph(&mut self) -> Result<&mut Self> {
|
||||||
|
let now = std::time::SystemTime::now();
|
||||||
|
|
||||||
let graph = self
|
let graph = self
|
||||||
.state
|
.state
|
||||||
.querier
|
.querier
|
||||||
@ -50,6 +52,9 @@ impl<'a> GraphExplorer<'a> {
|
|||||||
|
|
||||||
self.inner.graph = Some(graph);
|
self.inner.graph = Some(graph);
|
||||||
|
|
||||||
|
let elapsed = now.elapsed()?;
|
||||||
|
tracing::trace!("Graph.update_graph took: {}nanos", elapsed.as_nanos());
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,10 +146,26 @@ impl<'a> GraphExplorer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute_command(&mut self, command: &Commands) -> anyhow::Result<()> {
|
pub fn execute_command(&mut self, command: &Commands) -> anyhow::Result<()> {
|
||||||
if let Commands::Archive = command {
|
match command {
|
||||||
if !self.get_current_path().is_empty() {
|
Commands::Archive => {
|
||||||
tracing::debug!("archiving path: {:?}", self.get_current_path())
|
if !self.get_current_path().is_empty() {
|
||||||
|
tracing::debug!("archiving path: {:?}", self.get_current_path())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Commands::CreateSection { name } => {
|
||||||
|
if !name.is_empty() {
|
||||||
|
let mut path = self.get_current_path();
|
||||||
|
path.push(name.replace(" ", "-").replace(".", "-"));
|
||||||
|
|
||||||
|
self.state.commander.execute(
|
||||||
|
hyperlog_core::commander::Command::CreateSection {
|
||||||
|
root: self.inner.root.clone(),
|
||||||
|
path,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_graph()?;
|
self.update_graph()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user