mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-21 01:04:19 +01:00
also make nav go backward when clicking the account switch button if we already are navigating to accounts Signed-off-by: William Casarin <jb55@jb55.com>
85 lines
2.9 KiB
Rust
85 lines
2.9 KiB
Rust
use crate::{
|
|
account_manager::render_accounts_route,
|
|
relay_pool_manager::RelayPoolManager,
|
|
route::Route,
|
|
thread::thread_unsubscribe,
|
|
timeline::route::{render_timeline_route, TimelineRoute, TimelineRouteResponse},
|
|
ui::{note::PostAction, RelayView, View},
|
|
Damus,
|
|
};
|
|
|
|
use egui_nav::{Nav, NavAction};
|
|
|
|
pub fn render_nav(show_postbox: bool, col: usize, app: &mut Damus, ui: &mut egui::Ui) {
|
|
// TODO(jb55): clean up this router_mut mess by using Router<R> in egui-nav directly
|
|
let nav_response = Nav::new(app.columns().column(col).router().routes().clone())
|
|
.navigating(app.columns_mut().column_mut(col).router_mut().navigating)
|
|
.returning(app.columns_mut().column_mut(col).router_mut().returning)
|
|
.title(false)
|
|
.show_mut(ui, |ui, nav| match nav.top() {
|
|
Route::Timeline(tlr) => render_timeline_route(
|
|
&app.ndb,
|
|
&mut app.columns,
|
|
&mut app.pool,
|
|
&mut app.drafts,
|
|
&mut app.img_cache,
|
|
&mut app.note_cache,
|
|
&mut app.threads,
|
|
&mut app.accounts,
|
|
*tlr,
|
|
col,
|
|
show_postbox,
|
|
app.textmode,
|
|
ui,
|
|
),
|
|
Route::Accounts(amr) => {
|
|
render_accounts_route(
|
|
ui,
|
|
&app.ndb,
|
|
col,
|
|
&mut app.columns,
|
|
&mut app.img_cache,
|
|
&mut app.accounts,
|
|
&mut app.view_state.login,
|
|
*amr,
|
|
);
|
|
None
|
|
}
|
|
Route::Relays => {
|
|
let manager = RelayPoolManager::new(app.pool_mut());
|
|
RelayView::new(manager).ui(ui);
|
|
None
|
|
}
|
|
});
|
|
|
|
if let Some(reply_response) = nav_response.inner {
|
|
// start returning when we're finished posting
|
|
match reply_response {
|
|
TimelineRouteResponse::Post(resp) => {
|
|
if let Some(action) = resp.action {
|
|
match action {
|
|
PostAction::Post(_) => {
|
|
app.columns_mut().column_mut(col).router_mut().returning = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if let Some(NavAction::Returned) = nav_response.action {
|
|
let r = app.columns_mut().column_mut(col).router_mut().pop();
|
|
if let Some(Route::Timeline(TimelineRoute::Thread(id))) = r {
|
|
thread_unsubscribe(
|
|
&app.ndb,
|
|
&mut app.threads,
|
|
&mut app.pool,
|
|
&mut app.note_cache,
|
|
id.bytes(),
|
|
);
|
|
}
|
|
} else if let Some(NavAction::Navigated) = nav_response.action {
|
|
app.columns_mut().column_mut(col).router_mut().navigating = false;
|
|
}
|
|
}
|