Skip to content

Commit

Permalink
Remove unnecessary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lusingander committed May 20, 2024
1 parent b924977 commit 87a1c34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
22 changes: 8 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ impl App {
self.app_objects.get_bucket_items()
}

fn current_object_items(&self) -> Vec<ObjectItem> {
fn current_object_items(&self) -> Option<Vec<ObjectItem>> {
self.app_objects
.get_object_items(&self.current_object_key())
}

pub fn bucket_list_move_down(&mut self) {
if self.exists_current_objects() {
let object_list_page =
Page::of_object_list(self.current_object_items(), self.tx.clone());
if let Some(current_object_items) = self.current_object_items() {
// object list has been already loaded
let object_list_page = Page::of_object_list(current_object_items, self.tx.clone());
self.page_stack.push(object_list_page);
} else {
self.tx.send(AppEventType::LoadObjects);
Expand Down Expand Up @@ -195,10 +195,10 @@ impl App {
}
}
ObjectItem::Dir { .. } => {
if self.exists_current_objects() {
if let Some(current_object_items) = self.current_object_items() {
// object list has been already loaded
let object_list_page =
Page::of_object_list(self.current_object_items(), self.tx.clone());
Page::of_object_list(current_object_items, self.tx.clone());
self.page_stack.push(object_list_page);
} else {
self.tx.send(AppEventType::LoadObjects);
Expand All @@ -208,11 +208,6 @@ impl App {
}
}

fn exists_current_objects(&self) -> bool {
self.app_objects
.exists_object_item(&self.current_object_key())
}

pub fn object_list_move_up(&mut self) {
if self.page_stack.len() == 2 /* bucket list and object list */ && self.bucket_items().len() == 1
{
Expand Down Expand Up @@ -243,10 +238,9 @@ impl App {
match result {
Ok(CompleteLoadObjectsResult { items }) => {
self.app_objects
.set_object_items(self.current_object_key().to_owned(), items);
.set_object_items(self.current_object_key().to_owned(), items.clone());

let object_list_page =
Page::of_object_list(self.current_object_items(), self.tx.clone());
let object_list_page = Page::of_object_list(items, self.tx.clone());
self.page_stack.push(object_list_page);
}
Err(e) => {
Expand Down
11 changes: 2 additions & 9 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ impl AppObjects {
self.bucket_items.to_vec()
}

pub fn get_object_items(&self, key: &ObjectKey) -> Vec<ObjectItem> {
self.object_items_map
.get(key)
.unwrap_or(&Vec::new())
.to_vec()
pub fn get_object_items(&self, key: &ObjectKey) -> Option<Vec<ObjectItem>> {
self.object_items_map.get(key).map(|items| items.to_vec())
}

pub fn set_bucket_items(&mut self, items: Vec<BucketItem>) {
Expand All @@ -78,10 +75,6 @@ impl AppObjects {
self.object_items_map.insert(key, items);
}

pub fn exists_object_item(&self, key: &ObjectKey) -> bool {
self.object_items_map.contains_key(key)
}

pub fn get_object_detail(&self, key: &ObjectKey) -> Option<&FileDetail> {
self.detail_map.get(key)
}
Expand Down

0 comments on commit 87a1c34

Please sign in to comment.