Skip to content

Commit

Permalink
Fix ObjectPreviewPage to have own ObjectKey
Browse files Browse the repository at this point in the history
  • Loading branch information
lusingander committed Sep 9, 2024
1 parent afbf4b6 commit 77f52bd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ impl App {
}

pub fn complete_preview_object(&mut self, result: Result<CompletePreviewObjectResult>) {
let object_detail_page = self.page_stack.current_page().as_object_detail();
let current_object_key = object_detail_page.current_object_key().clone();

match result {
Ok(CompletePreviewObjectResult {
obj,
Expand All @@ -506,6 +509,7 @@ impl App {
file_version_id,
obj,
path,
current_object_key,
self.config.preview.clone(),
self.tx.clone(),
);
Expand Down
54 changes: 47 additions & 7 deletions src/pages/object_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
config::PreviewConfig,
event::{AppEventType, Sender},
key_code, key_code_char,
object::{FileDetail, RawObject},
object::{FileDetail, ObjectKey, RawObject},
pages::util::{build_helps, build_short_helps},
widget::{InputDialog, InputDialogState, TextPreview, TextPreviewState},
};
Expand All @@ -21,6 +21,7 @@ pub struct ObjectPreviewPage {
file_version_id: Option<String>,
object: RawObject,
path: String,
object_key: ObjectKey,

view_state: ViewState,

Expand All @@ -40,6 +41,7 @@ impl ObjectPreviewPage {
file_version_id: Option<String>,
object: RawObject,
path: String,
object_key: ObjectKey,
preview_config: PreviewConfig,
tx: Sender,
) -> Self {
Expand All @@ -54,6 +56,7 @@ impl ObjectPreviewPage {
file_detail,
file_version_id,
path,
object_key,
view_state: ViewState::Default,
tx,
}
Expand Down Expand Up @@ -218,6 +221,10 @@ impl ObjectPreviewPage {
version_id,
));
}

pub fn current_object_key(&self) -> &ObjectKey {
&self.object_key
}
}

#[cfg(test)]
Expand Down Expand Up @@ -250,9 +257,20 @@ mod tests {
];
let object = object(&preview);
let file_path = "file.txt".to_string();
let object_key = ObjectKey {
bucket_name: "test-bucket".to_string(),
object_path: vec![file_path.clone()],
};
let preview_config = PreviewConfig::default();
let mut page =
ObjectPreviewPage::new(file_detail, None, object, file_path, preview_config, tx);
let mut page = ObjectPreviewPage::new(
file_detail,
None,
object,
file_path,
object_key,
preview_config,
tx,
);
let area = Rect::new(0, 0, 30, 10);
page.render(f, area);
})?;
Expand Down Expand Up @@ -289,9 +307,20 @@ mod tests {
let preview = ["Hello, world!"; 20];
let object = object(&preview);
let file_path = "file.txt".to_string();
let object_key = ObjectKey {
bucket_name: "test-bucket".to_string(),
object_path: vec![file_path.clone()],
};
let preview_config = PreviewConfig::default();
let mut page =
ObjectPreviewPage::new(file_detail, None, object, file_path, preview_config, tx);
let mut page = ObjectPreviewPage::new(
file_detail,
None,
object,
file_path,
object_key,
preview_config,
tx,
);
let area = Rect::new(0, 0, 30, 10);
page.render(f, area);
})?;
Expand Down Expand Up @@ -333,9 +362,20 @@ mod tests {
];
let object = object(&preview);
let file_path = "file.txt".to_string();
let object_key = ObjectKey {
bucket_name: "test-bucket".to_string(),
object_path: vec![file_path.clone()],
};
let preview_config = PreviewConfig::default();
let mut page =
ObjectPreviewPage::new(file_detail, None, object, file_path, preview_config, tx);
let mut page = ObjectPreviewPage::new(
file_detail,
None,
object,
file_path,
object_key,
preview_config,
tx,
);
page.open_save_dialog();
let area = Rect::new(0, 0, 30, 10);
page.render(f, area);
Expand Down
2 changes: 2 additions & 0 deletions src/pages/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Page {
file_version_id: Option<String>,
object: RawObject,
path: String,
object_key: ObjectKey,
preview_config: PreviewConfig,
tx: Sender,
) -> Self {
Expand All @@ -74,6 +75,7 @@ impl Page {
file_version_id,
object,
path,
object_key,
preview_config,
tx,
)))
Expand Down

0 comments on commit 77f52bd

Please sign in to comment.