forked from janek/mostr
refactor: reformat
This commit is contained in:
parent
1ea34898d1
commit
9a2f3f8794
|
@ -1 +1,4 @@
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
*.html
|
||||||
|
/src/bin
|
||||||
|
|
|
@ -215,7 +215,8 @@ async fn repl() {
|
||||||
tasks.update_state("", |t| if t.pure_state() == State::Active { Some(State::Open) } else { None });
|
tasks.update_state("", |t| if t.pure_state() == State::Active { Some(State::Open) } else { None });
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
println!("Submitting created events");
|
println!("Submitting events");
|
||||||
|
// TODO send via message passing
|
||||||
let _ = CLIENT
|
let _ = CLIENT
|
||||||
.batch_event(
|
.batch_event(
|
||||||
tasks
|
tasks
|
||||||
|
|
22
src/task.rs
22
src/task.rs
|
@ -1,6 +1,6 @@
|
||||||
use std::fmt;
|
|
||||||
use nostr_sdk::{Event, EventId, Kind, Tag, Timestamp};
|
|
||||||
use crate::make_event;
|
use crate::make_event;
|
||||||
|
use nostr_sdk::{Event, EventId, Kind, Tag, Timestamp};
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
pub(crate) struct Task {
|
pub(crate) struct Task {
|
||||||
pub(crate) event: Event,
|
pub(crate) event: Event,
|
||||||
|
@ -45,15 +45,15 @@ impl Task {
|
||||||
1633 => Some(State::Active),
|
1633 => Some(State::Active),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
.map(|s| TaskState {
|
.map(|s| TaskState {
|
||||||
name: if event.content.is_empty() {
|
name: if event.content.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(event.content.clone())
|
Some(event.content.clone())
|
||||||
},
|
},
|
||||||
state: s,
|
state: s,
|
||||||
time: event.created_at.clone(),
|
time: event.created_at.clone(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
37
src/tasks.rs
37
src/tasks.rs
|
@ -1,8 +1,10 @@
|
||||||
use crate::{make_event, make_task};
|
|
||||||
use crate::task::{Task, State};
|
|
||||||
use nostr_sdk::{Event, EventId, Tag};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use nostr_sdk::{Event, EventId, Tag};
|
||||||
|
|
||||||
|
use crate::make_task;
|
||||||
|
use crate::task::{State, Task};
|
||||||
|
|
||||||
type TaskMap = HashMap<EventId, Task>;
|
type TaskMap = HashMap<EventId, Task>;
|
||||||
pub(crate) struct Tasks {
|
pub(crate) struct Tasks {
|
||||||
/// The Tasks
|
/// The Tasks
|
||||||
|
@ -30,34 +32,39 @@ impl Tasks {
|
||||||
pub(crate) fn get_position(&self) -> Option<EventId> {
|
pub(crate) fn get_position(&self) -> Option<EventId> {
|
||||||
self.position
|
self.position
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_tasks(&self, tasks: &Vec<EventId>) -> Vec<&Task> {
|
fn collect_tasks(&self, tasks: &Vec<EventId>) -> Vec<&Task> {
|
||||||
tasks.iter().filter_map(|id| self.tasks.get(id)).collect()
|
tasks.iter().filter_map(|id| self.tasks.get(id)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Total time this task and its subtasks have been active
|
/// Total time this task and its subtasks have been active
|
||||||
fn total_time_tracked(&self, task: &EventId) -> u64 {
|
fn total_time_tracked(&self, task: &EventId) -> u64 {
|
||||||
self.tasks.get(task).map_or(0, |t| {
|
self.tasks.get(task).map_or(0, |t| {
|
||||||
t.time_tracked() + t.children.iter().map(|e| self.total_time_tracked(e)).sum::<u64>()
|
t.time_tracked()
|
||||||
|
+ t.children
|
||||||
|
.iter()
|
||||||
|
.map(|e| self.total_time_tracked(e))
|
||||||
|
.sum::<u64>()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_filter(&mut self, view: Vec<EventId>) {
|
pub(crate) fn set_filter(&mut self, view: Vec<EventId>) {
|
||||||
self.view = view
|
self.view = view
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn current_tasks(&self) -> Vec<&Task> {
|
pub(crate) fn current_tasks(&self) -> Vec<&Task> {
|
||||||
let res = self.collect_tasks(&self.view);
|
let res = self.collect_tasks(&self.view);
|
||||||
if res.len() > 0 {
|
if res.len() > 0 {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
self.position.map_or_else(
|
self.position.map_or_else(
|
||||||
|| self.tasks.values().collect(),
|
|| self.tasks.values().collect(),
|
||||||
|p| {
|
|p| {
|
||||||
self.tasks.get(&p).map_or(Vec::new(), |t| {
|
self.tasks
|
||||||
self.collect_tasks(&t.children)
|
.get(&p)
|
||||||
})
|
.map_or(Vec::new(), |t| self.collect_tasks(&t.children))
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn print_current_tasks(&self) {
|
pub(crate) fn print_current_tasks(&self) {
|
||||||
|
@ -78,7 +85,7 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn make_task(&self, input: &str) -> Event {
|
pub(crate) fn make_task(&self, input: &str) -> Event {
|
||||||
let mut tags: Vec<Tag> = Vec::new();
|
let mut tags: Vec<Tag> = Vec::new();
|
||||||
self.position.inspect(|p| tags.push(Tag::event(*p)));
|
self.position.inspect(|p| tags.push(Tag::event(*p)));
|
||||||
|
|
Loading…
Reference in New Issue