Merge new Accounts button to chrome sidebar by kernel #994

kernelkind (3):
      use saturating sub
      add new Accounts button to chrome sidebar
      add ChromePanelAction::Profile & use for pfp
This commit is contained in:
William Casarin
2025-07-23 09:12:23 -07:00
4 changed files with 79 additions and 6 deletions

BIN
assets/icons/accounts.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -58,6 +58,7 @@ pub enum ChromePanelAction {
Wallet, Wallet,
Toolbar(ToolbarAction), Toolbar(ToolbarAction),
SaveTheme(ThemePreference), SaveTheme(ThemePreference),
Profile(notedeck::enostr::Pubkey),
} }
impl ChromePanelAction { impl ChromePanelAction {
@@ -160,6 +161,9 @@ impl ChromePanelAction {
notedeck_columns::Route::Wallet(WalletType::Auto), notedeck_columns::Route::Wallet(WalletType::Auto),
); );
} }
Self::Profile(pk) => {
columns_route_to_profile(pk, chrome, ctx, ui);
}
} }
} }
} }
@@ -571,6 +575,16 @@ fn columns_button(ui: &mut egui::Ui) -> egui::Response {
) )
} }
fn accounts_button(ui: &mut egui::Ui) -> egui::Response {
expanding_button(
"accounts-button",
24.0,
app_images::accounts_image().tint(ui.visuals().text_color()),
app_images::accounts_image(),
ui,
)
}
fn dave_sidebar_rect(ui: &mut egui::Ui) -> Rect { fn dave_sidebar_rect(ui: &mut egui::Ui) -> Rect {
let size = vec2(60.0, 60.0); let size = vec2(60.0, 60.0);
let available = ui.available_rect_before_wrap(); let available = ui.available_rect_before_wrap();
@@ -693,6 +707,59 @@ fn chrome_handle_app_action(
} }
} }
fn columns_route_to_profile(
pk: &notedeck::enostr::Pubkey,
chrome: &mut Chrome,
ctx: &mut AppContext,
ui: &mut egui::Ui,
) {
chrome.switch_to_columns();
let Some(columns) = chrome.get_columns_app() else {
return;
};
let cols = columns
.decks_cache
.active_columns_mut(ctx.i18n, ctx.accounts)
.unwrap();
let router = cols.get_first_router();
if router.routes().iter().any(|r| {
matches!(
r,
notedeck_columns::Route::Timeline(TimelineKind::Profile(_))
)
}) {
router.go_back();
return;
}
let txn = Transaction::new(ctx.ndb).unwrap();
let m_action = notedeck_columns::actionbar::execute_and_process_note_action(
notedeck::NoteAction::Profile(*pk),
ctx.ndb,
cols,
0,
&mut columns.timeline_cache,
&mut columns.threads,
ctx.note_cache,
ctx.pool,
&txn,
ctx.unknown_ids,
ctx.accounts,
ctx.global_wallet,
ctx.zaps,
ctx.img_cache,
ui,
);
if let Some(action) = m_action {
let col = cols.column_mut(0);
action.process(&mut col.router, &mut col.sheet_router);
}
}
fn pfp_button(ctx: &mut AppContext, ui: &mut egui::Ui) -> egui::Response { fn pfp_button(ctx: &mut AppContext, ui: &mut egui::Ui) -> egui::Response {
let max_size = ICON_WIDTH * ICON_EXPANSION_MULTIPLE; // max size of the widget let max_size = ICON_WIDTH * ICON_EXPANSION_MULTIPLE; // max size of the widget
let helper = AnimationHelper::new(ui, "pfp-button", egui::vec2(max_size, max_size)); let helper = AnimationHelper::new(ui, "pfp-button", egui::vec2(max_size, max_size));
@@ -720,6 +787,7 @@ fn bottomup_sidebar(
ui.add_space(8.0); ui.add_space(8.0);
let pfp_resp = pfp_button(ctx, ui).on_hover_cursor(egui::CursorIcon::PointingHand); let pfp_resp = pfp_button(ctx, ui).on_hover_cursor(egui::CursorIcon::PointingHand);
let accounts_resp = accounts_button(ui).on_hover_cursor(egui::CursorIcon::PointingHand);
let settings_resp = settings_button(ui).on_hover_cursor(egui::CursorIcon::PointingHand); let settings_resp = settings_button(ui).on_hover_cursor(egui::CursorIcon::PointingHand);
let theme_action = match ui.ctx().theme() { let theme_action = match ui.ctx().theme() {
@@ -791,6 +859,9 @@ fn bottomup_sidebar(
} }
if pfp_resp.clicked() { if pfp_resp.clicked() {
let pk = ctx.accounts.get_selected_account().key.pubkey;
Some(ChromePanelAction::Profile(pk))
} else if accounts_resp.clicked() {
Some(ChromePanelAction::Account) Some(ChromePanelAction::Account)
} else if settings_resp.clicked() { } else if settings_resp.clicked() {
Some(ChromePanelAction::Settings) Some(ChromePanelAction::Settings)

View File

@@ -474,12 +474,10 @@ impl TimelineSub {
let before = self.state.clone(); let before = self.state.clone();
's: { 's: {
match &mut self.state { match &mut self.state {
SubState::NoSub { dependers } => { SubState::NoSub { dependers } => *dependers = dependers.saturating_sub(1),
*dependers -= 1;
}
SubState::LocalOnly { local, dependers } => { SubState::LocalOnly { local, dependers } => {
if *dependers > 1 { if *dependers > 1 {
*dependers -= 1; *dependers = dependers.saturating_sub(1);
break 's; break 's;
} }
@@ -492,7 +490,7 @@ impl TimelineSub {
} }
SubState::RemoteOnly { remote, dependers } => { SubState::RemoteOnly { remote, dependers } => {
if *dependers > 1 { if *dependers > 1 {
*dependers -= 1; *dependers = dependers.saturating_sub(1);
break 's; break 's;
} }
@@ -502,7 +500,7 @@ impl TimelineSub {
} }
SubState::Unified { unified, dependers } => { SubState::Unified { unified, dependers } => {
if *dependers > 1 { if *dependers > 1 {
*dependers -= 1; *dependers = dependers.saturating_sub(1);
break 's; break 's;
} }

View File

@@ -11,6 +11,10 @@ pub fn add_account_image() -> Image<'static> {
)) ))
} }
pub fn accounts_image() -> Image<'static> {
Image::new(include_image!("../../../assets/icons/accounts.png"))
}
pub fn add_column_dark_image() -> Image<'static> { pub fn add_column_dark_image() -> Image<'static> {
Image::new(include_image!( Image::new(include_image!(
"../../../assets/icons/add_column_dark_4x.png" "../../../assets/icons/add_column_dark_4x.png"