Skip to content

Commit

Permalink
fix: clear notification panics (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-avb authored Aug 19, 2024
1 parent ca735c0 commit 90abb3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ web-sys = { version = "0.3.69", features = [
"Navigator",
"DomRect",
] }
gloo = "0.11.0"
gloo = { version = "0.11.0", features = ["timers", "futures"] }
infer = "0.15.0"
mime = "0.3.17"
futures-util = "0.3.30"
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/use_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ pub struct UseNotificationState {
inner: Signal<NotificationItem>,
}

use gloo::timers::future::TimeoutFuture;
impl UseNotificationState {
pub fn get(&self) -> NotificationItem {
self.inner.read().clone()
}

pub fn handle_notification(&mut self, item: NotificationItem) {
let mut this = self.clone();
let mut inner = self.inner.clone();
*inner.write() = item;

gloo::timers::callback::Timeout::new(3000, move || this.clear()).forget();
use_future(move || async move {
TimeoutFuture::new(3000).await;
*inner.write() = NotificationItem::default();
});
}

pub fn handle_success(&mut self, body: &str) {
Expand Down

0 comments on commit 90abb3e

Please sign in to comment.