route.rs (3908B)
1 use crate::{ 2 nav::RenderNavAction, 3 profile::ProfileAction, 4 timeline::{thread::Threads, ThreadSelection, TimelineCache, TimelineKind}, 5 ui::{self, ProfileView}, 6 }; 7 8 use enostr::Pubkey; 9 use notedeck::{DragResponse, NoteContext}; 10 use notedeck_ui::NoteOptions; 11 12 #[allow(clippy::too_many_arguments)] 13 pub fn render_timeline_route( 14 timeline_cache: &mut TimelineCache, 15 kind: &TimelineKind, 16 col: usize, 17 note_options: NoteOptions, 18 depth: usize, 19 ui: &mut egui::Ui, 20 note_context: &mut NoteContext, 21 scroll_to_top: bool, 22 ) -> DragResponse<RenderNavAction> { 23 match kind { 24 TimelineKind::List(_) 25 | TimelineKind::Search(_) 26 | TimelineKind::Algo(_) 27 | TimelineKind::Notifications(_) 28 | TimelineKind::Universe 29 | TimelineKind::Hashtag(_) 30 | TimelineKind::Generic(_) => { 31 let resp = 32 ui::TimelineView::new(kind, timeline_cache, note_context, note_options, col).ui(ui); 33 34 resp.map_output(RenderNavAction::NoteAction) 35 } 36 37 TimelineKind::Profile(pubkey) => { 38 if depth > 1 { 39 render_profile_route(pubkey, timeline_cache, col, ui, note_options, note_context) 40 } else { 41 // we render profiles like timelines if they are at the root 42 let resp = 43 ui::TimelineView::new(kind, timeline_cache, note_context, note_options, col) 44 .scroll_to_top(scroll_to_top) 45 .ui(ui); 46 47 resp.map_output(RenderNavAction::NoteAction) 48 } 49 } 50 } 51 } 52 53 #[allow(clippy::too_many_arguments)] 54 pub fn render_thread_route( 55 threads: &mut Threads, 56 selection: &ThreadSelection, 57 col: usize, 58 mut note_options: NoteOptions, 59 ui: &mut egui::Ui, 60 note_context: &mut NoteContext, 61 ) -> DragResponse<RenderNavAction> { 62 // don't truncate thread notes for now, since they are 63 // default truncated everywher eelse 64 note_options.set(NoteOptions::Truncate, false); 65 66 // We need the reply lines in threads 67 note_options.set(NoteOptions::Wide, false); 68 69 ui::ThreadView::new( 70 threads, 71 selection.selected_or_root(), 72 note_options, 73 note_context, 74 col, 75 ) 76 .ui(ui) 77 .map_output(RenderNavAction::NoteAction) 78 } 79 80 #[allow(clippy::too_many_arguments)] 81 pub fn render_profile_route( 82 pubkey: &Pubkey, 83 timeline_cache: &mut TimelineCache, 84 col: usize, 85 ui: &mut egui::Ui, 86 note_options: NoteOptions, 87 note_context: &mut NoteContext, 88 ) -> DragResponse<RenderNavAction> { 89 let profile_view = 90 ProfileView::new(pubkey, col, timeline_cache, note_options, note_context).ui(ui); 91 92 profile_view.map_output_maybe(|action| match action { 93 ui::profile::ProfileViewAction::EditProfile => note_context 94 .accounts 95 .get_full(pubkey) 96 .map(|kp| RenderNavAction::ProfileAction(ProfileAction::Edit(kp.to_full()))), 97 ui::profile::ProfileViewAction::Note(note_action) => { 98 Some(RenderNavAction::NoteAction(note_action)) 99 } 100 ui::profile::ProfileViewAction::Follow(target_key) => Some(RenderNavAction::ProfileAction( 101 ProfileAction::Follow(target_key), 102 )), 103 ui::profile::ProfileViewAction::Unfollow(target_key) => Some( 104 RenderNavAction::ProfileAction(ProfileAction::Unfollow(target_key)), 105 ), 106 ui::profile::ProfileViewAction::Context(profile_context_selection) => Some( 107 RenderNavAction::ProfileAction(ProfileAction::Context(profile_context_selection)), 108 ), 109 ui::profile::ProfileViewAction::ShowFollowing(pubkey) => { 110 Some(RenderNavAction::ShowFollowing(pubkey)) 111 } 112 ui::profile::ProfileViewAction::ShowFollowers(pubkey) => { 113 Some(RenderNavAction::ShowFollowers(pubkey)) 114 } 115 }) 116 }