@ -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 < Option < String > > = use_state ( | | None ) ;
let turnstile_token : UseStateHandle < Option < String > > = use_state ( | | None ) ;
// None = loading, Some(true) = locked, Some(false) = open
let submissions_locked : UseStateHandle < Option < bool > > = 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 {
< div class = "page-submit" >
< h1 class = "page-submit__title" > { "Submit a Quote" } < / h1 >
if let Some ( err ) = ( * error ) . clone ( ) {
< ErrorDisplay message = { err } / >
}
if * submissions_locked = = Some ( true ) {
< div class = "submissions-closed-banner" >
< p > { "Submissions are currently closed." } < / p >
< / div >
} else if submissions_locked . is_some ( ) {
if let Some ( err ) = ( * error ) . clone ( ) {
< ErrorDisplay message = { err } / >
}
< form class = "submit-form" onsubmit = { onsubmit } >
< form class = "submit-form" onsubmit = { onsubmit } >
< div class = "submit-form__field" >
< label class = "submit-form__label" for = "text" > { "Quote text *" } < / label >
< textarea
@ -274,7 +301,8 @@ pub fn submit_page() -> Html {
}
< / button >
< / div >
< / form >
< / form >
}
< / div >
}
}