diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-30 12:07:49 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-30 12:07:51 +0100 |
commit | 4d297d4d8772604ea4170063ad570a4a5e2d9b38 (patch) | |
tree | 3ec8c28f206fd2d7ba1dcf9c3f9997430cccce7b | |
parent | Frontend: Change OSSE component into a struct component (diff) | |
download | OSSE-4d297d4d8772604ea4170063ad570a4a5e2d9b38.tar.gz OSSE-4d297d4d8772604ea4170063ad570a4a5e2d9b38.tar.bz2 OSSE-4d297d4d8772604ea4170063ad570a4a5e2d9b38.zip |
Frontend: Add props to the OSSE Component
We can now set the API endpoint in the props.
-rw-r--r-- | frontend/src/main.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/frontend/src/main.rs b/frontend/src/main.rs index 3567f6f..2052a89 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -65,6 +65,11 @@ pub struct OSSE { pub results: Option<Vec<IndexedResource>>, //TODO: some loading? } +#[derive(Properties, PartialEq)] +pub struct OSSEProps { + pub api_endpoint: String, +} + pub enum OSSEMessage { SearchSubmitted, SearchChanged(String), @@ -73,7 +78,7 @@ pub enum OSSEMessage { impl Component for OSSE { type Message = OSSEMessage; - type Properties = (); + type Properties = OSSEProps; fn create(_ctx: &Context<Self>) -> Self { OSSE { @@ -86,8 +91,9 @@ impl Component for OSSE { match msg { OSSEMessage::SearchSubmitted => { let search_query = self.search_query.clone(); + let api_endpoint = ctx.props().api_endpoint.clone(); ctx.link().send_future(async move { - let endpoint = format!("http://127.0.0.1:4444/search/{}", search_query); + let endpoint = format!("{}/search/{}", api_endpoint, search_query); let fetched_response = Request::get(endpoint.as_str()).send().await.unwrap(); @@ -211,7 +217,7 @@ impl Component for OSSE { fn app() -> Html { html! { <> - <OSSE /> + <OSSE api_endpoint={"http://127.0.0.1:4444"}/> </> } } |