remove app from sidebar

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-09-24 16:00:21 -04:00
parent 0ea3132ee2
commit 2832def161
3 changed files with 47 additions and 22 deletions

View File

@@ -957,7 +957,12 @@ fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus, columns: usiz
.horizontal(|mut strip| { .horizontal(|mut strip| {
strip.cell(|ui| { strip.cell(|ui| {
let rect = ui.available_rect_before_wrap(); let rect = ui.available_rect_before_wrap();
let side_panel = DesktopSidePanel::new(app).show(ui); let side_panel = DesktopSidePanel::new(
&app.ndb,
&mut app.img_cache,
app.accounts.get_selected_account(),
)
.show(ui);
let router = if let Some(router) = app let router = if let Some(router) = app
.columns .columns

View File

@@ -1,6 +1,7 @@
use crate::app_style::NotedeckTextStyle; use crate::app_style::NotedeckTextStyle;
use crate::imgcache::ImageCache; use crate::imgcache::ImageCache;
use crate::ui::ProfilePic; use crate::ui::ProfilePic;
use crate::user_account::UserAccount;
use crate::{colors, images, DisplayName}; use crate::{colors, images, DisplayName};
use egui::load::TexturePoll; use egui::load::TexturePoll;
use egui::{Frame, RichText, Sense, Widget}; use egui::{Frame, RichText, Sense, Widget};
@@ -175,6 +176,22 @@ pub fn get_profile_url_owned(profile: Option<ProfileRecord<'_>>) -> &str {
} }
} }
pub fn get_account_url<'a>(
txn: &'a nostrdb::Transaction,
ndb: &nostrdb::Ndb,
account: Option<&UserAccount>,
) -> &'a str {
if let Some(selected_account) = account {
if let Ok(profile) = ndb.get_profile_by_pubkey(txn, selected_account.pubkey.bytes()) {
get_profile_url_owned(Some(profile))
} else {
get_profile_url_owned(None)
}
} else {
get_profile_url(None)
}
}
fn display_name_widget( fn display_name_widget(
display_name: DisplayName<'_>, display_name: DisplayName<'_>,
add_placeholder_space: bool, add_placeholder_space: bool,

View File

@@ -5,13 +5,15 @@ use crate::{
account_manager::AccountsRoute, account_manager::AccountsRoute,
colors, colors,
column::Column, column::Column,
imgcache::ImageCache,
route::{Route, Router}, route::{Route, Router},
user_account::UserAccount,
Damus, Damus,
}; };
use super::{ use super::{
anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE}, anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE},
profile::preview::{get_profile_url, get_profile_url_tmp}, profile::preview::get_account_url,
ProfilePic, View, ProfilePic, View,
}; };
@@ -19,7 +21,9 @@ pub static SIDE_PANEL_WIDTH: f32 = 64.0;
static ICON_WIDTH: f32 = 40.0; static ICON_WIDTH: f32 = 40.0;
pub struct DesktopSidePanel<'a> { pub struct DesktopSidePanel<'a> {
app: &'a mut Damus, ndb: &'a nostrdb::Ndb,
img_cache: &'a mut ImageCache,
selected_account: Option<&'a UserAccount>,
} }
impl<'a> View for DesktopSidePanel<'a> { impl<'a> View for DesktopSidePanel<'a> {
@@ -50,8 +54,16 @@ impl SidePanelResponse {
} }
impl<'a> DesktopSidePanel<'a> { impl<'a> DesktopSidePanel<'a> {
pub fn new(app: &'a mut Damus) -> Self { pub fn new(
DesktopSidePanel { app } ndb: &'a nostrdb::Ndb,
img_cache: &'a mut ImageCache,
selected_account: Option<&'a UserAccount>,
) -> Self {
Self {
ndb,
img_cache,
selected_account,
}
} }
pub fn panel() -> SidePanel { pub fn panel() -> SidePanel {
@@ -138,23 +150,10 @@ impl<'a> DesktopSidePanel<'a> {
let min_pfp_size = ICON_WIDTH; let min_pfp_size = ICON_WIDTH;
let cur_pfp_size = helper.scale_1d_pos(min_pfp_size); let cur_pfp_size = helper.scale_1d_pos(min_pfp_size);
let selected_account = self.app.accounts().get_selected_account(); let txn = nostrdb::Transaction::new(self.ndb).expect("should be able to create txn");
let txn = nostrdb::Transaction::new(&self.app.ndb).expect("should be able to create txn"); let profile_url = get_account_url(&txn, self.ndb, self.selected_account);
let profile_url = if let Some(selected_account) = selected_account {
if let Ok(profile) = self
.app
.ndb()
.get_profile_by_pubkey(&txn, selected_account.pubkey.bytes())
{
get_profile_url_tmp(Some(profile))
} else {
get_profile_url_tmp(None)
}
} else {
get_profile_url(None)
};
let widget = ProfilePic::new(self.app.img_cache_mut(), profile_url).size(cur_pfp_size); let widget = ProfilePic::new(self.img_cache, profile_url).size(cur_pfp_size);
ui.put(helper.get_animation_rect(), widget); ui.put(helper.get_animation_rect(), widget);
@@ -365,7 +364,11 @@ mod preview {
.clip(true) .clip(true)
.horizontal(|mut strip| { .horizontal(|mut strip| {
strip.cell(|ui| { strip.cell(|ui| {
let mut panel = DesktopSidePanel::new(&mut self.app); let mut panel = DesktopSidePanel::new(
&self.app.ndb,
&mut self.app.img_cache,
self.app.accounts.get_selected_account(),
);
let response = panel.show(ui); let response = panel.show(ui);
DesktopSidePanel::perform_action( DesktopSidePanel::perform_action(