diff --git a/common/locales/en-US/main.ftl b/common/locales/en-US/main.ftl index abfb659cd74..fba3a452bf3 100644 --- a/common/locales/en-US/main.ftl +++ b/common/locales/en-US/main.ftl @@ -109,6 +109,8 @@ messages = Messages .username-suggestion = Suggested Users .control-group = More .no-chats = No chats available + .attachments-fail = Upload Failed! + .attachments-fail-msg = Upload failed: { $reason } favorites = Favorites .favorites = Favorites diff --git a/common/src/state/mod.rs b/common/src/state/mod.rs index fbd58ac6b02..d8f7187fb22 100644 --- a/common/src/state/mod.rs +++ b/common/src/state/mod.rs @@ -1263,10 +1263,32 @@ impl State { conv_id: Uuid, msg: PendingMessage, progress: Progression, - ) { + ) -> bool { + let mut update = false; + if let Progression::ProgressFailed { + name, + last_size: _, + error, + } = &progress + { + let err = match error.as_ref() { + Some(err) => { + get_local_text_with_args("messages.attachments-fail-msg", vec![("reason", err)]) + } + None => get_local_text("messages.attachments-fail"), + }; + self.mutate(Action::AddToastNotification(ToastNotification::init( + name.clone(), + err, + None, + 2, + ))); + update = true; + } if let Some(chat) = self.chats.all.get_mut(&conv_id) { chat.update_pending_msg(msg, progress); } + update } pub fn decrement_outgoing_messagess( diff --git a/kit/src/components/embeds/file_embed/mod.rs b/kit/src/components/embeds/file_embed/mod.rs index 59271fc8b3f..e2bcff66f2b 100644 --- a/kit/src/components/embeds/file_embed/mod.rs +++ b/kit/src/components/embeds/file_embed/mod.rs @@ -7,12 +7,13 @@ 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; +use common::language::get_local_text_with_args; use common::return_correct_icon; use common::utils::local_file_path::get_fixed_path_to_load_local_file; use common::STATIC_ARGS; -use dioxus_html::input_data::keyboard_types::Modifiers; - use dioxus::prelude::*; +use dioxus_html::input_data::keyboard_types::Modifiers; use humansize::format_size; use humansize::DECIMAL; @@ -127,9 +128,17 @@ pub fn FileEmbed<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> { Progression::ProgressFailed { name: _, last_size: _, - error: _, + error, } => { - file_size_pending.push_str("Failed"); + match error.as_ref() { + Some(err) => file_size_pending.push_str(&get_local_text_with_args( + "messages.attachments-fail-msg", + vec![("reason", err)], + )), + None => { + file_size_pending.push_str(&get_local_text("messages.attachments-fail")) + } + }; 0 } } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index d3b4907ef5f..e7481df3494 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -508,18 +508,22 @@ fn use_app_coroutines(cx: &ScopeState) -> Option<()> { msg, }) = evt { - state + if state .write_silent() - .update_outgoing_messages(conversation_id, msg, progress); - let read = state.read(); - if read - .get_active_chat() - .map(|c| c.id.eq(&conversation_id)) - .unwrap_or_default() + .update_outgoing_messages(conversation_id, msg, progress) { - //Update the component only instead of whole state - if let Some(v) = read.scope_ids.pending_message_component { - schedule(ScopeId(v)) + state.write(); + } else { + let read = state.read(); + if read + .get_active_chat() + .map(|c| c.id.eq(&conversation_id)) + .unwrap_or_default() + { + //Update the component only instead of whole state + if let Some(v) = read.scope_ids.pending_message_component { + schedule(ScopeId(v)) + } } } } else {