Skip to content

Commit

Permalink
Fix update title (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonbaeten authored Apr 11, 2023
1 parent 223dc8d commit 361a957
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
13 changes: 1 addition & 12 deletions frontend/src/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::types::MailMessageMetadata;
use js_sys::Date;
use timeago::Formatter;
use yew::{
function_component, html, html_nested, use_effect, use_state, Callback, Html, Properties,
};
use yew::{function_component, html, html_nested, use_state, Callback, Html, Properties};
use yew_hooks::use_interval;

#[derive(Properties, PartialEq)]
Expand Down Expand Up @@ -32,15 +30,6 @@ pub fn list(props: &MessageListProps) -> Html {
);
}

{
let count = props.messages.iter().filter(|m| !m.opened).count();
use_effect(move || {
gloo_utils::document().set_title(&format!("MailCrab ({})", count));

|| ()
});
}

props
.messages
.iter()
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ impl Component for Overview {
match msg {
Msg::Message(message) => {
self.messages.push(*message);
true
}
Msg::Messages(messages) => {
self.messages = messages;
true
}
Msg::Select(id) => {
self.selected = id.clone();
Expand All @@ -84,31 +82,33 @@ impl Component for Overview {
if self.sender.try_send(Action::Open(id)).is_err() {
error!("Error registering email as opened");
}

unopened_message.opened = true;
}

true
}
Msg::SetTab(tab) => {
self.tab = tab;
true
}
Msg::Remove(id) => {
self.messages.retain(|m| m.id != id);

if self.sender.try_send(Action::Remove(id)).is_err() {
error!("Error removing email");
}

true
}
Msg::RemoveAll => {
if self.sender.try_send(Action::RemoveAll).is_ok() {
self.messages.clear();
}
true
}
}
};

true
}

fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool) {
let count = self.messages.iter().filter(|m| !m.opened).count();
gloo_utils::document().set_title(&format!("MailCrab ({})", count));
}

fn view(&self, ctx: &Context<Self>) -> Html {
Expand Down

0 comments on commit 361a957

Please sign in to comment.