Skip to content

Commit 8fcf40e

Browse files
committed
fix ci
1 parent 2f51a70 commit 8fcf40e

5 files changed

Lines changed: 33 additions & 6 deletions

File tree

crates/yew-hooks/src/hooks/use_permission.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::use_effect_once;
2323
/// html! {
2424
/// <>
2525
/// <b>{ " state: " }</b>
26-
/// { state.to_string() }
26+
/// { format!("{state:?}") }
2727
/// </>
2828
/// }
2929
/// }
@@ -39,20 +39,20 @@ pub fn use_permission(name: String) -> UseStateHandle<Option<PermissionState>> {
3939
let state = state.clone();
4040

4141
spawn_local(async move {
42-
let permissions = window().navigator().permissions().unwrap();
42+
let permissions = window().navigator().permissions().unwrap_throw();
4343

4444
let obj = Object::new();
45-
Reflect::set(&obj, &"name".into(), &name.into()).unwrap();
45+
Reflect::set(&obj, &"name".into(), &name.into()).unwrap_throw();
4646

47-
let fut = JsFuture::from(permissions.query(&obj).unwrap());
48-
let stat = PermissionStatus::from(fut.await.unwrap());
47+
let fut = JsFuture::from(permissions.query(&obj).unwrap_throw());
48+
let stat = PermissionStatus::from(fut.await.unwrap_throw());
4949

5050
let onchange = {
5151
let state = state.clone();
5252

5353
Closure::wrap(Box::new(move |event: Event| {
5454
if let Some(target) = event.target() {
55-
let stat: PermissionStatus = target.dyn_into().unwrap();
55+
let stat: PermissionStatus = target.dyn_into().unwrap_throw();
5656

5757
state.set(Some(stat.state()));
5858
}

examples/yew-app/src/app/home.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub fn home() -> Html {
9191
<li><Link<AppRoute> to={AppRoute::UseSwipe} classes="text-emerald-800 underline" >{ "use_swipe" }</Link<AppRoute>> { " - detects swipe based on TouchEvent." }</li>
9292
<li><Link<AppRoute> to={AppRoute::UseVisible} classes="text-emerald-800 underline" >{ "use_visible" }</Link<AppRoute>> { " - checks if an element is visible." }</li>
9393
<li><Link<AppRoute> to={AppRoute::UseHovered} classes="text-emerald-800 underline" >{ "use_hovered" }</Link<AppRoute>> { " - checks if an element is being hovered." }</li>
94+
<li><Link<AppRoute> to={AppRoute::UsePermission} classes="text-emerald-800 underline" >{ "use_permisson" }</Link<AppRoute>> { " - tracks browser's permission changes using the Permissions API." }</li>
9495
</ul>
9596

9697
<h2 class="text-2xl font-bold">{ "UI" }</h2>

examples/yew-app/src/app/hooks/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod use_measure;
3131
mod use_media;
3232
mod use_mount;
3333
mod use_mut_latest;
34+
mod use_permission;
3435
mod use_previous;
3536
mod use_queue;
3637
mod use_raf;
@@ -90,6 +91,7 @@ pub use use_measure::*;
9091
pub use use_media::*;
9192
pub use use_mount::*;
9293
pub use use_mut_latest::*;
94+
pub use use_permission::*;
9395
pub use use_previous::*;
9496
pub use use_queue::*;
9597
pub use use_raf::*;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use yew::prelude::*;
2+
use yew_hooks::prelude::*;
3+
4+
/// `use_permission` demo
5+
#[function_component]
6+
pub fn UsePermission() -> Html {
7+
let state = use_permission("notifications".to_owned());
8+
9+
html! {
10+
<div class="container">
11+
<header class="mt-24 text-xl text-center">
12+
<div class="space-x-4 space-y-4">
13+
<p>
14+
<b>{ "state: " }</b>
15+
{ format!("{state:?}") }
16+
</p>
17+
</div>
18+
</header>
19+
</div>
20+
}
21+
}

examples/yew-app/src/app/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ pub enum AppRoute {
131131
UseVisible,
132132
#[at("/use_hovered")]
133133
UseHovered,
134+
#[at("/use_permission")]
135+
UsePermission,
134136
#[not_found]
135137
#[at("/page-not-found")]
136138
PageNotFound,
@@ -201,6 +203,7 @@ pub fn switch(routes: AppRoute) -> Html {
201203
AppRoute::UseInfiniteScroll => html! { <UseInfiniteScroll /> },
202204
AppRoute::UseVisible => html! { <UseVisible /> },
203205
AppRoute::UseHovered => html! { <UseHovered /> },
206+
AppRoute::UsePermission => html! { <UsePermission /> },
204207
AppRoute::PageNotFound => html! { <Home /> },
205208
}
206209
}

0 commit comments

Comments
 (0)