Skip to content

Commit

Permalink
improve upload error msg for storage limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Flemmli97 committed Mar 7, 2024
1 parent 4c69090 commit 1ed6a14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions common/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ messages = Messages
.no-chats = No chats available
.attachments-fail = Upload Failed!
.attachments-fail-msg = Upload failed: { $reason }
.attachments-fail-no-storage = No more storage left!
favorites = Favorites
.favorites = Favorites
Expand Down
23 changes: 19 additions & 4 deletions common/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,10 +1270,7 @@ impl State {
error,
} = &progress
{
let err = get_local_text_with_args(
"messages.attachments-fail-msg",
vec![("reason", error.to_string())],
);
let err = get_upload_error_text(error);
self.mutate(Action::AddToastNotification(ToastNotification::init(
name.clone(),
err,
Expand Down Expand Up @@ -1960,3 +1957,21 @@ pub fn pending_group_messages<'a>(
messages,
})
}

pub fn get_upload_error_text(err: &warp::error::Error) -> String {
match err {
warp::error::Error::InvalidLength {
context: _,
current: _,
minimum: _,
maximum: _,
} => get_local_text_with_args(
"messages.attachments-fail-msg",
vec![(
"reason",
get_local_text("messages.attachments-fail-no-storage"),
)],
),
_ => get_local_text("messages.attachments-fail"),
}
}
7 changes: 2 additions & 5 deletions kit/src/components/embeds/file_embed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use common::icons::outline::Shape as Icon;
use common::icons::Icon as IconElement;
use common::is_file_available_to_preview;
use common::is_video;
use common::language::get_local_text_with_args;
use common::return_correct_icon;
use common::state::get_upload_error_text;
use common::state::pending_message::FileProgression;
use common::utils::local_file_path::get_fixed_path_to_load_local_file;
use common::STATIC_ARGS;
Expand Down Expand Up @@ -129,10 +129,7 @@ pub fn FileEmbed<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
last_size: _,
error,
} => {
file_size_pending.push_str(&get_local_text_with_args(
"messages.attachments-fail-msg",
vec![("reason", error.to_string())],
));
file_size_pending.push_str(&get_upload_error_text(error));
0
}
}
Expand Down

0 comments on commit 1ed6a14

Please sign in to comment.