-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add waiting state to showcase form #1605
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ const PassengerShowcaseForm = () => { | |
video: location.state?.video ?? '' | ||
}); | ||
const [error, setError] = useState(null); | ||
const [submitted, setSubmitted] = useState(false); | ||
const [submitted, setSubmitted] = useState('not-submitted'); // not-submitted, waiting, submitted | ||
|
||
const data = useVideosWithShowcase(); | ||
|
||
|
@@ -158,12 +158,14 @@ const PassengerShowcaseForm = () => { | |
|
||
const onSubmit = async (e) => { | ||
e.preventDefault(); | ||
setSubmitted('waiting'); | ||
|
||
// Check that everything has been filled out | ||
try { | ||
await schema.validate(state, { strict: true }); | ||
} catch (e) { | ||
setError(e.toString().replace('ValidationError: ', '')); | ||
setSubmitted('not-submitted'); | ||
return; | ||
} | ||
|
||
|
@@ -176,6 +178,7 @@ const PassengerShowcaseForm = () => { | |
setError( | ||
'The uploaded image is larger than 500kb. Please upload a JPG or PNG that is maximum 800 pixels wide and 500kb in size.' | ||
); | ||
setSubmitted('not-submitted'); | ||
return; | ||
} | ||
|
||
|
@@ -199,22 +202,25 @@ const PassengerShowcaseForm = () => { | |
}); | ||
const json = await response.json(); | ||
if (response.ok) { | ||
setSubmitted(true); | ||
setSubmitted('submitted'); | ||
setState(defaultState); | ||
} else { | ||
setError( | ||
json.error || | ||
'Oh no! The train broke down. Please contact [email protected] to report the malfunction!' | ||
); | ||
setSubmitted('not-submitted'); | ||
} | ||
} catch (e) { | ||
setError( | ||
'Oh no! The train broke down. Please contact [email protected] to report the malfunction!' | ||
); | ||
setSubmitted('not-submitted'); | ||
} | ||
}; | ||
reader.onerror = function (error) { | ||
setError('Something went wrong parsing your image.'); | ||
setSubmitted('not-submitted'); | ||
}; | ||
}; | ||
|
||
|
@@ -419,7 +425,7 @@ const PassengerShowcaseForm = () => { | |
</span> | ||
</label> | ||
{error && <div className={css.error}>{error}</div>} | ||
{submitted && ( | ||
{submitted === 'submitted' && ( | ||
<div className={css.submitted}> | ||
Thank you for submitting to the Passenger Showcase! Please refresh | ||
the page in order to upload another submission. | ||
|
@@ -429,7 +435,7 @@ const PassengerShowcaseForm = () => { | |
className={css.submitBtn} | ||
onClick={onSubmit} | ||
variant="purple" | ||
disabled={submitted} | ||
disabled={submitted !== 'not-submitted'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit-pick but I find it hard to parse cognitively with the double (triple?) negative. Maybe renaming the variable to submissionState === 'submitted'
disabled = !!submissionState |
||
rainbow> | ||
Submit | ||
</Button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,6 @@ | |
} | ||
} | ||
|
||
.submitBtn:hover { | ||
.submitBtn:hover:not([disabled]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we could actually use |
||
cursor: pointer; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the pseudo class
:disabled
instead of the attributedisabled
? We might not need all the color variants specificity here either.And well done on the negation here, I was wondering why you didn't use
:enabled
initially but this button component is sneaky and can end up being a<button>
or a<Link>
/<a>
tag based on the props passed to it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about this a bit more, and maybe the
:not(:disabled)
bit is too "clever" without a comment? Maybe something like this would be clearer/more self-documenting in the long run.