actionbar: move BarAction and add execute method

We will be executing baractions in multiple places, so factor this
out.

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-07-16 12:41:45 -07:00
parent 758de6b024
commit 66c8973edf
5 changed files with 37 additions and 19 deletions

30
src/actionbar.rs Normal file
View File

@@ -0,0 +1,30 @@
use crate::{route::Route, Damus};
use enostr::NoteId;
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum BarAction {
Reply,
OpenThread,
}
impl BarAction {
pub fn execute(self, app: &mut Damus, timeline: usize, replying_to: &[u8; 32]) {
match self {
BarAction::Reply => {
let timeline = &mut app.timelines[timeline];
timeline
.routes
.push(Route::Reply(NoteId::new(replying_to.to_owned())));
timeline.navigating = true;
}
BarAction::OpenThread => {
let timeline = &mut app.timelines[timeline];
timeline
.routes
.push(Route::Thread(NoteId::new(replying_to.to_owned())));
timeline.navigating = true;
}
}
}
}