Skip to content

Commit

Permalink
task(files): Add failed msg to upload failing (#1876)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flemmli97 authored Mar 5, 2024
1 parent 7fc0096 commit 6d37e55
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
2 changes: 2 additions & 0 deletions common/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion common/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 13 additions & 4 deletions kit/src/components/embeds/file_embed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}
Expand Down
24 changes: 14 additions & 10 deletions ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6d37e55

Please sign in to comment.