Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task(files): Add failed msg to upload failing #1876

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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 @@ -1262,10 +1262,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 @@ -505,18 +505,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
Loading