| 25 | #[tracing::instrument(level = "debug", skip(key, name, account_id))] |
| 26 | #[component] |
| 27 | pub fn LoginModal( |
| 28 | #[prop()] key: String, |
| 29 | #[prop()] name: String, |
| 30 | account_id: String, |
| 31 | ) -> impl IntoView { |
| 32 | let having_trouble = RwSignal::new(false); |
| 33 | let code = RwSignal::new(String::new()); |
| 34 | let url = RwSignal::new(String::new()); |
| 35 | |
| 36 | let key_cloned = key.clone(); |
| 37 | |
| 38 | let authorize = Action::new_local(move |code: &String| { |
| 39 | let code = code.clone(); |
| 40 | let key = key.clone(); |
| 41 | |
| 42 | async move { provider_authorize(key, code).await } |
| 43 | }); |
| 44 | |
| 45 | spawn_local(async move { |
| 46 | let ret = provider_login(key_cloned, account_id).await.unwrap(); |
| 47 | tracing::debug!("Got login url {}", ret); |
| 48 | url.set(ret); |
| 49 | }); |
| 50 | |
| 51 | let open_external = move |_| { |
| 52 | let url = url.get(); |
| 53 | |
| 54 | #[derive(Serialize)] |
| 55 | struct OpenExternalArgs { |
| 56 | url: String, |
| 57 | } |
| 58 | |
| 59 | spawn_local(async move { |
| 60 | let res = crate::utils::invoke::open_external(url).await; |
| 61 | if let Err(e) = res { |
| 62 | tracing::error!("Failed to open external: {:?}", e); |
| 63 | } |
| 64 | }); |
| 65 | }; |
| 66 | |
| 67 | view! { |
| 68 | <GenericModal size=move || "modal-sm".into()> |
| 69 | <div class="w-100 h-100"> |
| 70 | <div class="container response-container"> |
| 71 | <div class="row no-gutters d-flex"> |
| 72 | <div class="col-auto title">Logging in to</div> |
| 73 | <div class="col-auto title ml-1" style="color: var(--accent)"> |
| 74 | {name} |
| 75 | </div> |
| 76 | </div> |
| 77 | |
| 78 | {move || { |
| 79 | if !having_trouble.get() { |
| 80 | view! { |
| 81 | <div> |
| 82 | <div class="row"> |
| 83 | <div class="col mt-4 waiting"> |
| 84 | Waiting for response from your browser |