make selected accounts non optional

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-06-25 22:09:55 -04:00
parent 9cacb6bb69
commit 8e92a97a57
16 changed files with 136 additions and 196 deletions

View File

@@ -165,7 +165,7 @@ pub struct AddColumnView<'a> {
key_state_map: &'a mut HashMap<Id, AcquireKeyState>,
ndb: &'a Ndb,
img_cache: &'a mut Images,
cur_account: Option<&'a UserAccount>,
cur_account: &'a UserAccount,
}
impl<'a> AddColumnView<'a> {
@@ -173,7 +173,7 @@ impl<'a> AddColumnView<'a> {
key_state_map: &'a mut HashMap<Id, AcquireKeyState>,
ndb: &'a Ndb,
img_cache: &'a mut Images,
cur_account: Option<&'a UserAccount>,
cur_account: &'a UserAccount,
) -> Self {
Self {
key_state_map,
@@ -188,7 +188,7 @@ impl<'a> AddColumnView<'a> {
for column_option_data in self.get_base_options() {
let option = column_option_data.option.clone();
if self.column_option_ui(ui, column_option_data).clicked() {
selected_option = self.cur_account.map(|acct| option.take_as_response(acct))
selected_option = Some(option.take_as_response(self.cur_account));
}
ui.add(Separator::default().spacing(0.0));
@@ -202,7 +202,7 @@ impl<'a> AddColumnView<'a> {
for column_option_data in self.get_notifications_options() {
let option = column_option_data.option.clone();
if self.column_option_ui(ui, column_option_data).clicked() {
selected_option = self.cur_account.map(|acct| option.take_as_response(acct));
selected_option = Some(option.take_as_response(self.cur_account));
}
ui.add(Separator::default().spacing(0.0));
@@ -233,11 +233,9 @@ impl<'a> AddColumnView<'a> {
};
let option = algo_option.option.clone();
if self.column_option_ui(ui, algo_option).clicked() {
self.cur_account.map(|acct| option.take_as_response(acct))
} else {
None
}
self.column_option_ui(ui, algo_option)
.clicked()
.then(|| option.take_as_response(self.cur_account))
}
fn algo_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> {
@@ -249,11 +247,9 @@ impl<'a> AddColumnView<'a> {
};
let option = algo_option.option.clone();
if self.column_option_ui(ui, algo_option).clicked() {
self.cur_account.map(|acct| option.take_as_response(acct))
} else {
None
}
self.column_option_ui(ui, algo_option)
.clicked()
.then(|| option.take_as_response(self.cur_account))
}
fn individual_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> {
@@ -261,7 +257,7 @@ impl<'a> AddColumnView<'a> {
for column_option_data in self.get_individual_options() {
let option = column_option_data.option.clone();
if self.column_option_ui(ui, column_option_data).clicked() {
selected_option = self.cur_account.map(|acct| option.take_as_response(acct));
selected_option = Some(option.take_as_response(self.cur_account));
}
ui.add(Separator::default().spacing(0.0));
@@ -327,12 +323,9 @@ impl<'a> AddColumnView<'a> {
}
}
if ui.add(add_column_button()).clicked() {
self.cur_account
.map(|acc| to_option(keypair.pubkey).take_as_response(acc))
} else {
None
}
ui.add(add_column_button())
.clicked()
.then(|| to_option(keypair.pubkey).take_as_response(self.cur_account))
} else {
None
};
@@ -453,20 +446,18 @@ impl<'a> AddColumnView<'a> {
option: AddColumnOption::Universe,
});
if let Some(acc) = self.cur_account {
let source = if acc.key.secret_key.is_some() {
PubkeySource::DeckAuthor
} else {
PubkeySource::Explicit(acc.key.pubkey)
};
let source = if self.cur_account.key.secret_key.is_some() {
PubkeySource::DeckAuthor
} else {
PubkeySource::Explicit(self.cur_account.key.pubkey)
};
vec.push(ColumnOptionData {
title: "Contacts",
description: "See notes from your contacts",
icon: app_images::home_image(),
option: AddColumnOption::Contacts(source),
});
}
vec.push(ColumnOptionData {
title: "Contacts",
description: "See notes from your contacts",
icon: app_images::home_image(),
option: AddColumnOption::Contacts(source),
});
vec.push(ColumnOptionData {
title: "Notifications",
description: "Stay up to date with notifications and mentions",
@@ -498,20 +489,18 @@ impl<'a> AddColumnView<'a> {
fn get_notifications_options(&self) -> Vec<ColumnOptionData> {
let mut vec = Vec::new();
if let Some(acc) = self.cur_account {
let source = if acc.key.secret_key.is_some() {
PubkeySource::DeckAuthor
} else {
PubkeySource::Explicit(acc.key.pubkey)
};
let source = if self.cur_account.key.secret_key.is_some() {
PubkeySource::DeckAuthor
} else {
PubkeySource::Explicit(self.cur_account.key.pubkey)
};
vec.push(ColumnOptionData {
title: "Your Notifications",
description: "Stay up to date with your notifications and mentions",
icon: app_images::notifications_image(),
option: AddColumnOption::Notification(source),
});
}
vec.push(ColumnOptionData {
title: "Your Notifications",
description: "Stay up to date with your notifications and mentions",
icon: app_images::notifications_image(),
option: AddColumnOption::Notification(source),
});
vec.push(ColumnOptionData {
title: "Someone else's Notifications",
@@ -526,20 +515,18 @@ impl<'a> AddColumnView<'a> {
fn get_individual_options(&self) -> Vec<ColumnOptionData> {
let mut vec = Vec::new();
if let Some(acc) = self.cur_account {
let source = if acc.key.secret_key.is_some() {
PubkeySource::DeckAuthor
} else {
PubkeySource::Explicit(acc.key.pubkey)
};
let source = if self.cur_account.key.secret_key.is_some() {
PubkeySource::DeckAuthor
} else {
PubkeySource::Explicit(self.cur_account.key.pubkey)
};
vec.push(ColumnOptionData {
title: "Your Notes",
description: "Keep track of your notes & replies",
icon: app_images::profile_image(),
option: AddColumnOption::Individual(source),
});
}
vec.push(ColumnOptionData {
title: "Your Notes",
description: "Keep track of your notes & replies",
icon: app_images::profile_image(),
option: AddColumnOption::Individual(source),
});
vec.push(ColumnOptionData {
title: "Someone else's Notes",
@@ -605,13 +592,8 @@ pub fn render_add_column_routes(
AddColumnRoute::Base => add_column_view.ui(ui),
AddColumnRoute::Algo(r) => match r {
AddAlgoRoute::Base => add_column_view.algo_ui(ui),
AddAlgoRoute::LastPerPubkey => {
if let Some(deck_author) = ctx.accounts.get_selected_account() {
add_column_view.algo_last_per_pk_ui(ui, deck_author.key.pubkey)
} else {
None
}
}
AddAlgoRoute::LastPerPubkey => add_column_view
.algo_last_per_pk_ui(ui, ctx.accounts.get_selected_account().key.pubkey),
},
AddColumnRoute::UndecidedNotification => add_column_view.notifications_ui(ui),
AddColumnRoute::ExternalNotification => add_column_view.external_notification_ui(ui),

View File

@@ -115,10 +115,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
&txn,
self.is_muted,
self.note_context,
&self
.accounts
.get_selected_account()
.map(|a| (&a.key).into()),
&(&self.accounts.get_selected_account().key).into(),
self.jobs,
)
.show(ui)

View File

@@ -27,7 +27,7 @@ pub struct SearchView<'a, 'd> {
txn: &'a Transaction,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
}
@@ -38,7 +38,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
note_options: NoteOptions,
query: &'a mut SearchQueryState,
note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
) -> Self {
Self {

View File

@@ -21,7 +21,7 @@ pub static SIDE_PANEL_WIDTH: f32 = 68.0;
static ICON_WIDTH: f32 = 40.0;
pub struct DesktopSidePanel<'a> {
selected_account: Option<&'a UserAccount>,
selected_account: &'a UserAccount,
decks_cache: &'a DecksCache,
}
@@ -55,7 +55,7 @@ impl SidePanelResponse {
}
impl<'a> DesktopSidePanel<'a> {
pub fn new(selected_account: Option<&'a UserAccount>, decks_cache: &'a DecksCache) -> Self {
pub fn new(selected_account: &'a UserAccount, decks_cache: &'a DecksCache) -> Self {
Self {
selected_account,
decks_cache,
@@ -92,9 +92,7 @@ impl<'a> DesktopSidePanel<'a> {
// ui.add_space(24.0);
//}
let is_interactive = self
.selected_account
.is_some_and(|s| s.key.secret_key.is_some());
let is_interactive = self.selected_account.key.secret_key.is_some();
let compose_resp = ui.add(crate::ui::post::compose_note_button(
is_interactive,
dark_mode,
@@ -388,14 +386,10 @@ fn add_deck_button() -> impl Widget {
fn show_decks<'a>(
ui: &mut egui::Ui,
decks_cache: &'a DecksCache,
selected_account: Option<&'a UserAccount>,
selected_account: &'a UserAccount,
) -> InnerResponse<Option<usize>> {
let show_decks_id = ui.id().with("show-decks");
let account_id = if let Some(acc) = selected_account {
acc.key.pubkey
} else {
*decks_cache.get_fallback_pubkey()
};
let account_id = selected_account.key.pubkey;
let (cur_decks, account_id) = (
decks_cache.decks(&account_id),
show_decks_id.with(account_id),

View File

@@ -18,7 +18,7 @@ pub struct ThreadView<'a, 'd> {
id_source: egui::Id,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
}
@@ -30,7 +30,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
note_options: NoteOptions,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
) -> Self {
let id_source = egui::Id::new("threadscroll_threadview");
@@ -135,10 +135,9 @@ impl<'a, 'd> ThreadView<'a, 'd> {
}
let zapping_acc = self
.cur_acc
.as_ref()
.filter(|_| self.note_context.current_account_has_wallet)
.or(self.cur_acc.as_ref());
.note_context
.current_account_has_wallet
.then_some(self.cur_acc);
show_notes(
ui,

View File

@@ -21,7 +21,7 @@ pub struct TimelineView<'a, 'd> {
reverse: bool,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
}
@@ -33,7 +33,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
note_options: NoteOptions,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
) -> Self {
let reverse = false;
@@ -78,7 +78,7 @@ fn timeline_ui(
note_options: NoteOptions,
is_muted: &MuteFun,
note_context: &mut NoteContext,
cur_acc: &Option<KeypairUnowned>,
cur_acc: &KeypairUnowned,
jobs: &mut JobsCache,
) -> Option<NoteAction> {
//padding(4.0, ui, |ui| ui.heading("Notifications"));
@@ -337,7 +337,7 @@ pub struct TimelineTabView<'a, 'd> {
txn: &'a Transaction,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
}
@@ -350,7 +350,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
txn: &'a Transaction,
is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
cur_acc: &'a KeypairUnowned<'a>,
jobs: &'a mut JobsCache,
) -> Self {
Self {
@@ -407,11 +407,11 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
};
if !muted {
let zapping_acc = self
.cur_acc
.as_ref()
.filter(|_| self.note_context.current_account_has_wallet)
.or(self.cur_acc.as_ref());
let zapping_acc = if self.note_context.current_account_has_wallet {
Some(self.cur_acc)
} else {
None
};
notedeck_ui::padding(8.0, ui, |ui| {
let resp = NoteView::new(

View File

@@ -92,13 +92,11 @@ impl WalletAction {
global_wallet.ui_state.for_local_only = true;
}
WalletAction::Delete => {
if let Some(acc) = accounts.get_selected_account() {
if acc.wallet.is_some() {
accounts.update_current_account(|acc| {
acc.wallet = None;
});
return None;
}
if accounts.get_selected_account().wallet.is_some() {
accounts.update_current_account(|acc| {
acc.wallet = None;
});
return None;
}
global_wallet.wallet = None;