Skip to content
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

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/components/Button.module.css
Copy link
Collaborator

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 attribute disabled? We might not need all the color variants specificity here either.

.rainbow:hover:not(:disabled) {
  background-position: left bottom;
  transition: background-position 4s ease-out;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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.

Copy link
Collaborator

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.

a.rainbow, button.rainbow:enabled {
  &:hover {
    background-position: left bottom;
    transition: background-position 4s ease-out;
  }
}

Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,16 @@ button.rainbow.cyan {
transition: background-position 1s ease-out;
}

.rainbow.red:hover,
.rainbow.orange:hover,
.rainbow.purple:hover,
.rainbow.pink:hover,
.rainbow.cyan:hover {
.rainbow.red:hover:not([disabled]),
.rainbow.orange:hover:not([disabled]),
.rainbow.purple:hover:not([disabled]),
.rainbow.pink:hover:not([disabled]),
.rainbow.cyan:hover:not([disabled]) {
background-position: left bottom;
transition: background-position 4s ease-out;
}

button[disabled] {
opacity: 0.5;
cursor: not-allowed;
}
14 changes: 10 additions & 4 deletions src/components/PassengerShowcaseForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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');
};
};

Expand Down Expand Up @@ -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.
Expand All @@ -429,7 +435,7 @@ const PassengerShowcaseForm = () => {
className={css.submitBtn}
onClick={onSubmit}
variant="purple"
disabled={submitted}
disabled={submitted !== 'not-submitted'}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 and finding an alternate name for not-submitted state that doesn't contain a negative would help? What about undefined, would that read better?

submissionState === 'submitted'

disabled = !!submissionState

rainbow>
Submit
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/PassengerShowcaseForm.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
}
}

.submitBtn:hover {
.submitBtn:hover:not([disabled]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could actually use :enabled since it is always a button

cursor: pointer;
}
Loading