notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

nav.rs (2959B)


      1 use crate::{
      2     account_manager::render_accounts_route,
      3     relay_pool_manager::RelayPoolManager,
      4     route::Route,
      5     thread::thread_unsubscribe,
      6     timeline::route::{render_timeline_route, TimelineRoute, TimelineRouteResponse},
      7     ui::{note::PostAction, RelayView, View},
      8     Damus,
      9 };
     10 
     11 use egui_nav::{Nav, NavAction};
     12 
     13 pub fn render_nav(show_postbox: bool, col: usize, app: &mut Damus, ui: &mut egui::Ui) {
     14     // TODO(jb55): clean up this router_mut mess by using Router<R> in egui-nav directly
     15     let nav_response = Nav::new(app.columns().column(col).router().routes().clone())
     16         .navigating(app.columns_mut().column_mut(col).router_mut().navigating)
     17         .returning(app.columns_mut().column_mut(col).router_mut().returning)
     18         .title(false)
     19         .show_mut(ui, |ui, nav| match nav.top() {
     20             Route::Timeline(tlr) => render_timeline_route(
     21                 &app.ndb,
     22                 &mut app.columns,
     23                 &mut app.pool,
     24                 &mut app.drafts,
     25                 &mut app.img_cache,
     26                 &mut app.note_cache,
     27                 &mut app.threads,
     28                 &mut app.accounts,
     29                 *tlr,
     30                 col,
     31                 show_postbox,
     32                 app.textmode,
     33                 ui,
     34             ),
     35             Route::Accounts(amr) => {
     36                 render_accounts_route(
     37                     ui,
     38                     &app.ndb,
     39                     col,
     40                     &mut app.columns,
     41                     &mut app.img_cache,
     42                     &mut app.accounts,
     43                     &mut app.view_state.login,
     44                     *amr,
     45                 );
     46                 None
     47             }
     48             Route::Relays => {
     49                 let manager = RelayPoolManager::new(app.pool_mut());
     50                 RelayView::new(manager).ui(ui);
     51                 None
     52             }
     53         });
     54 
     55     if let Some(reply_response) = nav_response.inner {
     56         // start returning when we're finished posting
     57         match reply_response {
     58             TimelineRouteResponse::Post(resp) => {
     59                 if let Some(action) = resp.action {
     60                     match action {
     61                         PostAction::Post(_) => {
     62                             app.columns_mut().column_mut(col).router_mut().returning = true;
     63                         }
     64                     }
     65                 }
     66             }
     67         }
     68     }
     69 
     70     if let Some(NavAction::Returned) = nav_response.action {
     71         let r = app.columns_mut().column_mut(col).router_mut().pop();
     72         if let Some(Route::Timeline(TimelineRoute::Thread(id))) = r {
     73             thread_unsubscribe(
     74                 &app.ndb,
     75                 &mut app.threads,
     76                 &mut app.pool,
     77                 &mut app.note_cache,
     78                 id.bytes(),
     79             );
     80         }
     81     } else if let Some(NavAction::Navigated) = nav_response.action {
     82         app.columns_mut().column_mut(col).router_mut().navigating = false;
     83     }
     84 }