diff --git a/quotesdb/src/bin/ui/pages/submit.rs b/quotesdb/src/bin/ui/pages/submit.rs index 3084f8f..9e4698b 100644 --- a/quotesdb/src/bin/ui/pages/submit.rs +++ b/quotesdb/src/bin/ui/pages/submit.rs @@ -16,6 +16,10 @@ use yew_router::prelude::*; /// Provides a form for creating a new quote with fields for text, author, /// source, date, tags, and an optional custom auth code. On success, navigates /// directly to the quote detail page and stores the auth code in session storage. +/// +/// On mount, fetches `GET /api/status` to check whether submissions are locked. +/// If locked, the form is hidden and a closed-submissions banner is shown instead. +/// If the status check fails, the form is shown (fail-open behaviour). #[function_component(SubmitPage)] pub fn submit_page() -> Html { let text = use_state(String::new); @@ -27,8 +31,26 @@ pub fn submit_page() -> Html { let submitting = use_state(|| false); let error: UseStateHandle> = use_state(|| None); let turnstile_token: UseStateHandle> = use_state(|| None); + // None = loading, Some(true) = locked, Some(false) = open + let submissions_locked: UseStateHandle> = use_state(|| None); let navigator = use_navigator().unwrap(); + // Check submission lock state on mount. Fail-open: show the form on error. + { + let submissions_locked = submissions_locked.clone(); + use_effect_with((), move |_| { + spawn_local(async move { + match api::get_status().await { + Ok(status) => submissions_locked.set(Some(status.submissions_locked)), + Err(_) => { + // Fail-open: show the form if status check fails. + submissions_locked.set(Some(false)); + } + } + }); + }); + } + // Register the Turnstile callback in the global window object. { let turnstile_token = turnstile_token.clone(); @@ -139,11 +161,16 @@ pub fn submit_page() -> Html {

{ "Submit a Quote" }

- if let Some(err) = (*error).clone() { - - } + if *submissions_locked == Some(true) { +
+

{ "Submissions are currently closed." }

+
+ } else if submissions_locked.is_some() { + if let Some(err) = (*error).clone() { + + } -
+