diff options
Diffstat (limited to 'corp')
-rw-r--r-- | corp/rih/src/home.html | 3 | ||||
-rw-r--r-- | corp/rih/src/main.rs | 43 |
2 files changed, 35 insertions, 11 deletions
diff --git a/corp/rih/src/home.html b/corp/rih/src/home.html index 95a77877d317..7f1ff5f332a2 100644 --- a/corp/rih/src/home.html +++ b/corp/rih/src/home.html @@ -1,12 +1,13 @@ html! { <main> <script> - {r#"function captchaOnload(sitekey) { + {r#"function captchaOnload(sitekey, callback) { if (window.smartCaptcha) { const container = document.getElementById('captcha-container'); const widgetId = window.smartCaptcha.render(container, { sitekey: sitekey, hl: 'en', + callback: callback, }); } }"#} diff --git a/corp/rih/src/main.rs b/corp/rih/src/main.rs index 2fed9dfd8f4a..a419e2d9bfc8 100644 --- a/corp/rih/src/main.rs +++ b/corp/rih/src/main.rs @@ -98,7 +98,6 @@ struct Record { work_background: String, } -#[derive(Default)] struct App { // The record being populated. record: Record, @@ -111,6 +110,13 @@ struct App { // History handler. history: BrowserHistory, + + // Captcha token, if the captcha has been solved. + captcha_token: Option<String>, + + // Captcha callback closure which needs to be kept alive for the + // lifecycle of the app. + captcha_callback: Closure<dyn FnMut(String)>, } #[derive(Clone, Debug)] @@ -130,6 +136,7 @@ enum Msg { SetPosition(String), SetJobDetails(String), SetWorkBackground(String), + CaptchaSolved(String), } /// Callback handler for adding a technology. @@ -293,14 +300,20 @@ impl Component for App { type Message = Msg; type Properties = (); - fn create(_ctx: &Context<Self>) -> Self { - let mut new = Self::default(); - - if let Ok(record) = LocalStorage::get("record") { - new.record = record; + fn create(ctx: &Context<Self>) -> Self { + App { + record: LocalStorage::get("record").unwrap_or_default(), + citizenship_focus: false, + citizenship_query: String::default(), + history: BrowserHistory::default(), + captcha_token: None, + captcha_callback: { + let link = ctx.link().clone(); + Closure::wrap(Box::new(move |val| { + link.send_message(Msg::CaptchaSolved(val)); + })) + }, } - - new } fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool { @@ -369,6 +382,11 @@ impl Component for App { self.record.work_background = background; (true, false) } + + Msg::CaptchaSolved(token) => { + self.captcha_token = Some(token); + (false, true) + } }; if state_change { @@ -399,8 +417,13 @@ impl Component for App { fn rendered(&mut self, _: &Context<Self>, first_render: bool) { if first_render { - let func = js_sys::Function::new_with_args("key", "captchaOnload(key)"); - let _ = func.call1(&JsValue::NULL, &JsValue::from_str(CAPTCHA_KEY)); + let func = + js_sys::Function::new_with_args("key, callback", "captchaOnload(key, callback)"); + let _ = func.call2( + &JsValue::NULL, + &JsValue::from_str(CAPTCHA_KEY), + &self.captcha_callback.as_ref().unchecked_ref(), + ); } } } |