mirror of
https://github.com/damus-io/notedeck.git
synced 2024-10-18 11:13:23 +00:00
nav: fix accounts nav animations
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>
This commit is contained in:
parent
79a447239a
commit
fce82b2b6d
@ -11,6 +11,7 @@ use crate::{
|
||||
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)
|
||||
@ -67,7 +68,7 @@ pub fn render_nav(show_postbox: bool, col: usize, app: &mut Damus, ui: &mut egui
|
||||
}
|
||||
|
||||
if let Some(NavAction::Returned) = nav_response.action {
|
||||
let r = app.columns_mut().column_mut(col).router_mut().go_back();
|
||||
let r = app.columns_mut().column_mut(col).router_mut().pop();
|
||||
if let Some(Route::Timeline(TimelineRoute::Thread(id))) = r {
|
||||
thread_unsubscribe(
|
||||
&app.ndb,
|
||||
@ -77,7 +78,6 @@ pub fn render_nav(show_postbox: bool, col: usize, app: &mut Damus, ui: &mut egui
|
||||
id.bytes(),
|
||||
);
|
||||
}
|
||||
app.columns_mut().column_mut(col).router_mut().returning = false;
|
||||
} else if let Some(NavAction::Navigated) = nav_response.action {
|
||||
app.columns_mut().column_mut(col).router_mut().navigating = false;
|
||||
}
|
||||
|
11
src/route.rs
11
src/route.rs
@ -72,10 +72,21 @@ impl<R: Clone> Router<R> {
|
||||
self.routes.push(route);
|
||||
}
|
||||
|
||||
/// Go back, start the returning process
|
||||
pub fn go_back(&mut self) -> Option<R> {
|
||||
if self.returning || self.routes.len() == 1 {
|
||||
return None;
|
||||
}
|
||||
self.returning = true;
|
||||
self.routes.get(self.routes.len() - 2).cloned()
|
||||
}
|
||||
|
||||
/// Pop a route, should only be called on a NavRespose::Returned reseponse
|
||||
pub fn pop(&mut self) -> Option<R> {
|
||||
if self.routes.len() == 1 {
|
||||
return None;
|
||||
}
|
||||
self.returning = false;
|
||||
self.routes.pop()
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
use egui::{Button, Layout, SidePanel, Vec2, Widget};
|
||||
|
||||
use crate::{
|
||||
account_manager::AccountsRoute,
|
||||
column::Column,
|
||||
route::{Route, Router},
|
||||
ui::profile_preview_controller,
|
||||
@ -89,8 +90,16 @@ impl<'a> DesktopSidePanel<'a> {
|
||||
match action {
|
||||
SidePanelAction::Panel => {} // TODO
|
||||
SidePanelAction::Account => {
|
||||
if router
|
||||
.routes()
|
||||
.iter()
|
||||
.any(|&r| r == Route::Accounts(AccountsRoute::Accounts))
|
||||
{
|
||||
// return if we are already routing to accounts
|
||||
router.go_back();
|
||||
} else {
|
||||
router.route_to(Route::accounts());
|
||||
//app.show_account_switcher = !app.show_account_switcher,
|
||||
}
|
||||
}
|
||||
SidePanelAction::Settings => {} // TODO
|
||||
SidePanelAction::Columns => (), // TODO
|
||||
|
Loading…
Reference in New Issue
Block a user