feat: better feedback on bookmarking

This commit is contained in:
xeruf 2024-09-07 16:25:44 +03:00
parent 593ebcddca
commit bb3bb1fd56
2 changed files with 24 additions and 11 deletions

View File

@ -486,15 +486,17 @@ async fn main() -> Result<()> {
Some('*') => { Some('*') => {
match arg { match arg {
None => match tasks.get_position_ref() { None => match tasks.get_position() {
None => { None => {
info!("Filtering for bookmarked tasks"); info!("Filtering for bookmarked tasks");
tasks.set_view_bookmarks(); tasks.set_view_bookmarks();
} }
Some(pos) => { Some(pos) =>
info!("Toggling bookmark"); match or_warn!(tasks.toggle_bookmark(pos)) {
or_warn!(tasks.toggle_bookmark(*pos)); Some(true) => info!("Bookmarking \"{}\"", tasks.get_task_title(&pos)),
} Some(false) => info!("Removing bookmark for \"{}\"", tasks.get_task_title(&pos)),
None => {}
}
}, },
Some(arg) => info!("Setting priority not yet implemented"), Some(arg) => info!("Setting priority not yet implemented"),
} }

View File

@ -388,6 +388,7 @@ impl Tasks {
if sparse && current.is_empty() { if sparse && current.is_empty() {
vec![] vec![]
} else { } else {
// TODO highlight bookmarks
self.bookmarks.iter() self.bookmarks.iter()
.filter(|id| !position.is_some_and(|p| &p == id) && !ids.contains(id)) .filter(|id| !position.is_some_and(|p| &p == id) && !ids.contains(id))
.filter_map(|id| self.get_by_id(id)) .filter_map(|id| self.get_by_id(id))
@ -395,6 +396,7 @@ impl Tasks {
.collect_vec() .collect_vec()
}; };
current.append(&mut bookmarks); current.append(&mut bookmarks);
current current
} }
@ -523,14 +525,23 @@ impl Tasks {
// Movement and Selection // Movement and Selection
pub(crate) fn toggle_bookmark(&mut self, id: EventId) -> nostr_sdk::Result<Event> { /// Toggle bookmark on the given id.
match self.bookmarks.iter().position(|b| b == &id) { /// Returns whether it was added (true) or removed (false).
None => self.bookmarks.push(id), pub(crate) fn toggle_bookmark(&mut self, id: EventId) -> nostr_sdk::Result<bool> {
Some(pos) => { self.bookmarks.remove(pos); } let added = match self.bookmarks.iter().position(|b| b == &id) {
} None => {
self.bookmarks.push(id);
true
}
Some(pos) => {
self.bookmarks.remove(pos);
false
}
};
self.sender.submit( self.sender.submit(
EventBuilder::new(Kind::Bookmarks, "mostr pins", EventBuilder::new(Kind::Bookmarks, "mostr pins",
self.bookmarks.iter().map(|id| Tag::event(*id)))) self.bookmarks.iter().map(|id| Tag::event(*id))))?;
Ok(added)
} }
pub(crate) fn set_filter_author(&mut self, key: PublicKey) -> bool { pub(crate) fn set_filter_author(&mut self, key: PublicKey) -> bool {