forked from yewstack/yew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
63 lines (49 loc) · 1.6 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use web_sys::HtmlTextAreaElement;
use yew::prelude::*;
use log::Level;
mod use_sleep;
use use_sleep::use_sleep;
#[function_component(PleaseWait)]
fn please_wait() -> Html {
html! {<div class="content-area">{"Please wait 5 Seconds..."}</div>}
}
#[function_component(AppContent)]
fn app_content() -> HtmlResult {
let resleep = use_sleep()?;
let value = use_state(|| "I am writing a long story...".to_string());
let on_text_input = {
let value = value.clone();
Callback::from(move |e: InputEvent| {
let input: HtmlTextAreaElement = e.target_unchecked_into();
value.set(input.value());
})
};
let on_take_a_break = Callback::from(move |_| (resleep.clone())());
Ok(html! {
<div class="content-area">
<textarea value={value.to_string()} oninput={on_text_input}></textarea>
<div class="action-area">
<button onclick={on_take_a_break}>{"Take a break!"}</button>
<div class="hint">{"You can take a break at anytime"}<br />{"and your work will be preserved."}</div>
</div>
</div>
})
}
#[function_component(App)]
fn app() -> Html {
let fallback = html! {<PleaseWait />};
html! {
<div class="layout">
<div class="content">
<h1>{"Yew Suspense Demo"}</h1>
<Suspense fallback={fallback}>
<AppContent />
</Suspense>
</div>
</div>
}
}
fn main() {
console_log::init_with_level(Level::Trace).expect("Failed to initialise Log!");
yew::start_app::<App>();
}