blob: e449e4a1af90deb8e778dc6b0da1b20b9a838bf7 (
plain) (
blame)
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
|
mod app;
use app::OSSE;
use web_sys::window;
use yew::prelude::*;
use yew_router::prelude::*;
#[derive(Clone, Routable, PartialEq)]
enum Route {
#[at("/")]
OSSEHome,
#[at("/search/")]
OSSEHomeEmptySearch,
#[at("/search/:query")]
OSSESearch { query: String },
}
fn switch_routes(routes: Route) -> Html {
let location = window().unwrap().location();
let api_endpoint = format!(
"{}//{}:{}/api",
location.protocol().unwrap(),
location.hostname().unwrap(),
4444
);
match routes {
Route::OSSEHome | Route::OSSEHomeEmptySearch => html! {
<OSSE api_endpoint={api_endpoint} initial_search_query={None as Option<String>} />
},
Route::OSSESearch { query } => html! {
<OSSE api_endpoint={api_endpoint} initial_search_query={Some(query)} />
},
}
}
#[function_component(App)]
fn yew_app() -> Html {
html! {
<>
<BrowserRouter>
<Switch<Route> render={switch_routes} />
</BrowserRouter>
</>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}
|