From 2a558e17ed61a812ac779a34dd41541813117a40 Mon Sep 17 00:00:00 2001 From: Marlon Baeten Date: Tue, 22 Aug 2023 12:14:21 +0200 Subject: [PATCH] Stay on the last selected tab when available --- frontend/src/overview.rs | 2 +- frontend/src/view.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/overview.rs b/frontend/src/overview.rs index e341c34..f9f43b3 100644 --- a/frontend/src/overview.rs +++ b/frontend/src/overview.rs @@ -86,7 +86,7 @@ impl Component for Overview { .iter_mut() .find(|m| m.id == self.selected && !m.opened); - if let Some(mut unopened_message) = unopened { + if let Some(unopened_message) = unopened { if self.sender.try_send(Action::Open(id)).is_err() { error!("Error registering email as opened"); } diff --git a/frontend/src/view.rs b/frontend/src/view.rs index f0964a7..1f4f4a3 100644 --- a/frontend/src/view.rs +++ b/frontend/src/view.rs @@ -28,15 +28,17 @@ pub fn view(props: &ViewMessageProps) -> Html { let id = props.message.id.clone(); let set_tab = props.set_tab.clone(); let inner_message = message.clone(); + let current_tab = props.active_tab.clone(); use_effect_with_deps( |message_id| { let message_id = message_id.clone(); spawn_local(async move { let message = fetch_message(&message_id).await; - if message.html.is_empty() { + if message.html.is_empty() && current_tab == Tab::Formatted { set_tab.emit(Tab::Text) - } else { - set_tab.emit(Tab::Formatted) + } + if message.text.is_empty() && current_tab == Tab::Text { + set_tab.emit(Tab::Formatted); } inner_message.set(message); });