Skip to content

Commit

Permalink
Extract app function
Browse files Browse the repository at this point in the history
  • Loading branch information
lusingander committed Dec 30, 2024
1 parent 6bba16b commit 9d7e698
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
18 changes: 18 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,24 @@ impl App {
object_preview_page.enable_image_render();
}

pub fn breadcrumb(&self) -> Vec<String> {
let mut target_pages: Vec<&Page> = self
.page_stack
.iter()
.filter(|page| matches!(page, Page::BucketList(_) | Page::ObjectList(_)))
.collect();
target_pages.pop(); // Remove the last item (current page)

target_pages
.iter()
.map(|page| match page {
Page::BucketList(page) => page.current_selected_item().name.clone(),
Page::ObjectList(page) => page.current_selected_item().name().into(),
_ => unreachable!(),
})
.collect()
}

pub fn copy_to_clipboard(&self, name: String, value: String) {
match copy_to_clipboard(value) {
Ok(_) => {
Expand Down
26 changes: 3 additions & 23 deletions src/ui/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ fn render_background(f: &mut Frame, area: Rect, app: &App) {
}

fn render_header(f: &mut Frame, area: Rect, app: &App) {
if area.is_empty() {
return;
if !area.is_empty() {
let header = Header::new(app.breadcrumb()).theme(app.theme());
f.render_widget(header, area);
}
let header = build_header(app);
f.render_widget(header, area);
}

fn render_content(f: &mut Frame, area: Rect, app: &mut App) {
Expand Down Expand Up @@ -84,25 +83,6 @@ fn render_loading_dialog(f: &mut Frame, app: &App) {
}
}

fn build_header(app: &App) -> Header {
let mut target_pages: Vec<&Page> = app
.page_stack
.iter()
.filter(|page| matches!(page, Page::BucketList(_) | Page::ObjectList(_)))
.collect();
target_pages.pop(); // Remove the last item (current page)

let breadcrumb: Vec<String> = target_pages
.iter()
.map(|page| match page {
Page::BucketList(page) => page.current_selected_item().name.clone(),
Page::ObjectList(page) => page.current_selected_item().name().into(),
_ => unreachable!(),
})
.collect();
Header::new(breadcrumb).theme(app.theme())
}

fn build_short_help(app: &App, width: u16) -> Paragraph {
let helps = app.page_stack.current_page().short_helps();
let pad = Padding::horizontal(2);
Expand Down

0 comments on commit 9d7e698

Please sign in to comment.