Skip to content

Commit

Permalink
move get first router to Columns
Browse files Browse the repository at this point in the history
Signed-off-by: kernelkind <[email protected]>
  • Loading branch information
kernelkind committed Oct 1, 2024
1 parent 57069ff commit 45223db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ impl Columns {
self.columns.push(Column::new(vec![Route::AddColumn]));
}

// Get the first router in the columns if there are columns present.
// Otherwise, create a new column picker and return the router
pub fn get_first_router(&mut self) -> &mut Router<Route> {
if self.columns.is_empty() {
self.new_column_picker();
}
self.columns
.get_mut(0)
.expect("There should be at least one column")
.router_mut()
}

pub fn columns_mut(&mut self) -> &mut Vec<Column> {
&mut self.columns
}
Expand Down
15 changes: 2 additions & 13 deletions src/ui/side_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
colors,
column::{Column, Columns},
imgcache::ImageCache,
route::{Route, Router},
route::Route,
user_account::UserAccount,
Damus,
};
Expand Down Expand Up @@ -163,7 +163,7 @@ impl<'a> DesktopSidePanel<'a> {
}

pub fn perform_action(columns: &mut Columns, action: SidePanelAction) {
let router = get_first_router(columns);
let router = columns.get_first_router();
match action {
SidePanelAction::Panel => {} // TODO
SidePanelAction::Account => {
Expand Down Expand Up @@ -234,17 +234,6 @@ fn settings_button(dark_mode: bool) -> impl Widget {
}
}

fn get_first_router(columns: &mut Columns) -> &mut Router<Route> {
if columns.columns().is_empty() {
columns.new_column_picker();
}
columns
.columns_mut()
.get_mut(0)
.expect("There should be at least one column")
.router_mut()
}

fn add_column_button(dark_mode: bool) -> impl Widget {
let _ = dark_mode;
move |ui: &mut egui::Ui| {
Expand Down

0 comments on commit 45223db

Please sign in to comment.