make views pure

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-09-18 11:19:24 -04:00
parent 6e77d20197
commit eadef78543
3 changed files with 39 additions and 48 deletions

View File

@@ -1,19 +1,17 @@
use crate::draft::Drafts;
use crate::draft::Draft;
use crate::imgcache::ImageCache;
use crate::notecache::NoteCache;
use crate::post_action_executor::PostActionExecutor;
use crate::ui;
use crate::ui::note::PostResponse;
use enostr::{FilledKeypair, RelayPool};
use enostr::FilledKeypair;
use nostrdb::Ndb;
pub struct PostReplyView<'a> {
ndb: &'a Ndb,
poster: FilledKeypair<'a>,
pool: &'a mut RelayPool,
note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache,
drafts: &'a mut Drafts,
draft: &'a mut Draft,
note: &'a nostrdb::Note<'a>,
id_source: Option<egui::Id>,
}
@@ -22,8 +20,7 @@ impl<'a> PostReplyView<'a> {
pub fn new(
ndb: &'a Ndb,
poster: FilledKeypair<'a>,
pool: &'a mut RelayPool,
drafts: &'a mut Drafts,
draft: &'a mut Draft,
note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache,
note: &'a nostrdb::Note<'a>,
@@ -32,8 +29,7 @@ impl<'a> PostReplyView<'a> {
PostReplyView {
ndb,
poster,
pool,
drafts,
draft,
note,
note_cache,
img_cache,
@@ -79,10 +75,9 @@ impl<'a> PostReplyView<'a> {
let rect_before_post = ui.min_rect();
let post_response = {
let draft = self.drafts.reply_mut(replying_to);
ui::PostView::new(
self.ndb,
draft,
self.draft,
crate::draft::DraftSource::Reply(replying_to),
self.img_cache,
self.note_cache,
@@ -92,16 +87,6 @@ impl<'a> PostReplyView<'a> {
.ui(self.note.txn().unwrap(), ui)
};
if let Some(action) = &post_response.action {
PostActionExecutor::execute(
self.poster,
action,
self.pool,
self.drafts.reply_mut(replying_to),
|np, seckey| np.to_reply(seckey, self.note),
);
}
//
// reply line
//

View File

@@ -1,15 +1,17 @@
use crate::post_action_executor::PostActionExecutor;
use crate::draft::Draft;
use crate::{
actionbar::BarAction, column::Columns, draft::Drafts, imgcache::ImageCache,
notecache::NoteCache, timeline::TimelineId, ui,
actionbar::BarAction, column::Columns, imgcache::ImageCache, notecache::NoteCache,
timeline::TimelineId, ui,
};
use egui::containers::scroll_area::ScrollBarVisibility;
use egui::{Direction, Layout};
use egui_tabs::TabColor;
use enostr::{FilledKeypair, RelayPool};
use enostr::FilledKeypair;
use nostrdb::{Ndb, Transaction};
use tracing::{debug, error, warn};
use super::note::PostResponse;
pub struct TimelineView<'a> {
timeline_id: TimelineId,
columns: &'a mut Columns,
@@ -171,29 +173,22 @@ fn timeline_ui(
pub fn postbox_view<'a>(
ndb: &'a Ndb,
key: FilledKeypair<'a>,
pool: &'a mut RelayPool,
drafts: &'a mut Drafts,
draft: &'a mut Draft,
img_cache: &'a mut ImageCache,
note_cache: &'a mut NoteCache,
ui: &'a mut egui::Ui,
) {
) -> PostResponse {
// show a postbox in the first timeline
let txn = Transaction::new(ndb).expect("txn");
let response = ui::PostView::new(
ui::PostView::new(
ndb,
drafts.compose_mut(),
draft,
crate::draft::DraftSource::Compose,
img_cache,
note_cache,
key,
)
.ui(&txn, ui);
if let Some(action) = response.action {
PostActionExecutor::execute(key, &action, pool, drafts.compose_mut(), |np, seckey| {
np.to_note(seckey)
});
}
.ui(&txn, ui)
}
fn tabs_ui(ui: &mut egui::Ui) -> i32 {