mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 09:04:21 +01:00
@@ -500,13 +500,14 @@ fn chrome_handle_app_action(
|
||||
|
||||
let txn = Transaction::new(ctx.ndb).unwrap();
|
||||
|
||||
notedeck_columns::actionbar::execute_and_process_note_action(
|
||||
let cols = columns
|
||||
.decks_cache
|
||||
.active_columns_mut(ctx.accounts)
|
||||
.unwrap();
|
||||
let m_action = notedeck_columns::actionbar::execute_and_process_note_action(
|
||||
note_action,
|
||||
ctx.ndb,
|
||||
columns
|
||||
.decks_cache
|
||||
.active_columns_mut(ctx.accounts)
|
||||
.unwrap(),
|
||||
cols,
|
||||
0,
|
||||
&mut columns.timeline_cache,
|
||||
ctx.note_cache,
|
||||
@@ -519,6 +520,12 @@ fn chrome_handle_app_action(
|
||||
ctx.img_cache,
|
||||
ui,
|
||||
);
|
||||
|
||||
if let Some(action) = m_action {
|
||||
let col = cols.column_mut(0);
|
||||
|
||||
action.process(col.router_mut());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
column::Columns,
|
||||
route::{Route, Router},
|
||||
nav::{RouterAction, RouterType},
|
||||
route::Route,
|
||||
timeline::{ThreadSelection, TimelineCache, TimelineKind},
|
||||
};
|
||||
|
||||
@@ -21,12 +22,16 @@ pub enum TimelineOpenResult {
|
||||
NewNotes(NewNotes),
|
||||
}
|
||||
|
||||
struct NoteActionResponse {
|
||||
timeline_res: Option<TimelineOpenResult>,
|
||||
router_action: Option<RouterAction>,
|
||||
}
|
||||
|
||||
/// The note action executor for notedeck_columns
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn execute_note_action(
|
||||
action: NoteAction,
|
||||
ndb: &Ndb,
|
||||
router: &mut Router<Route>,
|
||||
timeline_cache: &mut TimelineCache,
|
||||
note_cache: &mut NoteCache,
|
||||
pool: &mut RelayPool,
|
||||
@@ -36,42 +41,43 @@ fn execute_note_action(
|
||||
zaps: &mut Zaps,
|
||||
images: &mut Images,
|
||||
ui: &mut egui::Ui,
|
||||
) -> Option<TimelineOpenResult> {
|
||||
) -> NoteActionResponse {
|
||||
let mut timeline_res = None;
|
||||
let mut router_action = None;
|
||||
|
||||
match action {
|
||||
NoteAction::Reply(note_id) => {
|
||||
router.route_to(Route::reply(note_id));
|
||||
None
|
||||
router_action = Some(RouterAction::route_to(Route::reply(note_id)));
|
||||
}
|
||||
NoteAction::Profile(pubkey) => {
|
||||
let kind = TimelineKind::Profile(pubkey);
|
||||
router.route_to(Route::Timeline(kind.clone()));
|
||||
timeline_cache.open(ndb, note_cache, txn, pool, &kind)
|
||||
router_action = Some(RouterAction::route_to(Route::Timeline(kind.clone())));
|
||||
timeline_res = timeline_cache.open(ndb, note_cache, txn, pool, &kind);
|
||||
}
|
||||
NoteAction::Note(note_id) => 'ex: {
|
||||
let Ok(thread_selection) = ThreadSelection::from_note_id(ndb, note_cache, txn, note_id)
|
||||
else {
|
||||
tracing::error!("No thread selection for {}?", hex::encode(note_id.bytes()));
|
||||
break 'ex None;
|
||||
break 'ex;
|
||||
};
|
||||
|
||||
let kind = TimelineKind::Thread(thread_selection);
|
||||
router.route_to(Route::Timeline(kind.clone()));
|
||||
router_action = Some(RouterAction::route_to(Route::Timeline(kind.clone())));
|
||||
// NOTE!!: you need the note_id to timeline root id thing
|
||||
|
||||
timeline_cache.open(ndb, note_cache, txn, pool, &kind)
|
||||
timeline_res = timeline_cache.open(ndb, note_cache, txn, pool, &kind);
|
||||
}
|
||||
NoteAction::Hashtag(htag) => {
|
||||
let kind = TimelineKind::Hashtag(htag.clone());
|
||||
router.route_to(Route::Timeline(kind.clone()));
|
||||
timeline_cache.open(ndb, note_cache, txn, pool, &kind)
|
||||
router_action = Some(RouterAction::route_to(Route::Timeline(kind.clone())));
|
||||
timeline_res = timeline_cache.open(ndb, note_cache, txn, pool, &kind);
|
||||
}
|
||||
NoteAction::Quote(note_id) => {
|
||||
router.route_to(Route::quote(note_id));
|
||||
None
|
||||
router_action = Some(RouterAction::route_to(Route::quote(note_id)));
|
||||
}
|
||||
NoteAction::Zap(zap_action) => 's: {
|
||||
let Some(cur_acc) = accounts.get_selected_account_mut() else {
|
||||
break 's None;
|
||||
break 's;
|
||||
};
|
||||
|
||||
let sender = cur_acc.key.pubkey;
|
||||
@@ -98,26 +104,26 @@ fn execute_note_action(
|
||||
}
|
||||
ZapAction::ClearError(target) => clear_zap_error(&sender, zaps, target),
|
||||
ZapAction::CustomizeAmount(target) => {
|
||||
router.route_to(Route::CustomizeZapAmount(target.to_owned()))
|
||||
let route = Route::CustomizeZapAmount(target.to_owned());
|
||||
router_action = Some(RouterAction::route_to(route));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
NoteAction::Context(context) => {
|
||||
match ndb.get_note_by_key(txn, context.note_key) {
|
||||
Err(err) => tracing::error!("{err}"),
|
||||
Ok(note) => {
|
||||
context.action.process(ui, ¬e, pool);
|
||||
}
|
||||
NoteAction::Context(context) => match ndb.get_note_by_key(txn, context.note_key) {
|
||||
Err(err) => tracing::error!("{err}"),
|
||||
Ok(note) => {
|
||||
context.action.process(ui, ¬e, pool);
|
||||
}
|
||||
None
|
||||
}
|
||||
},
|
||||
NoteAction::Media(media_action) => {
|
||||
media_action.process(images);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
NoteActionResponse {
|
||||
timeline_res,
|
||||
router_action,
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a NoteAction and process the result
|
||||
@@ -125,8 +131,8 @@ fn execute_note_action(
|
||||
pub fn execute_and_process_note_action(
|
||||
action: NoteAction,
|
||||
ndb: &Ndb,
|
||||
columns: &mut Columns,
|
||||
col: usize,
|
||||
_columns: &mut Columns,
|
||||
_col: usize,
|
||||
timeline_cache: &mut TimelineCache,
|
||||
note_cache: &mut NoteCache,
|
||||
pool: &mut RelayPool,
|
||||
@@ -137,12 +143,10 @@ pub fn execute_and_process_note_action(
|
||||
zaps: &mut Zaps,
|
||||
images: &mut Images,
|
||||
ui: &mut egui::Ui,
|
||||
) {
|
||||
let router = columns.column_mut(col).router_mut();
|
||||
if let Some(br) = execute_note_action(
|
||||
) -> Option<RouterAction> {
|
||||
let resp = execute_note_action(
|
||||
action,
|
||||
ndb,
|
||||
router,
|
||||
timeline_cache,
|
||||
note_cache,
|
||||
pool,
|
||||
@@ -152,9 +156,13 @@ pub fn execute_and_process_note_action(
|
||||
zaps,
|
||||
images,
|
||||
ui,
|
||||
) {
|
||||
);
|
||||
|
||||
if let Some(br) = resp.timeline_res {
|
||||
br.process(ndb, note_cache, txn, timeline_cache, unknown_ids);
|
||||
}
|
||||
|
||||
resp.router_action
|
||||
}
|
||||
|
||||
fn send_zap(
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
profile::{ProfileAction, SaveProfileChanges},
|
||||
profile_state::ProfileState,
|
||||
relay_pool_manager::RelayPoolManager,
|
||||
route::Route,
|
||||
route::{Route, Router},
|
||||
timeline::{route::render_timeline_route, TimelineCache},
|
||||
ui::{
|
||||
self,
|
||||
@@ -198,6 +198,31 @@ fn process_nav_resp(
|
||||
switching_occured
|
||||
}
|
||||
|
||||
pub enum RouterAction {
|
||||
GoBack,
|
||||
RouteTo(Route, RouterType),
|
||||
}
|
||||
|
||||
pub enum RouterType {
|
||||
Stack,
|
||||
}
|
||||
|
||||
impl RouterAction {
|
||||
pub fn process(self, stack_router: &mut Router<Route>) {
|
||||
match self {
|
||||
RouterAction::GoBack => {
|
||||
stack_router.go_back();
|
||||
}
|
||||
RouterAction::RouteTo(route, router_type) => match router_type {
|
||||
RouterType::Stack => stack_router.route_to(route),
|
||||
},
|
||||
}
|
||||
}
|
||||
pub fn route_to(route: Route) -> Self {
|
||||
RouterAction::RouteTo(route, RouterType::Stack)
|
||||
}
|
||||
}
|
||||
|
||||
fn process_render_nav_action(
|
||||
app: &mut Damus,
|
||||
ctx: &mut AppContext<'_>,
|
||||
@@ -205,13 +230,8 @@ fn process_render_nav_action(
|
||||
col: usize,
|
||||
action: RenderNavAction,
|
||||
) -> bool {
|
||||
match action {
|
||||
RenderNavAction::Back => {
|
||||
app.columns_mut(ctx.accounts)
|
||||
.column_mut(col)
|
||||
.router_mut()
|
||||
.go_back();
|
||||
}
|
||||
let router_action = match action {
|
||||
RenderNavAction::Back => Some(RouterAction::GoBack),
|
||||
|
||||
RenderNavAction::RemoveColumn => {
|
||||
let kinds_to_pop = app.columns_mut(ctx.accounts).delete_column(col);
|
||||
@@ -231,10 +251,8 @@ fn process_render_nav_action(
|
||||
Err(err) => tracing::error!("Error executing post action: {err}"),
|
||||
Ok(_) => tracing::debug!("Post action executed"),
|
||||
}
|
||||
get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
|
||||
.column_mut(col)
|
||||
.router_mut()
|
||||
.go_back();
|
||||
|
||||
Some(RouterAction::GoBack)
|
||||
}
|
||||
|
||||
RenderNavAction::NoteAction(note_action) => {
|
||||
@@ -255,28 +273,26 @@ fn process_render_nav_action(
|
||||
ctx.zaps,
|
||||
ctx.img_cache,
|
||||
ui,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
RenderNavAction::SwitchingAction(switching_action) => {
|
||||
return switching_action.process(&mut app.timeline_cache, &mut app.decks_cache, ctx);
|
||||
}
|
||||
RenderNavAction::ProfileAction(profile_action) => {
|
||||
profile_action.process(
|
||||
&mut app.view_state.pubkey_to_profile_state,
|
||||
ctx.ndb,
|
||||
ctx.pool,
|
||||
get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
|
||||
.column_mut(col)
|
||||
.router_mut(),
|
||||
);
|
||||
}
|
||||
RenderNavAction::ProfileAction(profile_action) => profile_action.process(
|
||||
&mut app.view_state.pubkey_to_profile_state,
|
||||
ctx.ndb,
|
||||
ctx.pool,
|
||||
),
|
||||
RenderNavAction::WalletAction(wallet_action) => {
|
||||
let router = get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
|
||||
.column_mut(col)
|
||||
.router_mut();
|
||||
wallet_action.process(ctx.accounts, ctx.global_wallet, router)
|
||||
wallet_action.process(ctx.accounts, ctx.global_wallet)
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(action) = router_action {
|
||||
let cols = get_active_columns_mut(ctx.accounts, &mut app.decks_cache).column_mut(col);
|
||||
let router = cols.router_mut();
|
||||
action.process(router);
|
||||
}
|
||||
|
||||
false
|
||||
|
||||
@@ -5,10 +5,7 @@ use nostrdb::{Ndb, Note, NoteBuildOptions, NoteBuilder};
|
||||
|
||||
use tracing::info;
|
||||
|
||||
use crate::{
|
||||
profile_state::ProfileState,
|
||||
route::{Route, Router},
|
||||
};
|
||||
use crate::{nav::RouterAction, profile_state::ProfileState, route::Route};
|
||||
|
||||
pub struct SaveProfileChanges {
|
||||
pub kp: FullKeypair,
|
||||
@@ -48,12 +45,9 @@ impl ProfileAction {
|
||||
state_map: &mut HashMap<Pubkey, ProfileState>,
|
||||
ndb: &Ndb,
|
||||
pool: &mut RelayPool,
|
||||
router: &mut Router<Route>,
|
||||
) {
|
||||
) -> Option<RouterAction> {
|
||||
match self {
|
||||
ProfileAction::Edit(kp) => {
|
||||
router.route_to(Route::EditProfile(kp.pubkey));
|
||||
}
|
||||
ProfileAction::Edit(kp) => Some(RouterAction::route_to(Route::EditProfile(kp.pubkey))),
|
||||
ProfileAction::SaveChanges(changes) => {
|
||||
let raw_msg = format!("[\"EVENT\",{}]", changes.to_note().json().unwrap());
|
||||
|
||||
@@ -66,7 +60,7 @@ impl ProfileAction {
|
||||
info!("sending {}", raw_msg);
|
||||
pool.send(&enostr::ClientMessage::raw(raw_msg));
|
||||
|
||||
router.go_back();
|
||||
Some(RouterAction::GoBack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use notedeck::{
|
||||
PendingDefaultZapState, Wallet, WalletError, WalletUIState, ZapWallet,
|
||||
};
|
||||
|
||||
use crate::route::{Route, Router};
|
||||
use crate::{nav::RouterAction, route::Route};
|
||||
|
||||
use super::widgets::styled_button;
|
||||
|
||||
@@ -55,43 +55,40 @@ impl WalletAction {
|
||||
&self,
|
||||
accounts: &mut Accounts,
|
||||
global_wallet: &mut GlobalWallet,
|
||||
router: &mut Router<Route>,
|
||||
) {
|
||||
) -> Option<RouterAction> {
|
||||
let mut action = None;
|
||||
|
||||
match &self {
|
||||
WalletAction::SaveURI => {
|
||||
let ui_state = &mut global_wallet.ui_state;
|
||||
if ui_state.for_local_only {
|
||||
ui_state.for_local_only = false;
|
||||
let Some(cur_acc) = accounts.get_selected_account_mut() else {
|
||||
return;
|
||||
};
|
||||
let cur_acc = accounts.get_selected_account_mut()?;
|
||||
|
||||
if cur_acc.wallet.is_some() {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
|
||||
let Some(wallet) = try_create_wallet(ui_state) else {
|
||||
return;
|
||||
};
|
||||
let wallet = try_create_wallet(ui_state)?;
|
||||
|
||||
accounts.update_current_account(move |acc| {
|
||||
acc.wallet = Some(wallet.into());
|
||||
});
|
||||
} else {
|
||||
if global_wallet.wallet.is_some() {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
|
||||
let Some(wallet) = try_create_wallet(ui_state) else {
|
||||
return;
|
||||
};
|
||||
let wallet = try_create_wallet(ui_state)?;
|
||||
|
||||
global_wallet.wallet = Some(wallet.into());
|
||||
global_wallet.save_wallet();
|
||||
}
|
||||
}
|
||||
WalletAction::AddLocalOnly => {
|
||||
router.route_to(Route::Wallet(notedeck::WalletType::Local));
|
||||
action = Some(RouterAction::route_to(Route::Wallet(
|
||||
notedeck::WalletType::Local,
|
||||
)));
|
||||
global_wallet.ui_state.for_local_only = true;
|
||||
}
|
||||
WalletAction::Delete => {
|
||||
@@ -100,7 +97,7 @@ impl WalletAction {
|
||||
accounts.update_current_account(|acc| {
|
||||
acc.wallet = None;
|
||||
});
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +150,7 @@ impl WalletAction {
|
||||
(wallet.default_zap.get_default_zap_msats() / 1000).to_string();
|
||||
}
|
||||
}
|
||||
action
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user