Skip to content

Commit

Permalink
refactor(Files): Hide download status toast notification if download …
Browse files Browse the repository at this point in the history
…is to preview the file
  • Loading branch information
lgmarchi committed Jan 11, 2024
1 parent 7bace92 commit ae88525
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions ui/src/layouts/storage/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ pub fn download_file(
None => return,
}
} else {
temp_path_to_download_file_to_preview.unwrap_or_default()
temp_path_to_download_file_to_preview
.clone()
.unwrap_or_default()
};

ch.send(ChanCmd::DownloadFile {
file_name: file_name.to_string(),
local_path_to_save_file: file_path_buf,
notification_download_status: temp_path_to_download_file_to_preview.is_none(),
});
}

Expand Down Expand Up @@ -226,6 +229,7 @@ pub enum ChanCmd {
DownloadFile {
file_name: String,
local_path_to_save_file: PathBuf,
notification_download_status: bool,
},
RenameItem {
old_name: String,
Expand Down Expand Up @@ -344,6 +348,7 @@ pub fn init_coroutine<'a>(
ChanCmd::DownloadFile {
file_name,
local_path_to_save_file,
notification_download_status,
} => {
let (local_path_to_save_file, on_finish) =
get_download_path(local_path_to_save_file);
Expand All @@ -356,49 +361,55 @@ pub fn init_coroutine<'a>(
rsp: tx,
},
)) {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text_with_args(
"files.download-failed",
vec![("file", file_name)],
),
None,
2,
),
));
log::error!("failed to download file {}", e);
continue;
}

let rsp = rx.await.expect("command canceled");
match rsp {
Ok(_) => {
if notification_download_status {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text_with_args(
"files.download-success",
"files.download-failed",
vec![("file", file_name)],
),
None,
2,
),
));
}
log::error!("failed to download file {}", e);
continue;
}

let rsp = rx.await.expect("command canceled");
match rsp {
Ok(_) => {
if notification_download_status {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text_with_args(
"files.download-success",
vec![("file", file_name)],
),
None,
2,
),
));
}
on_finish.await
}
Err(error) => {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text_with_args(
"files.download-failed",
vec![("file", file_name)],
if notification_download_status {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text_with_args(
"files.download-failed",
vec![("file", file_name)],
),
None,
2,
),
None,
2,
),
));
));
}
log::error!("failed to download file: {}", error);
on_finish.await;
continue;
Expand Down

0 comments on commit ae88525

Please sign in to comment.