route.rs (3935B)
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::NoteContext; 10 use notedeck_ui::{jobs::JobsCache, 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 jobs: &mut JobsCache, 22 scroll_to_top: bool, 23 ) -> Option<RenderNavAction> { 24 match kind { 25 TimelineKind::List(_) 26 | TimelineKind::Search(_) 27 | TimelineKind::Algo(_) 28 | TimelineKind::Notifications(_) 29 | TimelineKind::Universe 30 | TimelineKind::Hashtag(_) 31 | TimelineKind::Generic(_) => { 32 let note_action = 33 ui::TimelineView::new(kind, timeline_cache, note_context, note_options, jobs, col) 34 .scroll_to_top(scroll_to_top) 35 .ui(ui); 36 37 note_action.map(RenderNavAction::NoteAction) 38 } 39 40 TimelineKind::Profile(pubkey) => { 41 if depth > 1 { 42 render_profile_route( 43 pubkey, 44 timeline_cache, 45 col, 46 ui, 47 note_options, 48 note_context, 49 jobs, 50 ) 51 } else { 52 // we render profiles like timelines if they are at the root 53 let note_action = ui::TimelineView::new( 54 kind, 55 timeline_cache, 56 note_context, 57 note_options, 58 jobs, 59 col, 60 ) 61 .scroll_to_top(scroll_to_top) 62 .ui(ui); 63 64 note_action.map(RenderNavAction::NoteAction) 65 } 66 } 67 } 68 } 69 70 #[allow(clippy::too_many_arguments)] 71 pub fn render_thread_route( 72 threads: &mut Threads, 73 selection: &ThreadSelection, 74 col: usize, 75 mut note_options: NoteOptions, 76 ui: &mut egui::Ui, 77 note_context: &mut NoteContext, 78 jobs: &mut JobsCache, 79 ) -> Option<RenderNavAction> { 80 // don't truncate thread notes for now, since they are 81 // default truncated everywher eelse 82 note_options.set(NoteOptions::Truncate, false); 83 84 ui::ThreadView::new( 85 threads, 86 selection.selected_or_root(), 87 note_options, 88 note_context, 89 jobs, 90 ) 91 .id_source(col) 92 .ui(ui) 93 .map(Into::into) 94 } 95 96 #[allow(clippy::too_many_arguments)] 97 pub fn render_profile_route( 98 pubkey: &Pubkey, 99 timeline_cache: &mut TimelineCache, 100 col: usize, 101 ui: &mut egui::Ui, 102 note_options: NoteOptions, 103 note_context: &mut NoteContext, 104 jobs: &mut JobsCache, 105 ) -> Option<RenderNavAction> { 106 let profile_view = ProfileView::new( 107 pubkey, 108 col, 109 timeline_cache, 110 note_options, 111 note_context, 112 jobs, 113 ) 114 .ui(ui); 115 116 if let Some(action) = profile_view { 117 match action { 118 ui::profile::ProfileViewAction::EditProfile => note_context 119 .accounts 120 .get_full(pubkey) 121 .map(|kp| RenderNavAction::ProfileAction(ProfileAction::Edit(kp.to_full()))), 122 ui::profile::ProfileViewAction::Note(note_action) => { 123 Some(RenderNavAction::NoteAction(note_action)) 124 } 125 ui::profile::ProfileViewAction::Follow(target_key) => Some( 126 RenderNavAction::ProfileAction(ProfileAction::Follow(target_key)), 127 ), 128 ui::profile::ProfileViewAction::Unfollow(target_key) => Some( 129 RenderNavAction::ProfileAction(ProfileAction::Unfollow(target_key)), 130 ), 131 } 132 } else { 133 None 134 } 135 }