mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-17 15:24:19 +01:00
remove profile_preview_controller
no longer needed Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -10,8 +10,6 @@ use egui::{Align, Button, Frame, Image, InnerResponse, Layout, RichText, ScrollA
|
||||
use nostrdb::{Ndb, Transaction};
|
||||
|
||||
use super::profile::preview::SimpleProfilePreview;
|
||||
use super::profile::ProfilePreviewOp;
|
||||
use super::profile_preview_controller::profile_preview_view;
|
||||
|
||||
pub struct AccountsView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
@@ -26,6 +24,12 @@ pub enum AccountsViewResponse {
|
||||
RouteToLogin,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ProfilePreviewOp {
|
||||
RemoveAccount,
|
||||
SwitchTo,
|
||||
}
|
||||
|
||||
impl<'a> AccountsView<'a> {
|
||||
pub fn new(ndb: &'a Ndb, accounts: &'a AccountManager, img_cache: &'a mut ImageCache) -> Self {
|
||||
AccountsView {
|
||||
@@ -86,9 +90,13 @@ impl<'a> AccountsView<'a> {
|
||||
false
|
||||
};
|
||||
|
||||
if let Some(op) =
|
||||
profile_preview_view(ui, profile.as_ref(), img_cache, is_selected)
|
||||
{
|
||||
let profile_peview_view = {
|
||||
let width = ui.available_width();
|
||||
let preview = SimpleProfilePreview::new(profile.as_ref(), img_cache);
|
||||
show_profile_card(ui, preview, width, is_selected)
|
||||
};
|
||||
|
||||
if let Some(op) = profile_peview_view {
|
||||
return_op = Some(match op {
|
||||
ProfilePreviewOp::SwitchTo => AccountsViewResponse::SelectAccount(i),
|
||||
ProfilePreviewOp::RemoveAccount => {
|
||||
@@ -119,7 +127,7 @@ impl<'a> AccountsView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_profile_card(
|
||||
fn show_profile_card(
|
||||
ui: &mut egui::Ui,
|
||||
preview: SimpleProfilePreview,
|
||||
width: f32,
|
||||
|
||||
@@ -15,7 +15,7 @@ pub use account_management::AccountsView;
|
||||
pub use mention::Mention;
|
||||
pub use note::{NoteResponse, NoteView, PostReplyView, PostView};
|
||||
pub use preview::{Preview, PreviewApp, PreviewConfig};
|
||||
pub use profile::{profile_preview_controller, ProfilePic, ProfilePreview};
|
||||
pub use profile::{ProfilePic, ProfilePreview};
|
||||
pub use relay::RelayView;
|
||||
pub use side_panel::{DesktopSidePanel, SidePanelAction};
|
||||
pub use thread::ThreadView;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
pub mod picture;
|
||||
pub mod preview;
|
||||
pub mod profile_preview_controller;
|
||||
|
||||
pub use picture::ProfilePic;
|
||||
pub use preview::ProfilePreview;
|
||||
pub use profile_preview_controller::ProfilePreviewOp;
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
use egui::Ui;
|
||||
use nostrdb::{Ndb, ProfileRecord, Transaction};
|
||||
|
||||
use crate::{
|
||||
imgcache::ImageCache, ui::account_management::show_profile_card, Damus, DisplayName, Result,
|
||||
};
|
||||
|
||||
use super::{
|
||||
preview::{get_display_name, get_profile_url, SimpleProfilePreview},
|
||||
ProfilePic,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ProfilePreviewOp {
|
||||
RemoveAccount,
|
||||
SwitchTo,
|
||||
}
|
||||
|
||||
pub fn profile_preview_view(
|
||||
ui: &mut Ui,
|
||||
profile: Option<&'_ ProfileRecord<'_>>,
|
||||
img_cache: &mut ImageCache,
|
||||
is_selected: bool,
|
||||
) -> Option<ProfilePreviewOp> {
|
||||
let width = ui.available_width();
|
||||
|
||||
let preview = SimpleProfilePreview::new(profile, img_cache);
|
||||
show_profile_card(ui, preview, width, is_selected)
|
||||
}
|
||||
|
||||
pub fn view_profile_previews(
|
||||
app: &mut Damus,
|
||||
ui: &mut egui::Ui,
|
||||
add_preview_ui: fn(
|
||||
ui: &mut egui::Ui,
|
||||
preview: SimpleProfilePreview,
|
||||
width: f32,
|
||||
is_selected: bool,
|
||||
index: usize,
|
||||
) -> bool,
|
||||
) -> Option<usize> {
|
||||
let width = ui.available_width();
|
||||
|
||||
let txn = if let Ok(txn) = Transaction::new(app.ndb()) {
|
||||
txn
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
||||
for i in 0..app.accounts().num_accounts() {
|
||||
let account = if let Some(account) = app.accounts().get_account(i) {
|
||||
account
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let profile = app
|
||||
.ndb()
|
||||
.get_profile_by_pubkey(&txn, account.pubkey.bytes())
|
||||
.ok();
|
||||
|
||||
let is_selected = if let Some(selected) = app.accounts().get_selected_account_index() {
|
||||
i == selected
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let preview = SimpleProfilePreview::new(profile.as_ref(), app.img_cache_mut());
|
||||
|
||||
if add_preview_ui(ui, preview, width, is_selected, i) {
|
||||
return Some(i);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn show_with_nickname(
|
||||
ndb: &Ndb,
|
||||
ui: &mut egui::Ui,
|
||||
key: &[u8; 32],
|
||||
ui_element: fn(ui: &mut egui::Ui, username: &DisplayName) -> egui::Response,
|
||||
) -> Result<egui::Response> {
|
||||
let txn = Transaction::new(ndb)?;
|
||||
let profile = ndb.get_profile_by_pubkey(&txn, key)?;
|
||||
Ok(ui_element(ui, &get_display_name(Some(&profile))))
|
||||
}
|
||||
|
||||
pub fn show_with_selected_pfp(
|
||||
app: &mut Damus,
|
||||
ui: &mut egui::Ui,
|
||||
ui_element: fn(ui: &mut egui::Ui, pfp: ProfilePic) -> egui::Response,
|
||||
) -> Option<egui::Response> {
|
||||
let selected_account = app.accounts().get_selected_account();
|
||||
if let Some(selected_account) = selected_account {
|
||||
if let Ok(txn) = Transaction::new(app.ndb()) {
|
||||
let profile = app
|
||||
.ndb()
|
||||
.get_profile_by_pubkey(&txn, selected_account.pubkey.bytes());
|
||||
|
||||
return Some(ui_element(
|
||||
ui,
|
||||
ProfilePic::new(app.img_cache_mut(), get_profile_url(profile.ok().as_ref())),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn show_with_pfp(
|
||||
app: &mut Damus,
|
||||
ui: &mut egui::Ui,
|
||||
key: &[u8; 32],
|
||||
ui_element: fn(ui: &mut egui::Ui, pfp: ProfilePic) -> egui::Response,
|
||||
) -> Option<egui::Response> {
|
||||
if let Ok(txn) = Transaction::new(app.ndb()) {
|
||||
let profile = app.ndb().get_profile_by_pubkey(&txn, key);
|
||||
|
||||
return Some(ui_element(
|
||||
ui,
|
||||
ProfilePic::new(app.img_cache_mut(), get_profile_url(profile.ok().as_ref())),
|
||||
));
|
||||
}
|
||||
None
|
||||
}
|
||||
Reference in New Issue
Block a user