spot/src/app/components/navigation/navigation_model.rs
Théo Barnouin 15cf412840
Some checks are pending
spot-quality / ci-check (push) Waiting to run
spot-quality / shellcheck (push) Waiting to run
first commit
2024-11-13 16:41:51 +01:00

31 lines
838 B
Rust

use crate::app::state::ScreenName;
use crate::app::{ActionDispatcher, AppModel, BrowserAction};
use std::ops::Deref;
use std::rc::Rc;
pub struct NavigationModel {
app_model: Rc<AppModel>,
dispatcher: Box<dyn ActionDispatcher>,
}
impl NavigationModel {
pub fn new(app_model: Rc<AppModel>, dispatcher: Box<dyn ActionDispatcher>) -> Self {
Self {
app_model,
dispatcher,
}
}
pub fn visible_child_name(&self) -> impl Deref<Target = ScreenName> + '_ {
self.app_model.map_state(|s| s.browser.current_screen())
}
pub fn set_nav_hidden(&self, hidden: bool) {
self.dispatcher
.dispatch(BrowserAction::SetNavigationHidden(hidden).into());
}
pub fn children_count(&self) -> usize {
self.app_model.get_state().browser.count()
}
}