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:
30
src/actionbar.rs
Normal file
30
src/actionbar.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ mod error;
|
|||||||
//mod block;
|
//mod block;
|
||||||
mod abbrev;
|
mod abbrev;
|
||||||
pub mod account_manager;
|
pub mod account_manager;
|
||||||
|
mod actionbar;
|
||||||
pub mod app_creation;
|
pub mod app_creation;
|
||||||
mod app_style;
|
mod app_style;
|
||||||
mod colors;
|
mod colors;
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ use crate::route::Route;
|
|||||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||||
use egui::{Direction, Layout};
|
use egui::{Direction, Layout};
|
||||||
|
|
||||||
use crate::ui::BarAction;
|
|
||||||
use egui_tabs::TabColor;
|
use egui_tabs::TabColor;
|
||||||
use egui_virtual_list::VirtualList;
|
use egui_virtual_list::VirtualList;
|
||||||
use enostr::{Filter, NoteId};
|
use enostr::Filter;
|
||||||
use nostrdb::{Note, Subscription, Transaction};
|
use nostrdb::{Note, Subscription, Transaction};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@@ -332,16 +331,9 @@ pub fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) {
|
|||||||
.show(ui);
|
.show(ui);
|
||||||
|
|
||||||
if let Some(action) = resp.action {
|
if let Some(action) = resp.action {
|
||||||
debug!("bar action: {:?}", action);
|
action.execute(app, timeline, note.id());
|
||||||
match action {
|
} else if resp.response.clicked() {
|
||||||
BarAction::Reply => {
|
debug!("clicked note");
|
||||||
let timeline = &mut app.timelines[timeline];
|
|
||||||
timeline
|
|
||||||
.routes
|
|
||||||
.push(Route::Reply(NoteId::new(note.id().to_owned())));
|
|
||||||
timeline.navigating = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub use account_switcher::AccountSelectionWidget;
|
|||||||
pub use fixed_window::{FixedWindow, FixedWindowResponse};
|
pub use fixed_window::{FixedWindow, FixedWindowResponse};
|
||||||
pub use global_popup::DesktopGlobalPopup;
|
pub use global_popup::DesktopGlobalPopup;
|
||||||
pub use mention::Mention;
|
pub use mention::Mention;
|
||||||
pub use note::{BarAction, NoteResponse, NoteView, PostReplyView, PostView};
|
pub use note::{NoteResponse, NoteView, PostReplyView, PostView};
|
||||||
pub use preview::{Preview, PreviewApp, PreviewConfig};
|
pub use preview::{Preview, PreviewApp, PreviewConfig};
|
||||||
pub use profile::{profile_preview_controller, ProfilePic, ProfilePreview};
|
pub use profile::{profile_preview_controller, ProfilePic, ProfilePreview};
|
||||||
pub use relay::RelayView;
|
pub use relay::RelayView;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pub use options::NoteOptions;
|
|||||||
pub use post::{PostAction, PostResponse, PostView};
|
pub use post::{PostAction, PostResponse, PostView};
|
||||||
pub use reply::PostReplyView;
|
pub use reply::PostReplyView;
|
||||||
|
|
||||||
use crate::{colors, notecache::CachedNote, ui, ui::View, Damus};
|
use crate::{actionbar::BarAction, colors, notecache::CachedNote, ui, ui::View, Damus};
|
||||||
use egui::{Label, RichText, Sense};
|
use egui::{Label, RichText, Sense};
|
||||||
use nostrdb::{Note, NoteKey, NoteReply, Transaction};
|
use nostrdb::{Note, NoteKey, NoteReply, Transaction};
|
||||||
|
|
||||||
@@ -368,11 +368,6 @@ impl<'a> NoteView<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
|
||||||
pub enum BarAction {
|
|
||||||
Reply,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_note_actionbar(
|
fn render_note_actionbar(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
note_key: NoteKey,
|
note_key: NoteKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user