From 4d297d4d8772604ea4170063ad570a4a5e2d9b38 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sun, 30 Oct 2022 12:07:49 +0100 Subject: Frontend: Add props to the OSSE Component We can now set the API endpoint in the props. --- frontend/src/main.rs | 12 +++++++++--- 1 file 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>, //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 { 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! { <> - + } } -- cgit 1.4.1