initial post box view

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-06-14 12:16:49 -07:00
parent 577aa76ac7
commit 1458498131
17 changed files with 181 additions and 25 deletions

View File

@@ -201,7 +201,7 @@ fn selected_widget() -> impl egui::Widget {
mod preview {
use super::*;
use crate::test_data::get_account_manager_test_app;
use crate::test_data;
pub struct AccountManagementPreview {
is_mobile: bool,
@@ -210,7 +210,7 @@ mod preview {
impl AccountManagementPreview {
fn new(is_mobile: bool) -> Self {
let app = get_account_manager_test_app(is_mobile);
let app = test_data::test_app(is_mobile);
AccountManagementPreview { is_mobile, app }
}

View File

@@ -214,7 +214,7 @@ mod previews {
impl AccountSelectionPreview {
fn new(is_mobile: bool) -> Self {
let app = test_data::get_account_manager_test_app(is_mobile);
let app = test_data::test_app(is_mobile);
AccountSelectionPreview { app }
}
}

View File

@@ -13,7 +13,7 @@ pub mod username;
pub use account_management::AccountManagementView;
pub use account_switcher::AccountSelectionWidget;
pub use mention::Mention;
pub use note::{BarAction, Note, NoteResponse};
pub use note::{BarAction, Note, NoteResponse, PostView};
pub use preview::{Preview, PreviewApp, PreviewConfig};
pub use profile::{profile_preview_controller, ProfilePic, ProfilePreview};
pub use relay::RelayView;

View File

@@ -1,8 +1,10 @@
pub mod contents;
pub mod options;
pub mod post;
pub use contents::NoteContents;
pub use options::NoteOptions;
pub use post::PostView;
use crate::{colors, notecache::CachedNote, ui, ui::View, Damus};
use egui::{Label, RichText, Sense};

112
src/ui/note/post.rs Normal file
View File

@@ -0,0 +1,112 @@
use crate::app::Damus;
use crate::draft::Draft;
use crate::ui::{Preview, PreviewConfig, View};
use crate::{ui, Error};
use egui::widgets::text_edit::TextEdit;
use nostrdb::Transaction;
pub struct PostView<'app, 'p> {
app: &'app mut Damus,
/// account index
poster: usize,
replying_to: &'p [u8; 32],
}
impl<'app, 'p> PostView<'app, 'p> {
pub fn new(app: &'app mut Damus, poster: usize, replying_to: &'p [u8; 32]) -> Self {
PostView {
app,
poster,
replying_to,
}
}
pub fn ui(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) -> Result<(), Error> {
egui::Frame::default()
.inner_margin(egui::Margin::same(12.0))
.inner_margin(egui::Margin::same(12.0))
.fill(ui.visuals().extreme_bg_color)
.stroke(ui.visuals().noninteractive().bg_stroke)
.rounding(12.0)
.show(ui, |ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 12.0;
let pfp_size = 24.0;
let poster_pubkey = self
.app
.account_manager
.get_account(self.poster)
.map(|acc| acc.pubkey.bytes())
.unwrap_or(crate::test_data::test_pubkey());
// TODO: refactor pfp control to do all of this for us
let poster_pfp = self
.app
.ndb
.get_profile_by_pubkey(&txn, poster_pubkey)
.as_ref()
.ok()
.and_then(|p| ui::ProfilePic::from_profile(&mut self.app.img_cache, p));
if let Some(pfp) = poster_pfp {
ui.add(pfp);
} else {
ui.add(
ui::ProfilePic::new(
&mut self.app.img_cache,
ui::ProfilePic::no_pfp_url(),
)
.size(pfp_size),
);
}
let draft = self
.app
.drafts
.entry(enostr::NoteId::new(*self.replying_to))
.or_insert_with(|| Draft::new());
ui.add(TextEdit::multiline(&mut draft.buffer).frame(false));
Ok(())
})
.inner
})
.inner
}
}
mod preview {
use super::*;
use crate::test_data;
pub struct PostPreview {
app: Damus,
}
impl PostPreview {
fn new(is_mobile: bool) -> Self {
PostPreview {
app: test_data::test_app(is_mobile),
}
}
}
impl View for PostPreview {
fn ui(&mut self, ui: &mut egui::Ui) {
let test_note_id = test_data::test_pubkey();
let txn = Transaction::new(&self.app.ndb).unwrap();
let _r = PostView::new(&mut self.app, 0, test_note_id).ui(&txn, ui);
}
}
impl<'app, 'p> Preview for PostView<'app, 'p> {
type Prev = PostPreview;
fn preview(cfg: PreviewConfig) -> Self::Prev {
PostPreview::new(cfg.is_mobile)
}
}
}

1
src/ui/note/reply.rs Normal file
View File

@@ -0,0 +1 @@
struct PostReplyView {}

View File

@@ -20,6 +20,17 @@ impl<'cache, 'url> ProfilePic<'cache, 'url> {
ProfilePic { cache, url, size }
}
pub fn from_profile(
cache: &'cache mut ImageCache,
profile: &nostrdb::ProfileRecord<'url>,
) -> Option<Self> {
if let Some(url) = profile.record().profile().and_then(|p| p.picture()) {
Some(ProfilePic::new(cache, url))
} else {
None
}
}
pub fn default_size() -> f32 {
38.0
}

View File

@@ -122,7 +122,7 @@ mod preview {
impl DesktopSidePanelPreview {
fn new(is_mobile: bool) -> Self {
let app = test_data::get_account_manager_test_app(is_mobile);
let app = test_data::test_app(is_mobile);
DesktopSidePanelPreview { app }
}
}