quote_repost.rs (2263B)
1 use super::{PostResponse, PostType}; 2 use crate::{ 3 draft::Draft, 4 ui::{self}, 5 }; 6 7 use egui::ScrollArea; 8 use enostr::{FilledKeypair, NoteId}; 9 use notedeck::{DragResponse, NoteContext}; 10 use notedeck_ui::NoteOptions; 11 12 pub struct QuoteRepostView<'a, 'd> { 13 note_context: &'a mut NoteContext<'d>, 14 poster: FilledKeypair<'a>, 15 draft: &'a mut Draft, 16 quoting_note: &'a nostrdb::Note<'a>, 17 scroll_id: egui::Id, 18 inner_rect: egui::Rect, 19 note_options: NoteOptions, 20 } 21 22 impl<'a, 'd> QuoteRepostView<'a, 'd> { 23 #[allow(clippy::too_many_arguments)] 24 pub fn new( 25 note_context: &'a mut NoteContext<'d>, 26 poster: FilledKeypair<'a>, 27 draft: &'a mut Draft, 28 quoting_note: &'a nostrdb::Note<'a>, 29 inner_rect: egui::Rect, 30 note_options: NoteOptions, 31 col: usize, 32 ) -> Self { 33 QuoteRepostView { 34 note_context, 35 poster, 36 draft, 37 quoting_note, 38 scroll_id: QuoteRepostView::scroll_id(col, quoting_note.id()), 39 inner_rect, 40 note_options, 41 } 42 } 43 44 fn id(col: usize, note_id: &[u8; 32]) -> egui::Id { 45 egui::Id::new(("quote_repost", col, note_id)) 46 } 47 48 pub fn scroll_id(col: usize, note_id: &[u8; 32]) -> egui::Id { 49 QuoteRepostView::id(col, note_id).with("scroll") 50 } 51 52 pub fn show(&mut self, ui: &mut egui::Ui) -> DragResponse<PostResponse> { 53 let scroll_out = ScrollArea::vertical() 54 .id_salt(self.scroll_id) 55 .show(ui, |ui| Some(self.show_internal(ui))); 56 57 let scroll_id = scroll_out.id; 58 59 if let Some(inner) = scroll_out.inner { 60 inner 61 } else { 62 DragResponse::none() 63 } 64 .scroll_raw(scroll_id) 65 } 66 67 fn show_internal(&mut self, ui: &mut egui::Ui) -> DragResponse<PostResponse> { 68 let quoting_note_id = self.quoting_note.id(); 69 70 let post_resp = ui::PostView::new( 71 self.note_context, 72 self.draft, 73 PostType::Quote(NoteId::new(quoting_note_id.to_owned())), 74 self.poster, 75 self.inner_rect, 76 self.note_options, 77 ) 78 .ui_no_scroll(self.quoting_note.txn().unwrap(), ui); 79 post_resp 80 } 81 }