forked from janek/mostr
1
0
Fork 0

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,14 +486,16 @@ async fn main() -> Result<()> {
Some('*') => {
match arg {
None => match tasks.get_position_ref() {
None => match tasks.get_position() {
None => {
info!("Filtering for bookmarked tasks");
tasks.set_view_bookmarks();
}
Some(pos) => {
info!("Toggling bookmark");
or_warn!(tasks.toggle_bookmark(*pos));
Some(pos) =>
match 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"),

View File

@ -388,6 +388,7 @@ impl Tasks {
if sparse && current.is_empty() {
vec![]
} else {
// TODO highlight bookmarks
self.bookmarks.iter()
.filter(|id| !position.is_some_and(|p| &p == id) && !ids.contains(id))
.filter_map(|id| self.get_by_id(id))
@ -395,6 +396,7 @@ impl Tasks {
.collect_vec()
};
current.append(&mut bookmarks);
current
}
@ -523,14 +525,23 @@ impl Tasks {
// Movement and Selection
pub(crate) fn toggle_bookmark(&mut self, id: EventId) -> nostr_sdk::Result<Event> {
match self.bookmarks.iter().position(|b| b == &id) {
None => self.bookmarks.push(id),
Some(pos) => { self.bookmarks.remove(pos); }
/// Toggle bookmark on the given id.
/// Returns whether it was added (true) or removed (false).
pub(crate) fn toggle_bookmark(&mut self, id: EventId) -> nostr_sdk::Result<bool> {
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(
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 {